Respond with 410 after upload if image was deleted
When updating the image after upload, we should return an HTTPGone instead of a 500 error if the image cannot be found. This will provide more information to nova when this occurs during snapshotting. Fixes bug #1217838 Change-Id: I6e9875a9ff95ed3e9c38685785473138327ad4a1
This commit is contained in:
parent
4164949ce6
commit
26a47e7723
@ -50,9 +50,19 @@ class ImageDataController(object):
|
||||
try:
|
||||
image = image_repo.get(image_id)
|
||||
image.status = 'saving'
|
||||
image_repo.save(image)
|
||||
image.set_data(data, size)
|
||||
image_repo.save(image)
|
||||
try:
|
||||
image_repo.save(image)
|
||||
image.set_data(data, size)
|
||||
image_repo.save(image)
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Image %s could not be found after upload."
|
||||
"The image may have been deleted during the upload: %s")
|
||||
% (image_id, e))
|
||||
LOG.warn(msg)
|
||||
raise webob.exc.HTTPGone(explanation=msg,
|
||||
request=req,
|
||||
content_type='text/plain')
|
||||
|
||||
except ValueError as e:
|
||||
LOG.debug("Cannot save data for image %s: %s", image_id, e)
|
||||
raise webob.exc.HTTPBadRequest(explanation=unicode(e))
|
||||
|
@ -164,7 +164,18 @@ class TestImagesController(base.StoreClearingUnitTest):
|
||||
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.upload,
|
||||
request, unit_test_utils.UUID1, 'YYYY', 4)
|
||||
|
||||
def test_upload_non_existent_image(self):
|
||||
def test_upload_non_existent_image_during_save(self):
|
||||
def fake_save(self):
|
||||
raise exception.NotFound()
|
||||
|
||||
request = unit_test_utils.get_fake_request()
|
||||
image = FakeImage('abcd', locations=['http://example.com/image'])
|
||||
self.image_repo.result = image
|
||||
self.image_repo.save = fake_save
|
||||
self.assertRaises(webob.exc.HTTPGone, self.controller.upload,
|
||||
request, uuidutils.generate_uuid(), 'ABC', 3)
|
||||
|
||||
def test_upload_non_existent_image_before_save(self):
|
||||
request = unit_test_utils.get_fake_request()
|
||||
self.image_repo.result = exception.NotFound()
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.upload,
|
||||
|
Loading…
Reference in New Issue
Block a user