diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index 1f513cbafd..058375341e 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -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, diff --git a/heat/common/exception.py b/heat/common/exception.py index db89cda919..1708484f02 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -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): diff --git a/heat/engine/clients/os/glance.py b/heat/engine/clients/os/glance.py index 3944effc44..e02f120030 100644 --- a/heat/engine/clients/os/glance.py +++ b/heat/engine/clients/os/glance.py @@ -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) diff --git a/heat/engine/clients/os/sahara.py b/heat/engine/clients/os/sahara.py index f4901c4451..98d72d7248 100644 --- a/heat/engine/clients/os/sahara.py +++ b/heat/engine/clients/os/sahara.py @@ -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): diff --git a/heat/tests/aws/test_instance.py b/heat/tests/aws/test_instance.py index 5d19b89909..8bec7a85f5 100644 --- a/heat/tests/aws/test_instance.py +++ b/heat/tests/aws/test_instance.py @@ -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) diff --git a/heat/tests/test_glance_client.py b/heat/tests/test_glance_client.py index 8681ca7b41..27dabac078 100644 --- a/heat/tests/test_glance_client.py +++ b/heat/tests/test_glance_client.py @@ -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)) diff --git a/heat/tests/test_sahara_client.py b/heat/tests/test_sahara_client.py index a95ba44bd1..c66bddccb7 100644 --- a/heat/tests/test_sahara_client.py +++ b/heat/tests/test_sahara_client.py @@ -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)) diff --git a/heat/tests/test_server.py b/heat/tests/test_server.py index ebc9a77da0..d9d0b7bf83 100644 --- a/heat/tests/test_server.py +++ b/heat/tests/test_server.py @@ -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() diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 0899b3e2f6..e684367116 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -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']