Resolve outputs from stack object
There are use cases where user have new heatclient and old version of rpc api ( < 1.19) so heatclient call new api methods that doesn't exist. In this case get stack outputs from stack object. Change-Id: I6c1fdbe13ecb8ae61690e0e7d8bac31405c148c6 Closes-Bug: #1526392
This commit is contained in:
@@ -2619,6 +2619,64 @@ class ShellTestUserPass(ShellBase):
|
|||||||
for r in required:
|
for r in required:
|
||||||
self.assertRegexpMatches(list_text, r)
|
self.assertRegexpMatches(list_text, r)
|
||||||
|
|
||||||
|
def test_output_list_api_400_error(self):
|
||||||
|
self.register_keystone_auth_fixture()
|
||||||
|
outputs = [{
|
||||||
|
"output_key": "key",
|
||||||
|
"description": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_key": "key1",
|
||||||
|
"description": "description1"
|
||||||
|
}]
|
||||||
|
stack_dict = {"stack": {
|
||||||
|
"id": "1",
|
||||||
|
"stack_name": "teststack",
|
||||||
|
"stack_status": 'CREATE_COMPLETE',
|
||||||
|
"creation_time": "2012-10-25T01:58:47Z",
|
||||||
|
"outputs": outputs
|
||||||
|
}}
|
||||||
|
|
||||||
|
stack_resp = fakes.FakeHTTPResponse(
|
||||||
|
200,
|
||||||
|
'OK',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps(stack_dict))
|
||||||
|
resp = fakes.FakeHTTPResponse(
|
||||||
|
404,
|
||||||
|
'Not Found',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps({}))
|
||||||
|
if self.client == http.SessionClient:
|
||||||
|
self.client.request(
|
||||||
|
'/stacks/teststack/1/outputs',
|
||||||
|
'GET').AndRaise(exc.from_response(resp))
|
||||||
|
self.client.request(
|
||||||
|
'/stacks/teststack/1',
|
||||||
|
'GET').AndReturn(stack_resp)
|
||||||
|
else:
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET',
|
||||||
|
'/stacks/teststack/1/outputs').AndRaise(
|
||||||
|
exc.from_response(resp))
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET', '/stacks/teststack/1').AndReturn((stack_resp,
|
||||||
|
stack_dict))
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
list_text = self.shell('output-list teststack/1')
|
||||||
|
|
||||||
|
required = [
|
||||||
|
'output_key',
|
||||||
|
'description',
|
||||||
|
'key',
|
||||||
|
'description',
|
||||||
|
'key1',
|
||||||
|
'description1'
|
||||||
|
]
|
||||||
|
for r in required:
|
||||||
|
self.assertRegexpMatches(list_text, r)
|
||||||
|
|
||||||
def test_output_show_all(self):
|
def test_output_show_all(self):
|
||||||
self.register_keystone_auth_fixture()
|
self.register_keystone_auth_fixture()
|
||||||
|
|
||||||
@@ -2712,6 +2770,62 @@ class ShellTestUserPass(ShellBase):
|
|||||||
for r in required:
|
for r in required:
|
||||||
self.assertRegexpMatches(resp, r)
|
self.assertRegexpMatches(resp, r)
|
||||||
|
|
||||||
|
def test_output_show_api_400_error(self):
|
||||||
|
self.register_keystone_auth_fixture()
|
||||||
|
output = {
|
||||||
|
"output_key": "key",
|
||||||
|
"output_value": "value",
|
||||||
|
'description': 'description'
|
||||||
|
}
|
||||||
|
stack_dict = {"stack": {
|
||||||
|
"id": "1",
|
||||||
|
"stack_name": "teststack",
|
||||||
|
"stack_status": 'CREATE_COMPLETE',
|
||||||
|
"creation_time": "2012-10-25T01:58:47Z",
|
||||||
|
'outputs': [output]
|
||||||
|
}}
|
||||||
|
|
||||||
|
resp = fakes.FakeHTTPResponse(
|
||||||
|
404,
|
||||||
|
'Internal Error',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps({}))
|
||||||
|
if self.client == http.SessionClient:
|
||||||
|
self.client.request(
|
||||||
|
'/stacks/teststack/1/outputs/key',
|
||||||
|
'GET').AndRaise(exc.from_response(resp))
|
||||||
|
self.client.request('/stacks/teststack/1', 'GET').AndReturn(
|
||||||
|
fakes.FakeHTTPResponse(
|
||||||
|
200,
|
||||||
|
'OK',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps(stack_dict)))
|
||||||
|
else:
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET',
|
||||||
|
'/stacks/teststack/1/outputs/key').AndRaise(
|
||||||
|
exc.from_response(resp))
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET', '/stacks/teststack/1').AndReturn((
|
||||||
|
fakes.FakeHTTPResponse(
|
||||||
|
200,
|
||||||
|
'OK',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps(stack_dict)), stack_dict))
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
resp = self.shell('output-show teststack/1 key')
|
||||||
|
required = [
|
||||||
|
'output_key',
|
||||||
|
'output_value',
|
||||||
|
'description',
|
||||||
|
'key',
|
||||||
|
'value',
|
||||||
|
'description',
|
||||||
|
]
|
||||||
|
for r in required:
|
||||||
|
self.assertRegexpMatches(resp, r)
|
||||||
|
|
||||||
def test_output_show_output1(self):
|
def test_output_show_output1(self):
|
||||||
self.register_keystone_auth_fixture()
|
self.register_keystone_auth_fixture()
|
||||||
|
|
||||||
|
@@ -651,15 +651,18 @@ def do_output_list(hc, args):
|
|||||||
try:
|
try:
|
||||||
outputs = hc.stacks.output_list(args.id)
|
outputs = hc.stacks.output_list(args.id)
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
raise exc.CommandError(_('Stack not found: %s') % args.id)
|
try:
|
||||||
else:
|
outputs = hc.stacks.get(args.id).to_dict()
|
||||||
fields = ['output_key', 'description']
|
except exc.HTTPNotFound:
|
||||||
formatters = {
|
raise exc.CommandError(_('Stack not found: %s') % args.id)
|
||||||
'output_key': lambda x: x['output_key'],
|
|
||||||
'description': lambda x: x['description'],
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.print_list(outputs['outputs'], fields, formatters=formatters)
|
fields = ['output_key', 'description']
|
||||||
|
formatters = {
|
||||||
|
'output_key': lambda x: x['output_key'],
|
||||||
|
'description': lambda x: x['description'],
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.print_list(outputs['outputs'], fields, formatters=formatters)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('id', metavar='<NAME or ID>',
|
@utils.arg('id', metavar='<NAME or ID>',
|
||||||
@@ -675,43 +678,64 @@ def do_output_list(hc, args):
|
|||||||
help=_('Returns only output value in specified format.'))
|
help=_('Returns only output value in specified format.'))
|
||||||
def do_output_show(hc, args):
|
def do_output_show(hc, args):
|
||||||
"""Show a specific stack output."""
|
"""Show a specific stack output."""
|
||||||
def show_output_by_key(output_key):
|
def resolve_output(output_key):
|
||||||
try:
|
try:
|
||||||
output = hc.stacks.output_show(args.id, output_key)
|
output = hc.stacks.output_show(args.id, output_key)
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
raise exc.CommandError(_('Stack %(id)s or '
|
try:
|
||||||
'output %(key)s not found.') % {
|
output = None
|
||||||
'id': args.id,
|
stack = hc.stacks.get(args.id).to_dict()
|
||||||
'key': args.output})
|
for o in stack.get('outputs', []):
|
||||||
else:
|
if o['output_key'] == output_key:
|
||||||
if 'output_error' in output['output']:
|
output = {'output': o}
|
||||||
msg = _("Output error: %s") % output['output']['output_error']
|
break
|
||||||
raise exc.CommandError(msg)
|
if output is None:
|
||||||
if args.only_value:
|
raise exc.CommandError(_('Output %(key)s not found.') % {
|
||||||
if (args.format == 'json'
|
'key': args.output})
|
||||||
or isinstance(output['output']['output_value'], dict)
|
except exc.HTTPNotFound:
|
||||||
or isinstance(output['output']['output_value'], list)):
|
raise exc.CommandError(
|
||||||
print(
|
_('Stack %(id)s or output %(key)s not found.') % {
|
||||||
utils.json_formatter(output['output']['output_value']))
|
'id': args.id,
|
||||||
else:
|
'key': args.output})
|
||||||
print(output['output']['output_value'])
|
return output
|
||||||
|
|
||||||
|
def show_output(output):
|
||||||
|
if 'output_error' in output['output']:
|
||||||
|
msg = _("Output error: %s") % output['output']['output_error']
|
||||||
|
raise exc.CommandError(msg)
|
||||||
|
if args.only_value:
|
||||||
|
if (args.format == 'json'
|
||||||
|
or isinstance(output['output']['output_value'], dict)
|
||||||
|
or isinstance(output['output']['output_value'], list)):
|
||||||
|
print(
|
||||||
|
utils.json_formatter(output['output']['output_value']))
|
||||||
else:
|
else:
|
||||||
formatters = {
|
print(output['output']['output_value'])
|
||||||
'output_value': (lambda x: utils.json_formatter(x)
|
else:
|
||||||
if args.format == 'json'
|
formatters = {
|
||||||
else x)
|
'output_value': (lambda x: utils.json_formatter(x)
|
||||||
}
|
if args.format == 'json'
|
||||||
utils.print_dict(output['output'], formatters=formatters)
|
else x)
|
||||||
|
}
|
||||||
|
utils.print_dict(output['output'], formatters=formatters)
|
||||||
|
|
||||||
if args.all:
|
if args.all:
|
||||||
try:
|
try:
|
||||||
outputs = hc.stacks.output_list(args.id)
|
outputs = hc.stacks.output_list(args.id)
|
||||||
|
resolved = False
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
raise exc.CommandError(_('Stack not found: %s') % args.id)
|
try:
|
||||||
|
outputs = hc.stacks.get(args.id).to_dict()
|
||||||
|
resolved = True
|
||||||
|
except exc.HTTPNotFound:
|
||||||
|
raise exc.CommandError(_('Stack not found: %s') % args.id)
|
||||||
for output in outputs['outputs']:
|
for output in outputs['outputs']:
|
||||||
show_output_by_key(output['output_key'])
|
if resolved:
|
||||||
|
show_output({'output': output})
|
||||||
|
else:
|
||||||
|
show_output(resolve_output(output['output_key']))
|
||||||
else:
|
else:
|
||||||
show_output_by_key(args.output)
|
show_output(resolve_output(args.output))
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('-f', '--filters', metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
|
@utils.arg('-f', '--filters', metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
|
||||||
|
Reference in New Issue
Block a user