From 0217812261482d238150e8dea4fc8fa56eb332a4 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 18 Dec 2014 12:09:11 +1000 Subject: [PATCH] Check stack adopt enable before adopting If the configuration is disabled, don't start to adopt. Co-Authored-by: huangtianhua Co-Authored-by: asalkeld Change-Id: Iddb5024971f9f7882c5e46d879439182d2a92124 Closes-Bug: #1396917 --- heat/engine/service.py | 12 ++++++------ heat/tests/test_engine_service.py | 27 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/heat/engine/service.py b/heat/engine/service.py index 52c4a9a228..5c0781444a 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -575,11 +575,14 @@ class EngineService(service.Service): params, files, args, owner_id=None, nested_depth=0, user_creds_id=None, stack_user_project_id=None): - tmpl = templatem.Template(template, files=files) - self._validate_new_stack(cnxt, stack_name, tmpl) - # If it is stack-adopt, use parameters from adopt_stack_data common_params = api.extract_args(args) + if (rpc_api.PARAM_ADOPT_STACK_DATA in common_params and + not cfg.CONF.enable_stack_adopt): + raise exception.NotSupported(feature='Stack Adopt') + + tmpl = templatem.Template(template, files=files) + self._validate_new_stack(cnxt, stack_name, tmpl) if rpc_api.PARAM_ADOPT_STACK_DATA in common_params: params[rpc_api.STACK_PARAMETERS] = common_params[ @@ -661,9 +664,6 @@ class EngineService(service.Service): # Create/Adopt a stack, and create the periodic task if successful if stack.adopt_stack_data: - if not cfg.CONF.enable_stack_adopt: - raise exception.NotSupported(feature='Stack Adopt') - stack.adopt() elif stack.status != stack.FAILED: stack.create() diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index bd9b5d9ee4..7e8d27b29b 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -556,14 +556,12 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase): self.assertEqual(exception.StackValidationFailed, ex.exc_info[0]) self.m.VerifyAll() - def test_stack_adopt_with_params(self): - cfg.CONF.set_override('enable_stack_adopt', True) + def _get_stack_adopt_data_and_template(self, environment=None): template = { "heat_template_version": "2013-05-23", "parameters": {"app_dbx": {"type": "string"}}, "resources": {"res1": {"type": "GenericResourceType"}}} - environment = {'parameters': {"app_dbx": "test"}} adopt_data = { "status": "COMPLETE", "name": "rtrove1", @@ -578,7 +576,13 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase): "action": "CREATE", "type": "GenericResourceType", "metadata": {}}}} + return template, adopt_data + def test_stack_adopt_with_params(self): + cfg.CONF.set_override('enable_stack_adopt', True) + environment = {'parameters': {"app_dbx": "test"}} + template, adopt_data = self._get_stack_adopt_data_and_template( + environment) res._register_class('GenericResourceType', generic_rsrc.GenericResource) result = self.man.create_stack(self.ctx, "test_adopt_stack", @@ -590,6 +594,23 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase): self.assertEqual(environment['parameters'], stack.parameters['parameters']) + def test_stack_adopt_disabled(self): + # to test disable stack adopt + cfg.CONF.set_override('enable_stack_adopt', False) + environment = {'parameters': {"app_dbx": "test"}} + template, adopt_data = self._get_stack_adopt_data_and_template( + environment) + res._register_class('GenericResourceType', + generic_rsrc.GenericResource) + ex = self.assertRaises( + dispatcher.ExpectedException, + self.man.create_stack, + self.ctx, "test_adopt_stack_disabled", + template, {}, None, + {'adopt_stack_data': str(adopt_data)}) + self.assertEqual(exception.NotSupported, ex.exc_info[0]) + self.assertIn('Stack Adopt', six.text_type(ex.exc_info[1])) + def test_stack_create_invalid_stack_name(self): stack_name = 'service_create/test_stack' stack = get_wordpress_stack('test_stack', self.ctx)