From: Zane Bitter Date: Thu, 17 Jan 2013 10:10:15 +0000 (+0100) Subject: RPC API: Add a StackExists exception X-Git-Tag: 2014.1~999 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2bc41c73208071346f7888ec08eec338e77d27dc;p=openstack-build%2Fheat-build.git RPC API: Add a StackExists exception Change-Id: Ia8cb5af80abc7570b938c381d51e41eb7aa0629d Signed-off-by: Zane Bitter --- diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 4ab0937c..1cfc1c89 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -248,6 +248,7 @@ def map_remote_error(ex): 'ValueError', 'InvalidTenant', 'StackNotFound', + 'StackExists', ) 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 db5323f3..c231b194 100644 --- a/heat/api/openstack/v1/util.py +++ b/heat/api/openstack/v1/util.py @@ -93,6 +93,7 @@ def remote_error(ex, force_exists=False): 'ValueError': client_error, 'StackNotFound': exc.HTTPNotFound, 'InvalidTenant': exc.HTTPForbidden, + 'StackExists': exc.HTTPConflict, } Exc = error_map.get(ex.exc_type, exc.HTTPInternalServerError) diff --git a/heat/common/exception.py b/heat/common/exception.py index d58b040b..8a170399 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -211,3 +211,7 @@ class InvalidTenant(OpenstackException): class StackNotFound(OpenstackException): message = _("The Stack (%(stack_name)s) could not be found.") + + +class StackExists(OpenstackException): + message = _("The Stack (%(stack_name)s) already exists.") diff --git a/heat/engine/service.py b/heat/engine/service.py index 81b463c0..2ed405bb 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -197,7 +197,7 @@ class EngineService(service.Service): logger.info('template is %s' % template) if db_api.stack_get_by_name(context, stack_name): - raise AttributeError('Stack already exists with that name') + raise exception.StackExists(stack_name=stack_name) tmpl = parser.Template(template) diff --git a/heat/tests/test_api_cfn_v1.py b/heat/tests/test_api_cfn_v1.py index 95b6278b..44b85f43 100644 --- a/heat/tests/test_api_cfn_v1.py +++ b/heat/tests/test_api_cfn_v1.py @@ -490,6 +490,40 @@ class StackControllerTest(unittest.TestCase): self.assertEqual(type(result), exception.HeatInvalidParameterValueError) + def test_create_err_exists(self): + # Format a dummy request + stack_name = "wordpress" + template = {u'Foo': u'bar'} + json_template = json.dumps(template) + params = {'Action': 'CreateStack', 'StackName': stack_name, + 'TemplateBody': '%s' % json_template, + 'TimeoutInMinutes': 30, + 'Parameters.member.1.ParameterKey': 'InstanceType', + 'Parameters.member.1.ParameterValue': 'm1.xlarge'} + engine_parms = {u'InstanceType': u'm1.xlarge'} + engine_args = {'timeout_mins': u'30'} + dummy_req = self._dummy_GET_request(params) + + # Insert an engine RPC error and ensure we map correctly to the + # heat exception type + self.m.StubOutWithMock(rpc, 'call') + + rpc.call(dummy_req.context, self.topic, + {'method': 'create_stack', + 'args': {'stack_name': stack_name, + 'template': template, + 'params': engine_parms, + 'args': engine_args}, + 'version': self.api_version}, None + ).AndRaise(rpc_common.RemoteError("StackExists")) + + self.m.ReplayAll() + + result = self.controller.create(dummy_req) + + self.assertEqual(type(result), + exception.HeatInvalidParameterValueError) + def test_create_err_engine(self): # Format a dummy request stack_name = "wordpress" diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index 8e733ebd..e9b19fd8 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -379,6 +379,34 @@ class StackControllerTest(ControllerTest, unittest.TestCase): req, tenant_id=self.tenant, body=body) self.m.VerifyAll() + def test_create_err_existing(self): + stack_name = "wordpress" + template = {u'Foo': u'bar'} + parameters = {u'InstanceType': u'm1.xlarge'} + json_template = json.dumps(template) + body = {'template': template, + 'stack_name': stack_name, + 'parameters': parameters, + 'timeout_mins': 30} + + req = self._post('/stacks', json.dumps(body)) + + self.m.StubOutWithMock(rpc, 'call') + rpc.call(req.context, self.topic, + {'method': 'create_stack', + 'args': {'stack_name': stack_name, + 'template': template, + 'params': parameters, + 'args': {'timeout_mins': 30}}, + 'version': self.api_version}, + None).AndRaise(rpc_common.RemoteError("StackExists")) + self.m.ReplayAll() + + self.assertRaises(webob.exc.HTTPConflict, + self.controller.create, + req, tenant_id=self.tenant, body=body) + self.m.VerifyAll() + def test_create_err_engine(self): stack_name = "wordpress" template = {u'Foo': u'bar'} diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 60c81cda..d4cd759a 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -412,7 +412,7 @@ class stackServiceTest(unittest.TestCase): self.ctx, 'wibble') def test_stack_create_existing(self): - self.assertRaises(AttributeError, self.man.create_stack, + self.assertRaises(exception.StackExists, self.man.create_stack, self.ctx, self.stack_name, self.stack.t, {}, {}) def test_stack_by_name_tenants(self):