Skip to content

Commit

Permalink
Display yaml format for stack deployed via hot template
Browse files Browse the repository at this point in the history
Determine hot template and display yaml format for it, display json
format for others.

Change-Id: Ie8d72c222a992ee0048897d040e8bc88fcf51760
Fixes: bug #1201482
  • Loading branch information
JUN JIE NAN committed Jul 16, 2013
1 parent b417688 commit e147586
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
53 changes: 53 additions & 0 deletions heatclient/tests/test_shell.py
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion heatclient/v1/shell.py
Expand Up @@ -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='<URL>',
Expand Down

0 comments on commit e147586

Please sign in to comment.