Fix slo constraint according to the error message
This patch allows to create a slo manifest when the manifest includes only one segment less than min_segment_size. When putting a manifest for slo with only one segment less than min_segment_size, it will fail as EntityTooSmall with the message "Each segment, except the last, must be at least min_segment_size bytes." This behavior is different from the message because when there is only one segment, the segment is absolutely the last segment. Change-Id: I8f0203afe55536207a41e1267128f8378f1ba15f
This commit is contained in:
parent
1f1cdceabe
commit
60504a9d23
@ -591,7 +591,7 @@ class StaticLargeObject(object):
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPBadRequest('Invalid Manifest File')
|
||||
if seg_size < self.min_segment_size and \
|
||||
(index == 0 or index < len(parsed_data) - 1):
|
||||
len(parsed_data) > 1 and index < len(parsed_data) - 1:
|
||||
raise HTTPBadRequest(
|
||||
'Each segment, except the last, must be at least '
|
||||
'%d bytes.' % self.min_segment_size)
|
||||
|
@ -196,7 +196,14 @@ class TestSloPutManifest(SloTestCase):
|
||||
self.assertEquals(e.status_int, 413)
|
||||
|
||||
with patch.object(self.slo, 'min_segment_size', 1000):
|
||||
req = Request.blank('/v1/a/c/o', body=test_json_data)
|
||||
test_json_data_2obj = json.dumps(
|
||||
[{'path': '/cont/small_object1',
|
||||
'etag': 'etagoftheobjectsegment',
|
||||
'size_bytes': 10},
|
||||
{'path': '/cont/small_object2',
|
||||
'etag': 'etagoftheobjectsegment',
|
||||
'size_bytes': 10}])
|
||||
req = Request.blank('/v1/a/c/o', body=test_json_data_2obj)
|
||||
try:
|
||||
self.slo.handle_multipart_put(req, fake_start_response)
|
||||
except HTTPException as e:
|
||||
@ -248,6 +255,19 @@ class TestSloPutManifest(SloTestCase):
|
||||
self.slo(req.environ, fake_start_response)
|
||||
self.assertTrue('X-Static-Large-Object' in req.headers)
|
||||
|
||||
def test_handle_multipart_put_success_allow_only_one_small_segment(self):
|
||||
with patch.object(self.slo, 'min_segment_size', 50):
|
||||
test_json_data = json.dumps([{'path': '/cont/small_object',
|
||||
'etag': 'etagoftheobjectsegment',
|
||||
'size_bytes': 10}])
|
||||
req = Request.blank(
|
||||
'/v1/AUTH_test/c/man?multipart-manifest=put',
|
||||
environ={'REQUEST_METHOD': 'PUT'}, headers={'Accept': 'test'},
|
||||
body=test_json_data)
|
||||
self.assertTrue('X-Static-Large-Object' not in req.headers)
|
||||
self.slo(req.environ, fake_start_response)
|
||||
self.assertTrue('X-Static-Large-Object' in req.headers)
|
||||
|
||||
def test_handle_multipart_put_success_unicode(self):
|
||||
test_json_data = json.dumps([{'path': u'/cont/object\u2661',
|
||||
'etag': 'etagoftheobjectsegment',
|
||||
|
Loading…
x
Reference in New Issue
Block a user