Merge "Change generic NotFound to ImageNotFound exception"

This commit is contained in:
Jenkins 2015-06-25 05:20:12 +00:00 committed by Gerrit Code Review
commit e68b6c1a86
15 changed files with 41 additions and 37 deletions

View File

@ -170,7 +170,7 @@ class CacheFilter(wsgi.Middleware):
try:
return method(request, image_id, image_iterator, image_metadata)
except exception.NotFound:
except exception.ImageNotFound:
msg = _LE("Image cache contained image file for image '%s', "
"however the registry did not contain metadata for "
"that image!") % image_id

View File

@ -1020,7 +1020,7 @@ class Controller(controller.BaseController):
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
except exception.NotFound as e:
except exception.ImageNotFound as e:
msg = (_("Failed to find image to update: %s") %
utils.exception_to_str(e))
LOG.warn(msg)
@ -1115,7 +1115,7 @@ class Controller(controller.BaseController):
{'status': ori_status})
registry.delete_image_metadata(req.context, id)
except exception.NotFound as e:
except exception.ImageNotFound as e:
msg = (_("Failed to find image to delete: %s") %
utils.exception_to_str(e))
LOG.warn(msg)

View File

@ -168,10 +168,10 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
except exception.Duplicate:
image = registry.get_image_metadata(req.context, image_id)
if image['status'] == 'deleted':
raise exception.NotFound()
raise exception.ImageNotFound()
else:
raise
except exception.NotFound:
except exception.ImageNotFound:
msg = _LI("Image %s could not be found after upload. The image may"
" have been deleted during the upload.") % image_id
LOG.info(msg)

View File

