Merge "Check stack adopt enable before adopting"

This commit is contained in:
Jenkins 2014-12-18 12:32:24 +00:00 committed by Gerrit Code Review
commit 1d8d3ec066
2 changed files with 30 additions and 9 deletions

View File

@ -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()

View File

@ -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)