Fix 500 from stage call on non-existing image

If user tries to stage data to unexisting image then it fails with 500
internal server error.

Caught NotFound exception and raised HTTPNotFound to return 404
response to the user.

Change-Id: I78d252fceb9a5537135f0c238c4ad2ba52fdda7c
Closes-Bug: #1733551
This commit is contained in:
Abhishek Kekane 2017-11-21 10:48:59 +00:00
parent b976fc0bf4
commit 7a67c4355b
2 changed files with 9 additions and 0 deletions

View File

@ -304,6 +304,9 @@ class ImageDataController(object):
msg = _("The image %s has data on staging") % image_id
raise webob.exc.HTTPConflict(explanation=msg)
except exception.NotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.msg)
except glance_store.StorageFull as e:
msg = _("Image storage media "
"is full: %s") % encodeutils.exception_to_unicode(e)

View File

@ -473,6 +473,12 @@ class TestImagesController(base.StoreClearingUnitTest):
request, image_id, 'YYYYYYY', 7)
self.assertEqual('queued', self.image_repo.saved_image.status)
def test_image_stage_non_existent_image(self):
request = unit_test_utils.get_fake_request()
self.image_repo.result = exception.NotFound()
self.assertRaises(webob.exc.HTTPNotFound, self.controller.stage,
request, str(uuid.uuid4()), 'ABC', 3)
class TestImageDataDeserializer(test_utils.BaseTestCase):