Merge "Use stack.get for resolving outputs for old API"

This commit is contained in:
Jenkins 2016-03-28 04:26:23 +00:00 committed by Gerrit Code Review
commit cff00ac9ba
2 changed files with 46 additions and 3 deletions

View File

@ -862,7 +862,17 @@ class OutputShowStack(show.ShowOne):
except heat_exc.HTTPNotFound:
msg = _('Stack %(id)s or output %(out)s not found.') % {
'id': parsed_args.stack, 'out': parsed_args.output}
raise exc.CommandError(msg)
try:
output = None
stack = client.stacks.get(parsed_args.stack).to_dict()
for o in stack.get('outputs', []):
if o['output_key'] == parsed_args.output:
output = o
break
if output is None:
raise exc.CommandError(msg)
except heat_exc.HTTPNotFound:
raise exc.CommandError(msg)
if 'output_error' in output:
msg = _('Output error: %s') % output['output_error']
@ -898,8 +908,12 @@ class OutputListStack(lister.Lister):
try:
outputs = client.stacks.output_list(parsed_args.stack)['outputs']
except heat_exc.HTTPNotFound:
msg = _('Stack not found: %s') % parsed_args.stack
raise exc.CommandError(msg)
try:
outputs = client.stacks.get(
parsed_args.stack).to_dict()['outputs']
except heat_exc.HTTPNotFound:
msg = _('Stack not found: %s') % parsed_args.stack
raise exc.CommandError(msg)
columns = ['output_key', 'description']

View File

@ -846,6 +846,7 @@ class TestStackOutputShow(TestStack):
def test_stack_output_show_bad_output(self):
arglist = ['my_stack', 'output3']
self.stack_client.output_show.side_effect = heat_exc.HTTPNotFound
self.stack_client.get.side_effect = heat_exc.HTTPNotFound
parsed_args = self.check_parser(self.cmd, arglist, [])
error = self.assertRaises(exc.CommandError,
@ -854,15 +855,32 @@ class TestStackOutputShow(TestStack):
str(error))
self.stack_client.output_show.assert_called_with('my_stack', 'output3')
def test_stack_output_show_old_api(self):
arglist = ['my_stack', 'output1']
self.stack_client.output_show.side_effect = heat_exc.HTTPNotFound
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, outputs = self.cmd.take_action(parsed_args)
self.stack_client.get.assert_called_with('my_stack')
self.assertEqual(('output_key', 'output_value'), columns)
self.assertEqual(('output1', 'value1'), outputs)
class TestStackOutputList(TestStack):
response = {'outputs': [{'output_key': 'key1', 'description': 'desc1'},
{'output_key': 'key2', 'description': 'desc2'}]}
stack_response = {
'stack_name': 'my_stack',
'outputs': response['outputs']
}
def setUp(self):
super(TestStackOutputList, self).setUp()
self.cmd = stack.OutputListStack(self.app, None)
self.stack_client.get = mock.MagicMock(
return_value=stacks.Stack(None, self.response))
def test_stack_output_list(self):
arglist = ['my_stack']
@ -877,12 +895,23 @@ class TestStackOutputList(TestStack):
def test_stack_output_list_not_found(self):
arglist = ['my_stack']
self.stack_client.output_list.side_effect = heat_exc.HTTPNotFound
self.stack_client.get.side_effect = heat_exc.HTTPNotFound
parsed_args = self.check_parser(self.cmd, arglist, [])
error = self.assertRaises(exc.CommandError,
self.cmd.take_action, parsed_args)
self.assertEqual('Stack not found: my_stack', str(error))
def test_stack_output_list_old_api(self):
arglist = ['my_stack']
self.stack_client.output_list.side_effect = heat_exc.HTTPNotFound
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, outputs = self.cmd.take_action(parsed_args)
self.stack_client.get.assert_called_with('my_stack')
self.assertEqual(['output_key', 'description'], columns)
class TestStackTemplateShow(TestStack):