Merge "Pass list of parameters to engine service to reset"

This commit is contained in:
Jenkins 2014-09-17 07:32:04 +00:00 committed by Gerrit Code Review
commit cd3e910312
4 changed files with 39 additions and 4 deletions

View File

@ -367,11 +367,15 @@ class Environment(object):
self.registry.load(env_snippet.get(env_fmt.RESOURCE_REGISTRY, {})) self.registry.load(env_snippet.get(env_fmt.RESOURCE_REGISTRY, {}))
self.params.update(env_snippet.get(env_fmt.PARAMETERS, {})) self.params.update(env_snippet.get(env_fmt.PARAMETERS, {}))
def patch_previous_parameters(self, previous_env): def patch_previous_parameters(self, previous_env, clear_parameters=[]):
"""This instance of Environment is the new environment where """This instance of Environment is the new environment where
we are reusing as default the previous parameter values. we are reusing as default the previous parameter values.
""" """
previous_parameters = copy.deepcopy(previous_env.params) previous_parameters = copy.deepcopy(previous_env.params)
# clear the parameters from the previous set as requested
for p in clear_parameters:
previous_parameters.pop(p, None)
# patch the new set of parameters # patch the new set of parameters
previous_parameters.update(self.params) previous_parameters.update(self.params)
self.params = previous_parameters self.params = previous_parameters

View File

@ -658,7 +658,9 @@ class EngineService(service.Service):
current_stack.disable_rollback) current_stack.disable_rollback)
env = environment.Environment(params) env = environment.Environment(params)
if args.get(rpc_api.PARAM_EXISTING, None): if args.get(rpc_api.PARAM_EXISTING, None):
env.patch_previous_parameters(current_stack.env) env.patch_previous_parameters(
current_stack.env,
args.get(rpc_api.PARAM_CLEAR_PARAMETERS, []))
updated_stack = parser.Stack(cnxt, stack_name, tmpl, updated_stack = parser.Stack(cnxt, stack_name, tmpl,
env, **common_params) env, **common_params)
updated_stack.parameters.set_stack_id(current_stack.identifier()) updated_stack.parameters.set_stack_id(current_stack.identifier())

View File

@ -15,10 +15,12 @@ ENGINE_TOPIC = 'engine'
PARAM_KEYS = ( PARAM_KEYS = (
PARAM_TIMEOUT, PARAM_DISABLE_ROLLBACK, PARAM_ADOPT_STACK_DATA, PARAM_TIMEOUT, PARAM_DISABLE_ROLLBACK, PARAM_ADOPT_STACK_DATA,
PARAM_SHOW_DELETED, PARAM_SHOW_NESTED, PARAM_EXISTING PARAM_SHOW_DELETED, PARAM_SHOW_NESTED, PARAM_EXISTING,
PARAM_CLEAR_PARAMETERS
) = ( ) = (
'timeout_mins', 'disable_rollback', 'adopt_stack_data', 'timeout_mins', 'disable_rollback', 'adopt_stack_data',
'show_deleted', 'show_nested', 'existing' 'show_deleted', 'show_nested', 'existing',
'clear_parameters'
) )
STACK_KEYS = ( STACK_KEYS = (

View File

@ -73,6 +73,33 @@ class EnvironmentTest(common.HeatTestCase):
env.patch_previous_parameters(prev_env) env.patch_previous_parameters(prev_env)
self.assertEqual(expected, env.user_env_as_dict()) self.assertEqual(expected, env.user_env_as_dict())
def test_patch_and_clear_existing_parameters(self):
# This tests patching cli parameters over the existing parameters
prev_params = {'foo': 'bar', 'tester': 'Yes',
'another_tester': 'Yes'}
params = {'tester': 'patched'}
expected = {'parameters': {'foo': 'bar', 'tester': 'patched'},
'resource_registry': {'resources': {}}}
prev_env = environment.Environment(
{'parameters': prev_params,
'resource_registry': {'resources': {}}})
env = environment.Environment(params)
env.patch_previous_parameters(prev_env, ['another_tester'])
self.assertEqual(expected, env.user_env_as_dict())
def test_clear_existing_parameters(self):
# This tests removing some parameters in the existing set of parameters
prev_params = {'foo': 'bar', 'tester': 'Yes'}
params = {}
expected = {'parameters': {'foo': 'bar'},
'resource_registry': {'resources': {}}}
prev_env = environment.Environment(
{'parameters': prev_params,
'resource_registry': {'resources': {}}})
env = environment.Environment(params)
env.patch_previous_parameters(prev_env, ['tester'])
self.assertEqual(expected, env.user_env_as_dict())
def test_global_registry(self): def test_global_registry(self):
self.g_env.register_class('CloudX::Nova::Server', self.g_env.register_class('CloudX::Nova::Server',
generic_resource.GenericResource) generic_resource.GenericResource)