summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Dobies <jason.dobies@redhat.com>2016-01-06 11:41:56 -0500
committerJay Dobies <jason.dobies@redhat.com>2016-01-06 11:41:56 -0500
commitb06c3daeb78ce15b6a77ebfe75056d3ebed6a023 (patch)
tree1c79130fff57a867c02b9cfbfe6115349e998266
parent09f853d3c39759edd28d0d6849d2587f2197807b (diff)
downloadpython-heatclient-b06c3daeb78ce15b6a77ebfe75056d3ebed6a023.tar.gz
Added -P support to template-validate
Change-Id: Ia6945d6b3f86966a6e585866447db245b1efab2d Partial-Bug: #1508857
-rw-r--r--heatclient/tests/unit/test_shell.py36
-rw-r--r--heatclient/v1/shell.py8
2 files changed, 43 insertions, 1 deletions
diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py
index 908f4b7..7a94144 100644
--- a/heatclient/tests/unit/test_shell.py
+++ b/heatclient/tests/unit/test_shell.py
@@ -955,6 +955,42 @@ class ShellTestUserPass(ShellBase):
for r in required:
self.assertRegexpMatches(show_text, r)
+ def test_template_validate(self):
+ self.register_keystone_auth_fixture()
+ resp_dict = {"heat_template_version": "2013-05-23",
+ "parameters": {},
+ "resources": {},
+ "outputs": {}}
+ resp = fakes.FakeHTTPResponse(
+ 200,
+ 'OK',
+ {'content-type': 'application/json'},
+ jsonutils.dumps(resp_dict))
+ if self.client == http.SessionClient:
+ self.client.request('/validate',
+ 'POST',
+ data=mox.IgnoreArg()
+ ).AndReturn(resp)
+ else:
+ self.client.json_request('POST',
+ '/validate',
+ data=mox.IgnoreArg()
+ ).AndReturn((resp, resp_dict))
+
+ self.m.ReplayAll()
+
+ template_file = os.path.join(TEST_VAR_DIR, 'minimal.template')
+ cmd = 'template-validate -f %s -P foo=bar' % template_file
+ show_text = self.shell(cmd)
+ required = [
+ 'heat_template_version',
+ 'outputs',
+ 'parameters',
+ 'resources'
+ ]
+ for r in required:
+ self.assertRegexpMatches(show_text, r)
+
def _test_stack_preview(self, timeout=None, enable_rollback=False,
tags=None):
self.register_keystone_auth_fixture()
diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py
index 1e8a69a..7be7621 100644
--- a/heatclient/v1/shell.py
+++ b/heatclient/v1/shell.py
@@ -816,8 +816,13 @@ def do_template_show(hc, args):
help=_('URL to retrieve template object (e.g. from swift).'))
@utils.arg('-n', '--show-nested', default=False, action="store_true",
help=_('Resolve parameters from nested templates as well.'))
+@utils.arg('-P', '--parameters', metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
+ help=_('Parameter values for the template. '
+ 'This can be specified multiple times, or once with '
+ 'parameters separated by a semicolon.'),
+ action='append')
def do_template_validate(hc, args):
- '''Validate a template with parameters.'''
+ """Validate a template with parameters."""
tpl_files, template = template_utils.get_template_contents(
args.template_file,
@@ -829,6 +834,7 @@ def do_template_validate(hc, args):
env_paths=args.environment_file)
fields = {
'template': template,
+ 'parameters': utils.format_parameters(args.parameters),
'files': dict(list(tpl_files.items()) + list(env_files.items())),
'environment': env,
}