Merge "Utilize LimitingReader for staging data"

This commit is contained in:
Zuul 2017-12-06 15:59:17 +00:00 committed by Gerrit Code Review
commit cf0e0fa6f2
2 changed files with 15 additions and 1 deletions

View File

@ -299,7 +299,9 @@ class ImageDataController(object):
image.status = 'uploading'
image_repo.save(image, from_state='queued')
try:
staging_store.add(image_id, data, 0)
staging_store.add(
image_id, utils.LimitingReader(
utils.CooperativeReader(data), CONF.image_size_cap), 0)
except glance_store.Duplicate as e:
msg = _("The image %s has data on staging") % image_id
raise webob.exc.HTTPConflict(explanation=msg)

View File

@ -479,6 +479,18 @@ class TestImagesController(base.StoreClearingUnitTest):
self.assertRaises(webob.exc.HTTPNotFound, self.controller.stage,
request, str(uuid.uuid4()), 'ABC', 3)
@mock.patch.object(filesystem.Store, 'add')
def test_image_stage_raises_image_size_exceeded(self, mock_store_add):
mock_store_add.side_effect = exception.ImageSizeLimitExceeded()
image_id = str(uuid.uuid4())
request = unit_test_utils.get_fake_request()
image = FakeImage(image_id=image_id)
self.image_repo.result = image
with mock.patch.object(self.controller, "_unstage"):
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
self.controller.stage,
request, image_id, 'YYYYYYY', 7)
class TestImageDataDeserializer(test_utils.BaseTestCase):