From 7867dd6b9d2dd5d91e818d6a9685df106dbabf8c Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Thu, 16 Jul 2015 12:12:54 +0000 Subject: [PATCH] Fix StackResourceUnavailable exception make this inherit from HeatException directly, report resource type instead of resouce name and expose it as HTTPBadRequest. Co-Authored-By: Kanagaraj Manickam Change-Id: Iba33b0bb1cebfd66b8b721adcb24aa7b9a0beb5a --- heat/api/middleware/fault.py | 1 + heat/common/exception.py | 12 +++--------- heat/engine/resource.py | 4 ++-- heat/tests/test_resource.py | 8 ++++---- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/heat/api/middleware/fault.py b/heat/api/middleware/fault.py index 506cc307cd..889effb552 100644 --- a/heat/api/middleware/fault.py +++ b/heat/api/middleware/fault.py @@ -91,6 +91,7 @@ class FaultWrapper(wsgi.Middleware): 'IncompatibleObjectVersion': webob.exc.HTTPBadRequest, 'OrphanedObjectError': webob.exc.HTTPBadRequest, 'UnsupportedObjectError': webob.exc.HTTPBadRequest, + 'ResourceTypeUnavailable': webob.exc.HTTPBadRequest, } def _map_exception_to_error(self, class_exception): diff --git a/heat/common/exception.py b/heat/common/exception.py index 8ca63f0361..637942486e 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -524,12 +524,6 @@ class SIGHUPInterrupt(HeatException): msg_fmt = _("System SIGHUP signal received.") -class StackResourceUnavailable(StackValidationFailed): - message = _("Service %(service_name)s does not have required endpoint in " - "service catalog for the resource %(resource_name)s") - - def __init__(self, service_name, resource_name): - super(StackResourceUnavailable, self).__init__( - message=self.message % dict( - service_name=service_name, - resource_name=resource_name)) +class ResourceTypeUnavailable(HeatException): + msg_fmt = _("Service %(service_name)s does not have required endpoint in " + "service catalog for the resource type %(resource_type)s") diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 5b26ab6310..a9afdbfebe 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -168,9 +168,9 @@ class Resource(object): assert issubclass(ResourceClass, Resource) if not ResourceClass.is_service_available(stack.context): - ex = exception.StackResourceUnavailable( + ex = exception.ResourceTypeUnavailable( service_name=ResourceClass.default_client_name, - resource_name=name + resource_type=definition.resource_type ) LOG.error(six.text_type(ex)) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index fbee242717..1019cb0890 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -2399,7 +2399,7 @@ class ResourceAvailabilityTest(common.HeatTestCase): def test_service_not_deployed_throws_exception(self): ''' When the service is not deployed, make sure resource is throwing - StackResourceUnavailable exception. + ResourceTypeUnavailable exception. ''' with mock.patch.object( generic_rsrc.ResourceWithDefaultClientName, @@ -2408,12 +2408,12 @@ class ResourceAvailabilityTest(common.HeatTestCase): definition = rsrc_defn.ResourceDefinition( name='Test Resource', - resource_type=mock.Mock()) + resource_type='UnavailableResourceType') mock_stack = mock.MagicMock() ex = self.assertRaises( - exception.StackResourceUnavailable, + exception.ResourceTypeUnavailable, generic_rsrc.ResourceWithDefaultClientName.__new__, cls=generic_rsrc.ResourceWithDefaultClientName, name='test_stack', @@ -2421,7 +2421,7 @@ class ResourceAvailabilityTest(common.HeatTestCase): stack=mock_stack) msg = ('Service sample does not have required endpoint in service' - ' catalog for the resource test_stack') + ' catalog for the resource type UnavailableResourceType') self.assertEqual(msg, six.text_type(ex), 'invalid exception message')