From b8ba69e05f8a51158f27142e354adc20a1e31149 Mon Sep 17 00:00:00 2001 From: Ton Ngo Date: Thu, 24 Jul 2014 06:01:37 -0700 Subject: [PATCH] Pass list of parameters to engine service to reset For stack-update, a new argument named clear-parameters with a list is passed in from the CLI and the new PATCH ReST API to delete the indicated parameters from the existing parameters in the DB, allowing the default parameters in the template to be used. A new method in environment handles the reset. Partially-implements: blueprint troubleshooting-low-level-control Partial-Bug: 1224828 Change-Id: Ia1270b679f27e264e6977c590d676b947c74c5da --- heat/engine/environment.py | 6 +++++- heat/engine/service.py | 4 +++- heat/rpc/api.py | 6 ++++-- heat/tests/test_environment.py | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 9ef0bbd940..0a7818e478 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -367,11 +367,15 @@ class Environment(object): self.registry.load(env_snippet.get(env_fmt.RESOURCE_REGISTRY, {})) 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 we are reusing as default the previous parameter values. """ 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 previous_parameters.update(self.params) self.params = previous_parameters diff --git a/heat/engine/service.py b/heat/engine/service.py index cee9fb0965..20a4dc09fa 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -658,7 +658,9 @@ class EngineService(service.Service): current_stack.disable_rollback) env = environment.Environment(params) 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, env, **common_params) updated_stack.parameters.set_stack_id(current_stack.identifier()) diff --git a/heat/rpc/api.py b/heat/rpc/api.py index fe5a6ee550..c6744169a5 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -15,10 +15,12 @@ ENGINE_TOPIC = 'engine' PARAM_KEYS = ( 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', - 'show_deleted', 'show_nested', 'existing' + 'show_deleted', 'show_nested', 'existing', + 'clear_parameters' ) STACK_KEYS = ( diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index 62febfff7c..edd5b6d605 100644 --- a/heat/tests/test_environment.py +++ b/heat/tests/test_environment.py @@ -73,6 +73,33 @@ class EnvironmentTest(common.HeatTestCase): env.patch_previous_parameters(prev_env) 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): self.g_env.register_class('CloudX::Nova::Server', generic_resource.GenericResource)