diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index 3ac3efff..77e3bd24 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -1497,6 +1497,103 @@ class ShellTestUserPass(ShellBase): for r in required: self.assertRegexpMatches(update_text, r) + @httpretty.activate + def test_stack_update_with_existing_and_default_parameters(self): + self.register_keystone_auth_fixture() + template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') + template_data = open(template_file).read() + resp = fakes.FakeHTTPResponse( + 202, + 'Accepted', + {}, + 'The request is accepted for processing.') + expected_data = { + 'files': {}, + 'environment': {}, + 'template': jsonutils.loads(template_data), + 'parameters': {}, + 'clear_parameters': ['InstanceType', 'DBUsername', + 'DBPassword', 'KeyPairName', + 'LinuxDistribution'], + 'disable_rollback': False} + http.HTTPClient.json_request( + 'PATCH', '/stacks/teststack2/2', + data=expected_data, + headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'} + ).AndReturn((resp, None)) + fakes.script_heat_list() + + self.m.ReplayAll() + + update_text = self.shell( + 'stack-update teststack2/2 ' + '--template-file=%s ' + '--enable-rollback ' + '--existing ' + '--clear-parameter=InstanceType ' + '--clear-parameter=DBUsername ' + '--clear-parameter=DBPassword ' + '--clear-parameter=KeyPairName ' + '--clear-parameter=LinuxDistribution' % template_file) + + required = [ + 'stack_name', + 'id', + 'teststack2', + '1' + ] + for r in required: + self.assertRegexpMatches(update_text, r) + + @httpretty.activate + def test_stack_update_with_patched_and_default_parameters(self): + self.register_keystone_auth_fixture() + template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') + template_data = open(template_file).read() + resp = fakes.FakeHTTPResponse( + 202, + 'Accepted', + {}, + 'The request is accepted for processing.') + expected_data = { + 'files': {}, + 'environment': {}, + 'template': jsonutils.loads(template_data), + 'parameters': {'"KeyPairName': 'updated_key"'}, + 'clear_parameters': ['InstanceType', 'DBUsername', + 'DBPassword', 'KeyPairName', + 'LinuxDistribution'], + 'disable_rollback': False} + http.HTTPClient.json_request( + 'PATCH', '/stacks/teststack2/2', + data=expected_data, + headers={'X-Auth-Key': 'password', 'X-Auth-User': 'username'} + ).AndReturn((resp, None)) + fakes.script_heat_list() + + self.m.ReplayAll() + + update_text = self.shell( + 'stack-update teststack2/2 ' + '--template-file=%s ' + '--enable-rollback ' + '--existing ' + '--parameters="KeyPairName=updated_key" ' + '--clear-parameter=InstanceType ' + '--clear-parameter=DBUsername ' + '--clear-parameter=DBPassword ' + '--clear-parameter=KeyPairName ' + '--clear-parameter=LinuxDistribution' % template_file) + + required = [ + 'stack_name', + 'id', + 'teststack2', + '1' + ] + for r in required: + self.assertRegexpMatches(update_text, r) + @httpretty.activate def test_stack_delete(self): self.register_keystone_auth_fixture() diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index fa8e19ae..93b5d61f 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -368,6 +368,11 @@ def do_stack_show(hc, args): 'Parameters specified in --parameters will patch over the existing ' 'values in the current stack. Parameters omitted will keep ' 'the existing values.') +@utils.arg('-c', '--clear-parameter', metavar='', + help='Remove the parameters from the set of parameters of current ' + 'stack for the stack-update. The default value in the template ' + 'will be used. This can be specified multiple times.', + action='append') @utils.arg('id', metavar='', help='Name or ID of stack to update.') def do_update(hc, args): @@ -409,6 +414,11 @@ def do_update(hc, args): 'Parameters specified in --parameters will patch over the existing ' 'values in the current stack. Parameters omitted will keep ' 'the existing values.') +@utils.arg('-c', '--clear-parameter', metavar='', + help='Remove the parameters from the set of parameters of current ' + 'stack for the stack-update. The default value in the template ' + 'will be used. This can be specified multiple times.', + action='append') @utils.arg('id', metavar='', help='Name or ID of stack to update.') def do_stack_update(hc, args): @@ -434,6 +444,8 @@ def do_stack_update(hc, args): if args.timeout: fields['timeout_mins'] = args.timeout + if args.clear_parameter: + fields['clear_parameters'] = list(args.clear_parameter) if args.rollback is not None: try: