From 764f6ace9747d2d240b766bd22256aff16ed35fa Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 17 Jan 2013 11:10:14 +0100 Subject: [PATCH] RPC API: Add a StackNotFound exception Change-Id: Ic109e9f6f5cca3af531ffcd2c9149742442e66d4 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 | 6 ++--- heat/tests/test_api_cfn_v1.py | 37 +++++++++++++++++++++++------ heat/tests/test_api_openstack_v1.py | 28 +++++++++++----------- heat/tests/test_engine_service.py | 16 ++++++------- 7 files changed, 61 insertions(+), 32 deletions(-) diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 87ff9e37..4ab0937c 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -247,6 +247,7 @@ def map_remote_error(ex): 'AttributeError', 'ValueError', 'InvalidTenant', + 'StackNotFound', ) if ex.exc_type in inval_param_errors: diff --git a/heat/api/openstack/v1/util.py b/heat/api/openstack/v1/util.py index 55f6d459..db5323f3 100644 --- a/heat/api/openstack/v1/util.py +++ b/heat/api/openstack/v1/util.py @@ -91,6 +91,7 @@ def remote_error(ex, force_exists=False): error_map = { 'AttributeError': client_error, 'ValueError': client_error, + 'StackNotFound': exc.HTTPNotFound, 'InvalidTenant': exc.HTTPForbidden, } diff --git a/heat/common/exception.py b/heat/common/exception.py index 22cd6fff..d58b040b 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -207,3 +207,7 @@ class ImageNotFound(OpenstackException): class InvalidTenant(OpenstackException): message = _("Searching Tenant %(target)s " "from Tenant %(actual)s forbidden.") + + +class StackNotFound(OpenstackException): + message = _("The Stack (%(stack_name)s) could not be found.") diff --git a/heat/engine/service.py b/heat/engine/service.py index c6995409..81b463c0 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -122,7 +122,7 @@ class EngineService(service.Service): stack = parser.Stack.load(context, stack=s) return dict(stack.identifier()) else: - raise AttributeError('Unknown stack name') + raise exception.StackNotFound(stack_name=stack_name) def _get_stack(self, context, stack_identity): identity = identifier.HeatIdentifier(**stack_identity) @@ -134,10 +134,10 @@ class EngineService(service.Service): s = db_api.stack_get(context, identity.stack_id) if s is None: - raise AttributeError('Stack not found') + raise exception.StackNotFound(stack_name=identity.stack_name) if identity.path or s.name != identity.stack_name: - raise AttributeError('Invalid stack ID') + raise exception.StackNotFound(stack_name=identity.stack_name) return s diff --git a/heat/tests/test_api_cfn_v1.py b/heat/tests/test_api_cfn_v1.py index a2031a53..95b6278b 100644 --- a/heat/tests/test_api_cfn_v1.py +++ b/heat/tests/test_api_cfn_v1.py @@ -374,7 +374,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -586,7 +586,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -668,7 +668,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -791,7 +791,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -893,7 +893,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -967,6 +967,29 @@ class StackControllerTest(unittest.TestCase): self.assertEqual(response, expected) + def test_describe_stack_resource_nonexistent_stack(self): + # Format a dummy request + stack_name = "wibble" + identity = dict(identifier.HeatIdentifier('t', stack_name, '6')) + params = {'Action': 'DescribeStackResource', + 'StackName': stack_name, + 'LogicalResourceId': "WikiDatabase"} + 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': 'identify_stack', + 'args': {'stack_name': stack_name}, + 'version': self.api_version}, + None).AndRaise(rpc_common.RemoteError("StackNotFound")) + + self.m.ReplayAll() + + result = self.controller.describe_stack_resource(dummy_req) + self.assertEqual(type(result), + exception.HeatInvalidParameterValueError) + def test_describe_stack_resources(self): # Format a dummy request stack_name = "wordpress" @@ -1046,7 +1069,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -1199,7 +1222,7 @@ class StackControllerTest(unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, None - ).AndRaise(rpc_common.RemoteError("AttributeError")) + ).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index 801cf14e..8e733ebd 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -441,7 +441,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup, @@ -483,7 +483,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): {'method': 'identify_stack', 'args': {'stack_name': stack_name}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup, @@ -558,8 +558,8 @@ class StackControllerTest(ControllerTest, unittest.TestCase): self.assertEqual(response, expected) self.m.VerifyAll() - def test_show_aterr(self): - identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6') + def test_show_notfound(self): + identity = identifier.HeatIdentifier(self.tenant, 'wibble', '6') req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity) @@ -568,7 +568,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): {'method': 'show_stack', 'args': {'stack_identity': dict(identity)}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -618,7 +618,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): self.assertEqual(response, template) self.m.VerifyAll() - def test_get_template_err_rpcerr(self): + def test_get_template_err_notfound(self): identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6') req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity) template = {u'Foo': u'bar'} @@ -628,7 +628,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): {'method': 'get_template', 'args': {'stack_identity': dict(identity)}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() @@ -692,7 +692,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): 'params': parameters, 'args': {'timeout_mins': 30}}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -747,7 +747,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase): {'method': 'delete_stack', 'args': {'stack_identity': dict(identity)}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -926,7 +926,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase): {'method': 'list_stack_resources', 'args': {'stack_identity': stack_identity}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -1008,7 +1008,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase): 'args': {'stack_identity': stack_identity, 'resource_name': res_name}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -1076,7 +1076,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase): 'args': {'stack_identity': stack_identity, 'resource_name': res_name}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -1246,7 +1246,7 @@ class EventControllerTest(ControllerTest, unittest.TestCase): {'method': 'list_events', 'args': {'stack_identity': stack_identity}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, @@ -1477,7 +1477,7 @@ class EventControllerTest(ControllerTest, unittest.TestCase): {'method': 'list_events', 'args': {'stack_identity': stack_identity}, 'version': self.api_version}, - None).AndRaise(rpc_common.RemoteError("AttributeError")) + None).AndRaise(rpc_common.RemoteError("StackNotFound")) self.m.ReplayAll() self.assertRaises(webob.exc.HTTPNotFound, diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 638c2fe4..60c81cda 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -260,7 +260,7 @@ class stackServiceCreateUpdateDeleteTest(unittest.TestCase): self.m.ReplayAll() - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.delete_stack, self.ctx, stack.identifier()) self.m.VerifyAll() @@ -347,7 +347,7 @@ class stackServiceCreateUpdateDeleteTest(unittest.TestCase): self.m.ReplayAll() - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.update_stack, self.ctx, stack.identifier(), template, params, {}) self.m.VerifyAll() @@ -408,7 +408,7 @@ class stackServiceTest(unittest.TestCase): self.assertEqual(identity, self.stack_identity) def test_stack_identify_nonexist(self): - self.assertRaises(AttributeError, self.man.identify_stack, + self.assertRaises(exception.StackNotFound, self.man.identify_stack, self.ctx, 'wibble') def test_stack_create_existing(self): @@ -492,7 +492,7 @@ class stackServiceTest(unittest.TestCase): def test_stack_describe_nonexistent(self): nonexist = dict(self.stack_identity) nonexist['stack_name'] = 'wibble' - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.show_stack, self.ctx, nonexist) @@ -575,7 +575,7 @@ class stackServiceTest(unittest.TestCase): def test_stack_resource_describe_nonexist_stack(self): nonexist = dict(self.stack_identity) nonexist['stack_name'] = 'foo' - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.describe_stack_resource, self.ctx, nonexist, 'WebServer') @@ -623,7 +623,7 @@ class stackServiceTest(unittest.TestCase): def test_stack_resources_describe_nonexist_stack(self): nonexist = dict(self.stack_identity) nonexist['stack_name'] = 'foo' - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.describe_stack_resources, self.ctx, nonexist, 'WebServer') @@ -662,7 +662,7 @@ class stackServiceTest(unittest.TestCase): def test_stack_resources_list_nonexist_stack(self): nonexist = dict(self.stack_identity) nonexist['stack_name'] = 'foo' - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.list_stack_resources, self.ctx, nonexist) @@ -680,7 +680,7 @@ class stackServiceTest(unittest.TestCase): test_metadata = {'foo': 'bar', 'baz': 'quux', 'blarg': 'wibble'} nonexist = dict(self.stack_identity) nonexist['stack_name'] = 'foo' - self.assertRaises(AttributeError, + self.assertRaises(exception.StackNotFound, self.man.metadata_update, self.ctx, nonexist, 'WebServer', test_metadata) -- 2.45.2