Merge "Glance v2: Include image/member id in 404 Response"

This commit is contained in:
Jenkins 2013-11-12 06:58:10 +00:00 committed by Gerrit Code Review
commit 60f4cfda04
3 changed files with 35 additions and 9 deletions

View File

@ -70,7 +70,8 @@ class ImageRepo(object):
db_api_image = dict(self.db_api.image_get(self.context, image_id))
assert not db_api_image['deleted']
except (exception.NotFound, exception.Forbidden, AssertionError):
raise exception.NotFound(image_id=image_id)
msg = _("No image found with ID %s") % image_id
raise exception.NotFound(msg)
tags = self.db_api.image_tag_get_all(self.context, image_id)
image = self._format_image_from_db(db_api_image, tags)
return ImageProxy(image, self.context, self.db_api)
@ -170,7 +171,8 @@ class ImageRepo(object):
image_values,
purge_props=True)
except (exception.NotFound, exception.Forbidden):
raise exception.NotFound(image_id=image.image_id)
msg = _("No image found with ID %s") % image.image_id
raise exception.NotFound(msg)
self.db_api.image_tag_set_all(self.context, image.image_id,
image.tags)
image.updated_at = new_values['updated_at']
@ -181,7 +183,8 @@ class ImageRepo(object):
self.db_api.image_update(self.context, image.image_id,
image_values, purge_props=True)
except (exception.NotFound, exception.Forbidden):
raise exception.NotFound(image_id=image.image_id)
msg = _("No image found with ID %s") % image.image_id
raise exception.NotFound(msg)
# NOTE(markwash): don't update tags?
new_values = self.db_api.image_destroy(self.context, image.image_id)
image.updated_at = new_values['updated_at']
@ -257,7 +260,8 @@ class ImageMemberRepo(object):
try:
self.db_api.image_member_delete(self.context, image_member.id)
except (exception.NotFound, exception.Forbidden):
raise exception.NotFound(member_id=image_member.id)
msg = _("The specified member %s could not be found")
raise exception.NotFound(msg % image_member.id)
def save(self, image_member):
image_member_values = self._format_image_member_to_db(image_member)

View File

@ -503,7 +503,7 @@ def image_update(context, image_id, image_values, purge_props=False):
try:
image = DATA['images'][image_id]
except KeyError:
raise exception.NotFound(image_id=image_id)
raise exception.NotFound()
location_data = image_values.pop('locations', None)
if location_data is not None:

View File

@ -145,8 +145,10 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertEqual(image.locations, [])
def test_get_not_found(self):
self.assertRaises(exception.NotFound, self.image_repo.get,
uuidutils.generate_uuid())
fake_uuid = uuidutils.generate_uuid()
exc = self.assertRaises(exception.NotFound, self.image_repo.get,
fake_uuid)
self.assertTrue(fake_uuid in unicode(exc))
def test_get_forbidden(self):
self.assertRaises(exception.NotFound, self.image_repo.get, UUID4)
@ -281,6 +283,14 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertEqual(image.tags, set(['king', 'kong']))
self.assertEqual(image.updated_at, current_update_time)
def test_save_image_not_found(self):
fake_uuid = uuidutils.generate_uuid()
image = self.image_repo.get(UUID1)
image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.save,
image)
self.assertTrue(fake_uuid in unicode(exc))
def test_remove_image(self):
image = self.image_repo.get(UUID1)
previous_update_time = image.updated_at
@ -288,6 +298,14 @@ class TestImageRepo(test_utils.BaseTestCase):
self.assertTrue(image.updated_at > previous_update_time)
self.assertRaises(exception.NotFound, self.image_repo.get, UUID1)
def test_remove_image_not_found(self):
fake_uuid = uuidutils.generate_uuid()
image = self.image_repo.get(UUID1)
image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.remove,
image)
self.assertTrue(fake_uuid in unicode(exc))
class TestEncryptedLocations(test_utils.BaseTestCase):
def setUp(self):
@ -448,8 +466,12 @@ class TestImageMemberRepo(test_utils.BaseTestCase):
TENANT2)
def test_remove_image_member_does_not_exist(self):
fake_uuid = uuidutils.generate_uuid()
image = self.image_repo.get(UUID2)
fake_member = glance.domain.ImageMemberFactory()\
.new_image_member(image, TENANT4)
self.assertRaises(exception.NotFound, self.image_member_repo.remove,
fake_member)
fake_member.id = fake_uuid
exc = self.assertRaises(exception.NotFound,
self.image_member_repo.remove,
fake_member)
self.assertTrue(fake_uuid in unicode(exc))