Use EntityNotFound instead of ImageNotFound
There are too many **NotFound exception classes defined in exception.py. This patch will define a general notfound exception: EntityNotFound. And will use it instead of ImageNotFound exception. Change-Id: I2a09637be97905548b29673273e8579c69d42d52 Closes-Bug: #1461343
This commit is contained in:
parent
d83e8ac397
commit
0ba3206b40
|
@ -54,6 +54,7 @@ class FaultWrapper(wsgi.Middleware):
|
|||
'AttributeError': webob.exc.HTTPBadRequest,
|
||||
'ActionInProgress': webob.exc.HTTPConflict,
|
||||
'ValueError': webob.exc.HTTPBadRequest,
|
||||
'EntityNotFound': webob.exc.HTTPNotFound,
|
||||
'StackNotFound': webob.exc.HTTPNotFound,
|
||||
'NotFound': webob.exc.HTTPNotFound,
|
||||
'ResourceActionNotSupported': webob.exc.HTTPBadRequest,
|
||||
|
|
|
@ -227,8 +227,8 @@ class FlavorMissing(HeatException):
|
|||
msg_fmt = _("The Flavor ID (%(flavor_id)s) could not be found.")
|
||||
|
||||
|
||||
class ImageNotFound(HeatException):
|
||||
msg_fmt = _("The Image (%(image_name)s) could not be found.")
|
||||
class EntityNotFound(HeatException):
|
||||
msg_fmt = _("The %(entity)s (%(name)s) could not be found.")
|
||||
|
||||
|
||||
class ServerNotFound(HeatException):
|
||||
|
|
|
@ -64,7 +64,7 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
:param image_identifier: image name or a UUID-like identifier
|
||||
:returns: the id of the requested :image_identifier:
|
||||
:raises: exception.ImageNotFound,
|
||||
:raises: exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity
|
||||
'''
|
||||
if uuidutils.is_uuid_like(image_identifier):
|
||||
|
@ -82,7 +82,7 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
:param image_identifier: image name
|
||||
:returns: the id of the requested :image_identifier:
|
||||
:raises: exception.ImageNotFound,
|
||||
:raises: exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity
|
||||
'''
|
||||
try:
|
||||
|
@ -95,7 +95,8 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||
if num_matches == 0:
|
||||
LOG.info(_LI("Image %s was not found in glance"),
|
||||
image_identifier)
|
||||
raise exception.ImageNotFound(image_name=image_identifier)
|
||||
raise exception.EntityNotFound(entity='Image',
|
||||
name=image_identifier)
|
||||
elif num_matches > 1:
|
||||
LOG.info(_LI("Multiple images %s were found in glance with name"),
|
||||
image_identifier)
|
||||
|
@ -107,7 +108,7 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
class ImageConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (exception.ImageNotFound,)
|
||||
expected_exceptions = (exception.EntityNotFound,)
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
client.client_plugin('glance').get_image_id(value)
|
||||
|
|
|
@ -73,7 +73,7 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
:param image_identifier: image name or a UUID-like identifier
|
||||
:returns: the id of the requested :image_identifier:
|
||||
:raises: exception.ImageNotFound,
|
||||
:raises: exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity
|
||||
'''
|
||||
if uuidutils.is_uuid_like(image_identifier):
|
||||
|
@ -92,7 +92,7 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
:param image_identifier: image name
|
||||
:returns: the id of the requested :image_identifier:
|
||||
:raises: exception.ImageNotFound,
|
||||
:raises: exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity
|
||||
'''
|
||||
try:
|
||||
|
@ -106,7 +106,8 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
|
|||
if num_matches == 0:
|
||||
LOG.info(_LI("Image %s was not found in sahara images"),
|
||||
image_identifier)
|
||||
raise exception.ImageNotFound(image_name=image_identifier)
|
||||
raise exception.EntityNotFound(entity='Image',
|
||||
name=image_identifier)
|
||||
elif num_matches > 1:
|
||||
LOG.info(_LI("Multiple images %s were found in sahara with name"),
|
||||
image_identifier)
|
||||
|
@ -118,7 +119,7 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
class ImageConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (exception.ImageNotFound,
|
||||
expected_exceptions = (exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity,)
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
|
|
|
@ -378,8 +378,8 @@ class InstancesTest(common.HeatTestCase):
|
|||
resource_defns['WebServer'], stack)
|
||||
|
||||
self._mock_get_image_id_fail('Slackware',
|
||||
exception.ImageNotFound(
|
||||
image_name='Slackware'))
|
||||
exception.EntityNotFound(
|
||||
entity='Image', name='Slackware'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
create = scheduler.TaskRunner(instance.create)
|
||||
|
|
|
@ -48,7 +48,7 @@ class GlanceUtilsTests(common.HeatTestCase):
|
|||
self.glance_client.images.list.side_effect = ([self.my_image], [])
|
||||
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_id))
|
||||
self.assertEqual(img_id, self.glance_plugin.get_image_id(img_name))
|
||||
self.assertRaises(exception.ImageNotFound,
|
||||
self.assertRaises(exception.EntityNotFound,
|
||||
self.glance_plugin.get_image_id, 'noimage')
|
||||
|
||||
calls = [mock.call(filters={'name': img_name}),
|
||||
|
@ -93,7 +93,7 @@ class GlanceUtilsTests(common.HeatTestCase):
|
|||
glance_exceptions.HTTPNotFound()]
|
||||
self.glance_client.images.list.return_value = []
|
||||
|
||||
self.assertRaises(exception.ImageNotFound,
|
||||
self.assertRaises(exception.EntityNotFound,
|
||||
self.glance_plugin.get_image_id, img_name)
|
||||
self.glance_client.images.get.assert_called_once_with(img_name)
|
||||
self.glance_client.images.list.assert_called_once_with(
|
||||
|
@ -127,6 +127,6 @@ class ImageConstraintTest(common.HeatTestCase):
|
|||
self.assertTrue(self.constraint.validate("foo", self.ctx))
|
||||
|
||||
def test_validation_error(self):
|
||||
self.mock_get_image.side_effect = exception.ImageNotFound(
|
||||
image_name='bar')
|
||||
self.mock_get_image.side_effect = exception.EntityNotFound(
|
||||
entity='Image', name='bar')
|
||||
self.assertFalse(self.constraint.validate("bar", self.ctx))
|
||||
|
|
|
@ -49,7 +49,7 @@ class SaharaUtilsTests(common.HeatTestCase):
|
|||
|
||||
self.assertEqual(img_id, self.sahara_plugin.get_image_id(img_id))
|
||||
self.assertEqual(img_id, self.sahara_plugin.get_image_id(img_name))
|
||||
self.assertRaises(exception.ImageNotFound,
|
||||
self.assertRaises(exception.EntityNotFound,
|
||||
self.sahara_plugin.get_image_id, 'noimage')
|
||||
|
||||
calls = [mock.call(name=img_name),
|
||||
|
@ -97,7 +97,7 @@ class SaharaUtilsTests(common.HeatTestCase):
|
|||
error_name='IMAGE_NOT_REGISTERED')]
|
||||
self.sahara_client.images.find.return_value = []
|
||||
|
||||
self.assertRaises(exception.ImageNotFound,
|
||||
self.assertRaises(exception.EntityNotFound,
|
||||
self.sahara_plugin.get_image_id, img_name)
|
||||
|
||||
self.sahara_client.images.get.assert_called_once_with(img_name)
|
||||
|
@ -130,6 +130,6 @@ class ImageConstraintTest(common.HeatTestCase):
|
|||
self.assertTrue(self.constraint.validate("foo", self.ctx))
|
||||
|
||||
def test_validation_error(self):
|
||||
self.mock_get_image.side_effect = exception.ImageNotFound(
|
||||
image_name='bar')
|
||||
self.mock_get_image.side_effect = exception.EntityNotFound(
|
||||
entity='Image', name='bar')
|
||||
self.assertFalse(self.constraint.validate("bar", self.ctx))
|
||||
|
|
|
@ -410,8 +410,9 @@ class ServersTest(common.HeatTestCase):
|
|||
resource_defns['WebServer'], stack)
|
||||
|
||||
self._mock_get_image_id_fail('Slackware',
|
||||
exception.ImageNotFound(
|
||||
image_name='Slackware'))
|
||||
exception.EntityNotFound(
|
||||
entity='Image',
|
||||
name='Slackware'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
create = scheduler.TaskRunner(server.create)
|
||||
|
@ -460,7 +461,8 @@ class ServersTest(common.HeatTestCase):
|
|||
resource_defns['WebServer'], stack)
|
||||
|
||||
self._mock_get_image_id_fail('1',
|
||||
exception.ImageNotFound(image_name='1'))
|
||||
exception.EntityNotFound(
|
||||
entity='Image', name='1'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
create = scheduler.TaskRunner(server.create)
|
||||
|
@ -3192,7 +3194,7 @@ class ServersTest(common.HeatTestCase):
|
|||
glance.ImageConstraint.validate(
|
||||
'CentOS 5.2', mox.IgnoreArg()).AndReturn(True)
|
||||
# verify that validate gets invoked exactly once for update
|
||||
ex = exception.ImageNotFound(image_name='Update Image')
|
||||
ex = exception.EntityNotFound(entity='Image', name='Update Image')
|
||||
glance.ImageConstraint.validate('Update Image',
|
||||
mox.IgnoreArg()).AndRaise(ex)
|
||||
self.m.ReplayAll()
|
||||
|
|
|
@ -1306,8 +1306,9 @@ class validateTest(common.HeatTestCase):
|
|||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||
|
||||
self._mock_get_image_id_fail('image_name',
|
||||
exception.ImageNotFound(
|
||||
image_name='image_name'))
|
||||
exception.EntityNotFound(
|
||||
entity='Image',
|
||||
name='image_name'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
resource = stack['Instance']
|
||||
|
|
Loading…
Reference in New Issue