Merge "Fix glance doesn't catches exception NotFound from glance_store"

This commit is contained in:
Jenkins 2015-12-23 14:08:11 +00:00 committed by Gerrit Code Review
commit f9a458668c
2 changed files with 19 additions and 2 deletions

View File

@ -88,7 +88,9 @@ class ImageDataController(object):
image_repo.save(image)
image.set_data(data, size)
image_repo.save(image, from_state='saving')
except (exception.ImageNotFound, exception.Conflict):
except (glance_store.NotFound,
exception.ImageNotFound,
exception.Conflict):
msg = (_("Image %s could not be found after upload. "
"The image may have been deleted during the "
"upload, cleaning up the chunks uploaded.") %

View File

@ -251,7 +251,7 @@ class TestImagesController(base.StoreClearingUnitTest):
request, str(uuid.uuid4()), 'ABC', 3)
self.assertTrue(image.delete.called)
def test_upload_non_existent_image_raises_not_found_exception(self):
def test_upload_non_existent_image_raises_image_not_found_exception(self):
def fake_save(self):
raise exception.ImageNotFound()
@ -266,6 +266,21 @@ class TestImagesController(base.StoreClearingUnitTest):
self.assertRaises(webob.exc.HTTPGone, self.controller.upload,
request, str(uuid.uuid4()), 'ABC', 3)
def test_upload_non_existent_image_raises_store_not_found_exception(self):
def fake_save(self):
raise glance_store.NotFound()
def fake_delete():
raise exception.ImageNotFound()
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
image.delete = fake_delete
self.assertRaises(webob.exc.HTTPGone, self.controller.upload,
request, str(uuid.uuid4()), 'ABC', 3)
def test_upload_non_existent_image_before_save(self):
request = unit_test_utils.get_fake_request()
self.image_repo.result = exception.NotFound()