From e14758686f71932c5fe5c884bdf7344a1f339d0a Mon Sep 17 00:00:00 2001 From: JUN JIE NAN Date: Tue, 16 Jul 2013 13:45:20 +0800 Subject: [PATCH] Display yaml format for stack deployed via hot template Determine hot template and display yaml format for it, display json format for others. Change-Id: Ie8d72c222a992ee0048897d040e8bc88fcf51760 Fixes: bug #1201482 --- heatclient/tests/test_shell.py | 53 ++++++++++++++++++++++++++++++++++ heatclient/v1/shell.py | 5 +++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index 5356aadb..3043f968 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -304,6 +304,59 @@ def test_describe(self): for r in required: self.assertRegexpMatches(list_text, r) + def test_template_show_cfn(self): + fakes.script_keystone_client() + template_data = open(os.path.join(TEST_VAR_DIR, + 'minimal.template')).read() + resp = fakes.FakeHTTPResponse( + 200, + 'OK', + {'content-type': 'application/json'}, + template_data) + resp_dict = json.loads(template_data) + v1client.Client.json_request( + 'GET', '/stacks/teststack/template').AndReturn((resp, resp_dict)) + + self.m.ReplayAll() + + show_text = self.shell('template-show teststack') + required = [ + '{', + ' "AWSTemplateFormatVersion": "2010-09-09",', + ' "Outputs": {},', + ' "Resources": {},', + ' "Parameters": {}', + '}' + ] + for r in required: + self.assertRegexpMatches(show_text, r) + + def test_template_show_hot(self): + fakes.script_keystone_client() + resp_dict = {"heat_template_version": "2013-05-23", + "parameters": {}, + "resources": {}, + "outputs": {}} + resp = fakes.FakeHTTPResponse( + 200, + 'OK', + {'content-type': 'application/json'}, + json.dumps(resp_dict)) + v1client.Client.json_request( + 'GET', '/stacks/teststack/template').AndReturn((resp, resp_dict)) + + self.m.ReplayAll() + + show_text = self.shell('template-show teststack') + required = [ + "heat_template_version: '2013-05-23'", + "outputs: {}", + "parameters: {}", + "resources: {}" + ] + for r in required: + self.assertRegexpMatches(show_text, r) + def test_create(self): fakes.script_keystone_client() resp = fakes.FakeHTTPResponse( diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 6b80e994..93ef0ea3 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -282,7 +282,10 @@ def do_template_show(hc, args): except exc.HTTPNotFound: raise exc.CommandError('Stack not found: %s' % args.id) else: - print json.dumps(template, indent=2) + if 'heat_template_version' in template: + print yaml.safe_dump(template, indent=2) + else: + print json.dumps(template, indent=2) @utils.arg('-u', '--template-url', metavar='',