From 805416ebb17a9af21e9c30cab807cf7815c92856 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 17 Jan 2013 11:10:15 +0100 Subject: [PATCH] RPC API: Add a PhysicalResourceNotFound exception Change-Id: I409f8df9e93809f7267fb09656302082e42753da Signed-off-by: Zane Bitter --- heat/api/aws/exception.py | 1 + heat/api/openstack/v1/util.py | 1 + heat/common/exception.py | 4 ++++ heat/engine/service.py | 4 ++-- heat/tests/test_api_cfn_v1.py | 26 ++++++++++++++++++++++++++ heat/tests/test_engine_service.py | 2 +- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 117e468e..727e104e 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -250,6 +250,7 @@ def map_remote_error(ex): 'StackNotFound', 'ResourceNotFound', 'ResourceNotAvailable', + 'PhysicalResourceNotFound', 'StackExists', ) diff --git a/heat/api/openstack/v1/util.py b/heat/api/openstack/v1/util.py index a7e7ae0c..708a2829 100644 --- a/heat/api/openstack/v1/util.py +++ b/heat/api/openstack/v1/util.py @@ -94,6 +94,7 @@ def remote_error(ex, force_exists=False): 'StackNotFound': exc.HTTPNotFound, 'ResourceNotFound': exc.HTTPNotFound, 'ResourceNotAvailable': exc.HTTPNotFound, + 'PhysicalResourceNotFound': exc.HTTPNotFound, 'InvalidTenant': exc.HTTPForbidden, 'StackExists': exc.HTTPConflict, } diff --git a/heat/common/exception.py b/heat/common/exception.py index dd3cb0d3..0b6e7b18 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -224,3 +224,7 @@ class ResourceNotFound(OpenstackException): class ResourceNotAvailable(OpenstackException): message = _("The Resource (%(resource_name)s) is not available.") + + +class PhysicalResourceNotFound(OpenstackException): + message = _("The Resource (%(resource_id)s) could not be found.") diff --git a/heat/engine/service.py b/heat/engine/service.py index 34fb1742..907808bf 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -396,8 +396,8 @@ class EngineService(service.Service): rs = db_api.resource_get_by_physical_resource_id(context, physical_resource_id) if not rs: - msg = "The specified PhysicalResourceId doesn't exist" - raise AttributeError(msg) + raise exception.PhysicalResourceNotFound( + resource_id=physical_resource_id) stack = parser.Stack.load(context, stack=rs.stack) resource = stack[rs.name] diff --git a/heat/tests/test_api_cfn_v1.py b/heat/tests/test_api_cfn_v1.py index 57576cbf..b576e17c 100644 --- a/heat/tests/test_api_cfn_v1.py +++ b/heat/tests/test_api_cfn_v1.py @@ -1208,6 +1208,32 @@ class StackControllerTest(unittest.TestCase): self.assertEqual(response, expected) + def test_describe_stack_resources_physical_not_found(self): + # Format a dummy request + stack_name = "wordpress" + identity = dict(identifier.HeatIdentifier('t', stack_name, '6')) + params = {'Action': 'DescribeStackResources', + 'LogicalResourceId': "WikiDatabase", + 'PhysicalResourceId': 'aaaaaaaa-9f88-404d-cccc-ffffffffffff'} + dummy_req = self._dummy_GET_request(params) + + # Stub out the RPC call to the engine with a pre-canned response + self.m.StubOutWithMock(rpc, 'call') + rpc.call(dummy_req.context, self.topic, + {'method': 'find_physical_resource', + 'args': {'physical_resource_id': + 'aaaaaaaa-9f88-404d-cccc-ffffffffffff'}, + 'version': self.api_version}, + None).AndRaise( + rpc_common.RemoteError("PhysicalResourceNotFound")) + + self.m.ReplayAll() + + response = self.controller.describe_stack_resources(dummy_req) + + self.assertEqual(type(response), + exception.HeatInvalidParameterValueError) + def test_describe_stack_resources_err_inval(self): # Format a dummy request containing both StackName and # PhysicalResourceId, which is invalid and should throw a diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index ab4298f5..ac235d12 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -640,7 +640,7 @@ class stackServiceTest(unittest.TestCase): self.assertEqual(resource_identity.resource_name, 'WebServer') def test_find_physical_resource_nonexist(self): - self.assertRaises(AttributeError, + self.assertRaises(exception.PhysicalResourceNotFound, self.man.find_physical_resource, self.ctx, 'foo') -- 2.45.2