@ -73,7 +73,7 @@ class ImageDataController(object):
image_repo.save(image)
image.set_data(data, size)
image_repo.save(image, from_state='saving')
except (exception.NotFound, exception.Conflict):
except (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.") %
@ -82,7 +82,7 @@ class ImageDataController(object):
# NOTE(sridevi): Cleaning up the uploaded chunks.
try:
image.delete()
except exception.NotFound:
except exception.ImageNotFound:
# NOTE(sridevi): Ignore this exception
pass
raise webob.exc.HTTPGone(explanation=msg,

View File

@ -336,6 +336,10 @@ class BadTaskConfiguration(GlanceException):
message = _("Task was not configured properly")
class ImageNotFound(NotFound):
message = _("Image with the given id %(image_id)s was not found")
class TaskNotFound(TaskException, NotFound):
message = _("Task with the given id %(task_id)s was not found")

View File

@ -164,9 +164,9 @@ class ImageRepo(object):
try:
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):
except (exception.ImageNotFound, exception.Forbidden, AssertionError):
msg = _("No image found with ID %s") % image_id
raise exception.NotFound(msg)
raise exception.ImageNotFound(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)
@ -274,9 +274,9 @@ class ImageRepo(object):
image_values,
purge_props=True,
from_state=from_state)
except (exception.NotFound, exception.Forbidden):
except (exception.ImageNotFound, exception.Forbidden):
msg = _("No image found with ID %s") % image.image_id
raise exception.NotFound(msg)
raise exception.ImageNotFound(msg)
self.db_api.image_tag_set_all(self.context, image.image_id,
image.tags)
image.updated_at = new_values['updated_at']
@ -286,9 +286,9 @@ class ImageRepo(object):
try:
self.db_api.image_update(self.context, image.image_id,
image_values, purge_props=True)
except (exception.NotFound, exception.Forbidden):
except (exception.ImageNotFound, exception.Forbidden):
msg = _("No image found with ID %s") % image.image_id
raise exception.NotFound(msg)
raise exception.ImageNotFound(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']

View File

@ -69,7 +69,7 @@ def image_update(client, image_id, values, purge_props=False, from_state=None):
"""
Set the given properties on an image and update it.
:raises NotFound if image does not exist.
:raises: ImageNotFound if image does not exist.
"""
return client.image_update(values=values,
image_id=image_id,

View File

@ -340,7 +340,7 @@ def _do_pagination(context, images, marker, limit, show_deleted,
start = i + 1
break
else:
raise exception.NotFound()
raise exception.ImageNotFound()
end = start + limit if limit is not None else None
return images[start:end]
@ -385,12 +385,12 @@ def _image_get(context, image_id, force_show_deleted=False, status=None):
image = DATA['images'][image_id]
except KeyError:
LOG.warn(_LW('Could not find image %s') % image_id)
raise exception.NotFound()
raise exception.ImageNotFound()
if image['deleted'] and not (force_show_deleted
or context.can_see_deleted):
LOG.warn(_LW('Unable to get deleted image'))
raise exception.NotFound()
raise exception.ImageNotFound()
if not is_image_visible(context, image):
LOG.warn(_LW('Unable to get unowned image'))
@ -690,7 +690,7 @@ def image_update(context, image_id, image_values, purge_props=False,
try:
image = DATA['images'][image_id]
except KeyError:
raise exception.NotFound()
raise exception.ImageNotFound()
location_data = image_values.pop('locations', None)
if location_data is not None:
@ -742,7 +742,7 @@ def image_destroy(context, image_id):
return _normalize_locations(context,
copy.deepcopy(DATA['images'][image_id]))
except KeyError:
raise exception.NotFound()
raise exception.ImageNotFound()
@log_call

View File

@ -134,7 +134,7 @@ def image_update(context, image_id, values, purge_props=False,
"""
Set the given properties on an image and update it.
:raises NotFound if image does not exist.
:raises ImageNotFound if image does not exist.
"""
return _image_update(context, values, image_id, purge_props,
from_state=from_state)
@ -215,7 +215,7 @@ def _check_image_id(image_id):
"""
if (image_id and
len(image_id) > models.Image.id.property.columns[0].type.length):
raise exception.NotFound()
raise exception.ImageNotFound()
def _image_get(context, image_id, session=None, force_show_deleted=False):
@ -238,7 +238,7 @@ def _image_get(context, image_id, session=None, force_show_deleted=False):
except sa_orm.exc.NoResultFound:
msg = "No image found with ID %s" % image_id
LOG.debug(msg)
raise exception.NotFound(msg)
raise exception.ImageNotFound(msg)
# Make sure they can look at it
if not is_image_visible(context, image):

View File

@ -122,7 +122,7 @@ class Controller(object):
try:
return self.db_api.image_get_all(context, filters=filters,
**params)
except exception.NotFound:
except exception.ImageNotFound:
LOG.warn(_LW("Invalid marker. Image %(id)s could not be "
"found.") % {'id': params.get('marker')})
msg = _("Invalid marker. Image could not be found.")
@ -339,7 +339,7 @@ class Controller(object):
image = self.db_api.image_get(req.context, id)
msg = "Successfully retrieved image %(id)s" % {'id': id}
LOG.debug(msg)
except exception.NotFound:
except exception.ImageNotFound:
msg = _LI("Image %(id)s not found") % {'id': id}
LOG.info(msg)
raise exc.HTTPNotFound()
@ -382,7 +382,7 @@ class Controller(object):
" 'not found'") % {'id': id}
LOG.info(msg)
return exc.HTTPNotFound()
except exception.NotFound:
except exception.ImageNotFound:
msg = _LI("Image %(id)s not found") % {'id': id}
LOG.info(msg)
return exc.HTTPNotFound()
@ -487,7 +487,7 @@ class Controller(object):
"Got error: %s") % utils.exception_to_str(e))
LOG.error(msg)
return exc.HTTPBadRequest(msg)
except exception.NotFound:
except exception.ImageNotFound:
msg = _LI("Image %(id)s not found") % {'id': id}
LOG.info(msg)
raise exc.HTTPNotFound(body='Image not found',

View File

@ -220,7 +220,7 @@ class TestCacheMiddlewareProcessRequest(base.IsolatedUnitTest):
"""
def fake_process_v1_request(request, image_id, image_iterator,
image_meta):
raise exception.NotFound()
raise exception.ImageNotFound()
def fake_get_v1_image_metadata(request, image_id):
return {'status': 'active', 'properties': {}}

View File

@ -188,7 +188,7 @@ class TestImageRepo(test_utils.BaseTestCase):
def test_get_not_found(self):
fake_uuid = str(uuid.uuid4())
exc = self.assertRaises(exception.NotFound, self.image_repo.get,
exc = self.assertRaises(exception.ImageNotFound, self.image_repo.get,
fake_uuid)
self.assertIn(fake_uuid, utils.exception_to_str(exc))
@ -368,7 +368,7 @@ class TestImageRepo(test_utils.BaseTestCase):
fake_uuid = str(uuid.uuid4())
image = self.image_repo.get(UUID1)
image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.save,
exc = self.assertRaises(exception.ImageNotFound, self.image_repo.save,
image)
self.assertIn(fake_uuid, utils.exception_to_str(exc))
@ -377,14 +377,14 @@ class TestImageRepo(test_utils.BaseTestCase):
previous_update_time = image.updated_at
self.image_repo.remove(image)
self.assertTrue(image.updated_at > previous_update_time)
self.assertRaises(exception.NotFound, self.image_repo.get, UUID1)
self.assertRaises(exception.ImageNotFound, self.image_repo.get, UUID1)
def test_remove_image_not_found(self):
fake_uuid = str(uuid.uuid4())
image = self.image_repo.get(UUID1)
image.image_id = fake_uuid
exc = self.assertRaises(exception.NotFound, self.image_repo.remove,
image)
exc = self.assertRaises(
exception.ImageNotFound, self.image_repo.remove, image)
self.assertIn(fake_uuid, utils.exception_to_str(exc))

View File

@ -304,7 +304,7 @@ class TestUploadUtils(base.StoreClearingUnitTest):
ext_update_data={'size': 10}) as (location, checksum, image_meta,
image_data, store, notifier,
update_data):
exc = exception.NotFound
exc = exception.ImageNotFound
with patch.object(registry, 'update_image_metadata',
side_effect=exc) as mock_update_image_metadata:
with patch.object(upload_utils,

View File

@ -194,7 +194,7 @@ class TestImagesController(base.StoreClearingUnitTest):
def test_upload_non_existent_image_during_save_initiates_deletion(self):
def fake_save_not_found(self):
raise exception.NotFound()
raise exception.ImageNotFound()
def fake_save_conflict(self):
raise exception.Conflict()
@ -211,10 +211,10 @@ class TestImagesController(base.StoreClearingUnitTest):
def test_upload_non_existent_image_raises_not_found_exception(self):
def fake_save(self):
raise exception.NotFound()
raise exception.ImageNotFound()
def fake_delete():
raise exception.NotFound()
raise exception.ImageNotFound()
request = unit_test_utils.get_fake_request()
image = FakeImage('abcd', locations=['http://example.com/image'])

View File

@ -148,7 +148,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
req.body = jsonutils.dumps(cmd)
res = req.get_response(self.api)
res_dict = jsonutils.loads(res.body)[0]
self.assertEqual('glance.common.exception.NotFound',
self.assertEqual('glance.common.exception.ImageNotFound',
res_dict["_error"]["cls"])
def test_get_index(self):