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='',