diff options
author | Steven Hardy <shardy@redhat.com> | 2015-07-25 12:33:56 +0100 |
---|---|---|
committer | Steve Baker <sbaker@redhat.com> | 2015-09-16 11:38:39 +1200 |
commit | 8ee2fc1b3d4df186d0bcc3e16353324a456a1fa0 (patch) | |
tree | b732d06e572a4338721a95b76b3cde7736e08cd7 | |
parent | 8eb188457d9cf7056eea401c4ade6154eab24ede (diff) | |
download | python-heatclient-8ee2fc1b3d4df186d0bcc3e16353324a456a1fa0.tar.gz |
stack-update -x tolerate no template
Replacement for the approach outlined in
https://review.openstack.org/#/c/154692/
This works with the following heat changes to enable
full PATCH update functionality, including omitting
the template or environment:
https://review.openstack.org/#/c/205754/
https://review.openstack.org/#/c/154619/
Closes-Bug: #1224828
Change-Id: I2a82936743badb69f0de5a6ca64f95ae63a35358
-rw-r--r-- | heatclient/common/template_utils.py | 4 | ||||
-rw-r--r-- | heatclient/tests/unit/test_shell.py | 45 | ||||
-rw-r--r-- | heatclient/tests/unit/test_template_utils.py | 6 | ||||
-rw-r--r-- | heatclient/v1/shell.py | 10 |
4 files changed, 61 insertions, 4 deletions
diff --git a/heatclient/common/template_utils.py b/heatclient/common/template_utils.py index ca0885d..e71a3b1 100644 --- a/heatclient/common/template_utils.py +++ b/heatclient/common/template_utils.py @@ -28,7 +28,7 @@ from heatclient.openstack.common._i18n import _ def get_template_contents(template_file=None, template_url=None, template_object=None, object_request=None, - files=None): + files=None, existing=False): # Transform a bare file path to a file:// URL. if template_file: @@ -41,6 +41,8 @@ def get_template_contents(template_file=None, template_url=None, template_url = template_object tpl = object_request and object_request('GET', template_object) + elif existing: + return {}, None else: raise exc.CommandError(_('Need to specify exactly one of ' '%(arg1)s, %(arg2)s or %(arg3)s') % diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index 2495303..133b0e9 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -2223,6 +2223,51 @@ class ShellTestUserPass(ShellBase): for r in required: self.assertRegexpMatches(update_text, r) + def test_stack_update_with_existing_template(self): + self.register_keystone_auth_fixture() + resp = fakes.FakeHTTPResponse( + 202, + 'Accepted', + {}, + 'The request is accepted for processing.') + expected_data = { + 'files': {}, + 'environment': {}, + 'template': None, + 'parameters': {}} + if self.client is http.HTTPClient: + headers = {'X-Auth-Key': 'password', 'X-Auth-User': 'username'} + else: + headers = {} + if self.client == http.SessionClient: + self.client.request( + '/stacks/teststack2/2', 'PATCH', + data=expected_data, + headers=headers + ).AndReturn(resp) + else: + self.client.json_request( + 'PATCH', '/stacks/teststack2/2', + data=expected_data, + headers=headers + ).AndReturn((resp, None)) + fakes.script_heat_list(client=self.client) + + self.m.ReplayAll() + + update_text = self.shell( + 'stack-update teststack2/2 ' + '--existing') + + required = [ + 'stack_name', + 'id', + 'teststack2', + '1' + ] + for r in required: + self.assertRegexpMatches(update_text, r) + def test_stack_update_with_tags(self): self.register_keystone_auth_fixture() template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index 9f917b3..7b584cc 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -436,6 +436,12 @@ class TestGetTemplateContents(testtools.TestCase): '--template-url or --template-object'), str(ex)) + def test_get_template_contents_file_none_existing(self): + files, tmpl_parsed = template_utils.get_template_contents( + existing=True) + self.assertEqual(None, tmpl_parsed) + self.assertEqual({}, files) + def test_get_template_contents_parse_error(self): with tempfile.NamedTemporaryFile() as tmpl_file: diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 386a045..59c3607 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -442,11 +442,14 @@ def do_stack_show(hc, args): 'would be the content of the file'), action='append') @utils.arg('-x', '--existing', default=False, action="store_true", - help=_('Re-use the set of parameters of the current stack. ' + help=_('Re-use the template, parameters and environment of the ' + 'current stack. If the template argument is omitted then the ' + 'existing template is used. If no %(env_arg)s is specified then ' + 'the existing environment is used. ' 'Parameters specified in %(arg)s will patch over the existing ' 'values in the current stack. Parameters omitted will keep ' 'the existing values.') - % {'arg': '--parameters'}) + % {'arg': '--parameters', 'env_arg': '--environment-file'}) @utils.arg('-c', '--clear-parameter', metavar='<PARAMETER>', help=_('Remove the parameters from the set of parameters of ' 'current stack for the %(cmd)s. The default value in the ' @@ -464,7 +467,8 @@ def do_stack_update(hc, args): args.template_file, args.template_url, args.template_object, - _authenticated_fetcher(hc)) + _authenticated_fetcher(hc), + existing=args.existing) env_files, env = template_utils.process_multiple_environments_and_files( env_paths=args.environment_file) |