Don't always resolve outputs when showing a stack
* Whenever a stack is created/updated/adopted, a call to show the stack is made. Do not resolve the outputs when showing the stack in this case because: * If we are not waiting (there is no --wait arg) for the stack to complete after a create/update/adopt command and immediately showing the stack, resolving the outputs is just incurring a pointless processing hit on the server (ultimately heat-engine) and delaying a response to the client. * Whether we --wait or or not, we only show "short" stack info which doesn't include outputs anyway. So, let's avoid the processing/time overhead of resolving the outputs. (In theory, with --wait we might want to show "long" output with stack outputs afterwards, but that would be additional functionality that should be handled in a different patch) * Add the --no-resolve-outputs option to "stack show" which already exists in the legacy heat stack-show command. Change-Id: Id0661b11fd3cece0df3981488de6976219556d7e Closes-Bug: #1659896 Closes-Bug: #1659899
This commit is contained in:
@@ -380,19 +380,28 @@ class ShowStack(command.ShowOne):
|
|||||||
metavar='<stack>',
|
metavar='<stack>',
|
||||||
help='Stack to display (name or ID)',
|
help='Stack to display (name or ID)',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--no-resolve-outputs', action="store_true",
|
||||||
|
help=_('Do not resolve outputs of the stack.')
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug("take_action(%s)", parsed_args)
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
|
|
||||||
heat_client = self.app.client_manager.orchestration
|
heat_client = self.app.client_manager.orchestration
|
||||||
return _show_stack(heat_client, stack_id=parsed_args.stack,
|
return _show_stack(
|
||||||
format=parsed_args.formatter)
|
heat_client, stack_id=parsed_args.stack,
|
||||||
|
format=parsed_args.formatter,
|
||||||
|
resolve_outputs=(not parsed_args.no_resolve_outputs))
|
||||||
|
|
||||||
|
|
||||||
def _show_stack(heat_client, stack_id, format='', short=False):
|
def _show_stack(heat_client, stack_id, format='', short=False,
|
||||||
|
resolve_outputs=True):
|
||||||
try:
|
try:
|
||||||
data = heat_client.stacks.get(stack_id=stack_id)
|
_resolve_outputs = not short and resolve_outputs
|
||||||
|
data = heat_client.stacks.get(stack_id=stack_id,
|
||||||
|
resolve_outputs=_resolve_outputs)
|
||||||
except heat_exc.HTTPNotFound:
|
except heat_exc.HTTPNotFound:
|
||||||
raise exc.CommandError('Stack not found: %s' % stack_id)
|
raise exc.CommandError('Stack not found: %s' % stack_id)
|
||||||
else:
|
else:
|
||||||
@@ -408,11 +417,10 @@ def _show_stack(heat_client, stack_id, format='', short=False):
|
|||||||
]
|
]
|
||||||
|
|
||||||
if not short:
|
if not short:
|
||||||
columns += [
|
columns.append('parameters')
|
||||||
'parameters',
|
if _resolve_outputs:
|
||||||
'outputs',
|
columns.append('outputs')
|
||||||
'links',
|
columns.append('links')
|
||||||
]
|
|
||||||
|
|
||||||
exclude_columns = ('template_description',)
|
exclude_columns = ('template_description',)
|
||||||
for key in data.to_dict():
|
for key in data.to_dict():
|
||||||
|
@@ -149,7 +149,8 @@ class TestStackCreate(TestStack):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.stack_client.create.assert_called_with(**self.defaults)
|
self.stack_client.create.assert_called_with(**self.defaults)
|
||||||
self.stack_client.get.assert_called_with(**{'stack_id': '1234'})
|
self.stack_client.get.assert_called_with(**{'stack_id': '1234',
|
||||||
|
'resolve_outputs': False})
|
||||||
|
|
||||||
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
||||||
return_value=('CREATE_FAILED',
|
return_value=('CREATE_FAILED',
|
||||||
@@ -347,7 +348,8 @@ class TestStackUpdate(TestStack):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.stack_client.update.assert_called_with(**self.defaults)
|
self.stack_client.update.assert_called_with(**self.defaults)
|
||||||
self.stack_client.get.assert_called_with(**{'stack_id': 'my_stack'})
|
self.stack_client.get.assert_called_with(**{'stack_id': 'my_stack',
|
||||||
|
'resolve_outputs': False})
|
||||||
|
|
||||||
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
||||||
return_value=('UPDATE_FAILED',
|
return_value=('UPDATE_FAILED',
|
||||||
@@ -414,6 +416,16 @@ class TestStackShow(TestStack):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
self.stack_client.get.assert_called_with(**{
|
self.stack_client.get.assert_called_with(**{
|
||||||
'stack_id': 'my_stack',
|
'stack_id': 'my_stack',
|
||||||
|
'resolve_outputs': True,
|
||||||
|
})
|
||||||
|
|
||||||
|
def test_stack_show_explicit_no_resolve(self):
|
||||||
|
arglist = ['--no-resolve-outputs', '--format', self.format, 'my_stack']
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
self.stack_client.get.assert_called_with(**{
|
||||||
|
'stack_id': 'my_stack',
|
||||||
|
'resolve_outputs': False,
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_stack_show_short(self):
|
def test_stack_show_short(self):
|
||||||
@@ -729,7 +741,8 @@ class TestStackAdopt(TestStack):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.stack_client.create.assert_called_with(**self.defaults)
|
self.stack_client.create.assert_called_with(**self.defaults)
|
||||||
self.stack_client.get.assert_called_with(**{'stack_id': '1234'})
|
self.stack_client.get.assert_called_with(**{'stack_id': '1234',
|
||||||
|
'resolve_outputs': False})
|
||||||
|
|
||||||
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
@mock.patch('heatclient.common.event_utils.poll_for_events',
|
||||||
return_value=('ADOPT_FAILED',
|
return_value=('ADOPT_FAILED',
|
||||||
|
Reference in New Issue
Block a user