mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-25 13:47:27 +00:00
Merge pull request #29 from andrewgaul/multipart-upload-empty-small
Test empty and small multi-part uploads Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
This commit is contained in:
commit
284938942e
3 changed files with 56 additions and 20 deletions
|
@ -9,8 +9,6 @@ import email.utils
|
||||||
import isodate
|
import isodate
|
||||||
import nose
|
import nose
|
||||||
import operator
|
import operator
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import os
|
import os
|
||||||
|
@ -34,6 +32,7 @@ from nose.plugins.attrib import attr
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
from .utils import assert_raises
|
from .utils import assert_raises
|
||||||
|
from .utils import generate_random
|
||||||
from .utils import region_sync_meta
|
from .utils import region_sync_meta
|
||||||
import AnonymousAuth
|
import AnonymousAuth
|
||||||
|
|
||||||
|
@ -4350,24 +4349,6 @@ def transfer_part(bucket, mp_id, mp_keyname, i, part):
|
||||||
part_out = StringIO(part)
|
part_out = StringIO(part)
|
||||||
mp.upload_part_from_file(part_out, i+1)
|
mp.upload_part_from_file(part_out, i+1)
|
||||||
|
|
||||||
def generate_random(size, part_size=5*1024*1024):
|
|
||||||
"""
|
|
||||||
Generate the specified number random data.
|
|
||||||
(actually each MB is a repetition of the first KB)
|
|
||||||
"""
|
|
||||||
chunk = 1024
|
|
||||||
allowed = string.ascii_letters
|
|
||||||
for x in range(0, size, part_size):
|
|
||||||
strpart = ''.join([allowed[random.randint(0, len(allowed) - 1)] for _ in xrange(chunk)])
|
|
||||||
s = ''
|
|
||||||
left = size - x
|
|
||||||
this_part_size = min(left, part_size)
|
|
||||||
for y in range(this_part_size / chunk):
|
|
||||||
s = s + strpart
|
|
||||||
yield s
|
|
||||||
if (x == size):
|
|
||||||
return
|
|
||||||
|
|
||||||
def _multipart_upload(bucket, s3_key_name, size, part_size=5*1024*1024, do_list=None, headers=None, metadata=None):
|
def _multipart_upload(bucket, s3_key_name, size, part_size=5*1024*1024, do_list=None, headers=None, metadata=None):
|
||||||
"""
|
"""
|
||||||
generate a multi-part upload for a random file of specifed size,
|
generate a multi-part upload for a random file of specifed size,
|
||||||
|
@ -4384,6 +4365,29 @@ def _multipart_upload(bucket, s3_key_name, size, part_size=5*1024*1024, do_list=
|
||||||
|
|
||||||
return upload
|
return upload
|
||||||
|
|
||||||
|
@attr(resource='object')
|
||||||
|
@attr(method='put')
|
||||||
|
@attr(operation='check multipart upload without parts')
|
||||||
|
def test_multipart_upload_empty():
|
||||||
|
bucket = get_new_bucket()
|
||||||
|
key = "mymultipart"
|
||||||
|
upload = _multipart_upload(bucket, key, 0)
|
||||||
|
e = assert_raises(boto.exception.S3ResponseError, upload.complete_upload)
|
||||||
|
eq(e.status, 400)
|
||||||
|
eq(e.error_code, u'MalformedXML')
|
||||||
|
|
||||||
|
@attr(resource='object')
|
||||||
|
@attr(method='put')
|
||||||
|
@attr(operation='check multipart uploads with single small part')
|
||||||
|
def test_multipart_upload_small():
|
||||||
|
bucket = get_new_bucket()
|
||||||
|
key = "mymultipart"
|
||||||
|
size = 1
|
||||||
|
upload = _multipart_upload(bucket, key, size)
|
||||||
|
upload.complete_upload()
|
||||||
|
key2 = bucket.get_key(key)
|
||||||
|
eq(key2.size, size)
|
||||||
|
|
||||||
@attr(resource='object')
|
@attr(resource='object')
|
||||||
@attr(method='put')
|
@attr(method='put')
|
||||||
@attr(operation='complete multi-part upload')
|
@attr(operation='complete multi-part upload')
|
||||||
|
|
11
s3tests/functional/test_utils.py
Normal file
11
s3tests/functional/test_utils.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from nose.tools import eq_ as eq
|
||||||
|
|
||||||
|
import utils
|
||||||
|
|
||||||
|
def test_generate():
|
||||||
|
FIVE_MB = 5 * 1024 * 1024
|
||||||
|
eq(len(''.join(utils.generate_random(0))), 0)
|
||||||
|
eq(len(''.join(utils.generate_random(1))), 1)
|
||||||
|
eq(len(''.join(utils.generate_random(FIVE_MB - 1))), FIVE_MB - 1)
|
||||||
|
eq(len(''.join(utils.generate_random(FIVE_MB))), FIVE_MB)
|
||||||
|
eq(len(''.join(utils.generate_random(FIVE_MB + 1))), FIVE_MB + 1)
|
|
@ -1,4 +1,6 @@
|
||||||
|
import random
|
||||||
import requests
|
import requests
|
||||||
|
import string
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from nose.tools import eq_ as eq
|
from nose.tools import eq_ as eq
|
||||||
|
@ -18,6 +20,25 @@ def assert_raises(excClass, callableObj, *args, **kwargs):
|
||||||
excName = str(excClass)
|
excName = str(excClass)
|
||||||
raise AssertionError("%s not raised" % excName)
|
raise AssertionError("%s not raised" % excName)
|
||||||
|
|
||||||
|
def generate_random(size, part_size=5*1024*1024):
|
||||||
|
"""
|
||||||
|
Generate the specified number random data.
|
||||||
|
(actually each MB is a repetition of the first KB)
|
||||||
|
"""
|
||||||
|
chunk = 1024
|
||||||
|
allowed = string.ascii_letters
|
||||||
|
for x in range(0, size, part_size):
|
||||||
|
strpart = ''.join([allowed[random.randint(0, len(allowed) - 1)] for _ in xrange(chunk)])
|
||||||
|
s = ''
|
||||||
|
left = size - x
|
||||||
|
this_part_size = min(left, part_size)
|
||||||
|
for y in range(this_part_size / chunk):
|
||||||
|
s = s + strpart
|
||||||
|
s = s + strpart[:(this_part_size % chunk)]
|
||||||
|
yield s
|
||||||
|
if (x == size):
|
||||||
|
return
|
||||||
|
|
||||||
# syncs all the regions except for the one passed in
|
# syncs all the regions except for the one passed in
|
||||||
def region_sync_meta(targets, region):
|
def region_sync_meta(targets, region):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue