Check stack adopt enable before adopting
If the configuration is disabled, don't start to adopt. Co-Authored-by: huangtianhua <huangtianhua@huawei.com> Co-Authored-by: asalkeld <asalkeld@mirantis.com> Change-Id: Iddb5024971f9f7882c5e46d879439182d2a92124 Closes-Bug: #1396917
This commit is contained in:
parent
2b5f5be2ab
commit
0217812261
|
@ -575,11 +575,14 @@ class EngineService(service.Service):
|
||||||
params, files, args, owner_id=None,
|
params, files, args, owner_id=None,
|
||||||
nested_depth=0, user_creds_id=None,
|
nested_depth=0, user_creds_id=None,
|
||||||
stack_user_project_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
|
# If it is stack-adopt, use parameters from adopt_stack_data
|
||||||
common_params = api.extract_args(args)
|
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:
|
if rpc_api.PARAM_ADOPT_STACK_DATA in common_params:
|
||||||
params[rpc_api.STACK_PARAMETERS] = 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
|
# Create/Adopt a stack, and create the periodic task if successful
|
||||||
if stack.adopt_stack_data:
|
if stack.adopt_stack_data:
|
||||||
if not cfg.CONF.enable_stack_adopt:
|
|
||||||
raise exception.NotSupported(feature='Stack Adopt')
|
|
||||||
|
|
||||||
stack.adopt()
|
stack.adopt()
|
||||||
elif stack.status != stack.FAILED:
|
elif stack.status != stack.FAILED:
|
||||||
stack.create()
|
stack.create()
|
||||||
|
|
|
@ -556,14 +556,12 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
|
||||||
self.assertEqual(exception.StackValidationFailed, ex.exc_info[0])
|
self.assertEqual(exception.StackValidationFailed, ex.exc_info[0])
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_stack_adopt_with_params(self):
|
def _get_stack_adopt_data_and_template(self, environment=None):
|
||||||
cfg.CONF.set_override('enable_stack_adopt', True)
|
|
||||||
template = {
|
template = {
|
||||||
"heat_template_version": "2013-05-23",
|
"heat_template_version": "2013-05-23",
|
||||||
"parameters": {"app_dbx": {"type": "string"}},
|
"parameters": {"app_dbx": {"type": "string"}},
|
||||||
"resources": {"res1": {"type": "GenericResourceType"}}}
|
"resources": {"res1": {"type": "GenericResourceType"}}}
|
||||||
|
|
||||||
environment = {'parameters': {"app_dbx": "test"}}
|
|
||||||
adopt_data = {
|
adopt_data = {
|
||||||
"status": "COMPLETE",
|
"status": "COMPLETE",
|
||||||
"name": "rtrove1",
|
"name": "rtrove1",
|
||||||
|
@ -578,7 +576,13 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
|
||||||
"action": "CREATE",
|
"action": "CREATE",
|
||||||
"type": "GenericResourceType",
|
"type": "GenericResourceType",
|
||||||
"metadata": {}}}}
|
"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',
|
res._register_class('GenericResourceType',
|
||||||
generic_rsrc.GenericResource)
|
generic_rsrc.GenericResource)
|
||||||
result = self.man.create_stack(self.ctx, "test_adopt_stack",
|
result = self.man.create_stack(self.ctx, "test_adopt_stack",
|
||||||
|
@ -590,6 +594,23 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase):
|
||||||
self.assertEqual(environment['parameters'],
|
self.assertEqual(environment['parameters'],
|
||||||
stack.parameters['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):
|
def test_stack_create_invalid_stack_name(self):
|
||||||
stack_name = 'service_create/test_stack'
|
stack_name = 'service_create/test_stack'
|
||||||
stack = get_wordpress_stack('test_stack', self.ctx)
|
stack = get_wordpress_stack('test_stack', self.ctx)
|
||||||
|
|
Loading…
Reference in New Issue