From a51ee8e1e90c70e52458841f0c0b5a92c9904c7f Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Fri, 2 Mar 2018 15:34:14 +0100 Subject: [PATCH] Use poll_for_events in undercloud install The undercloud deploy command reimplemented poorly the poll_for_events function, calling get_stack uselessly and resolving outputs. This fixes it. Change-Id: I9a1c64d5ee7336d9943aeb100f7dc4a6e4cc3402 --- tripleoclient/utils.py | 2 +- tripleoclient/v1/undercloud_deploy.py | 42 ++++----------------------- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 6344ae25f..348bfa0c4 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -168,7 +168,7 @@ def wait_for_stack_ready(orchestration_client, stack_name, marker=None, stack = get_stack(orchestration_client, stack_name) if not stack: return False - stack_name = stack.stack_name + stack_name = "%s/%s" % (stack.stack_name, stack.id) if verbose: out = sys.stdout diff --git a/tripleoclient/v1/undercloud_deploy.py b/tripleoclient/v1/undercloud_deploy.py index 9a2991396..0dcebdb71 100644 --- a/tripleoclient/v1/undercloud_deploy.py +++ b/tripleoclient/v1/undercloud_deploy.py @@ -43,7 +43,6 @@ except ImportError: from cliff import command from heatclient.common import event_utils from heatclient.common import template_utils -from heatclient.common import utils as heat_utils from openstackclient.i18n import _ from tripleoclient import constants @@ -375,39 +374,7 @@ class DeployUndercloud(command.Command): stack = orchestration_client.stacks.create(**stack_args) stack_id = stack['stack']['id'] - return stack_id - - def _wait_for_heat_complete(self, orchestration_client, stack_id, timeout): - - # Wait for the stack to go to COMPLETE. - timeout_t = time.time() + 60 * timeout - marker = None - event_log_context = heat_utils.EventLogContext() - kwargs = { - 'sort_dir': 'asc', - 'nested_depth': '6' - } - while True: - time.sleep(2) - events = event_utils.get_events( - orchestration_client, - stack_id=stack_id, - event_args=kwargs, - marker=marker) - if events: - marker = getattr(events[-1], 'id', None) - events_log = heat_utils.event_log_formatter( - events, event_log_context) - print(events_log) - - status = orchestration_client.stacks.get(stack_id).status - if status == 'FAILED': - raise Exception('Stack create failed') - if status == 'COMPLETE': - break - if time.time() > timeout_t: - msg = 'Stack creation timeout: %d minutes elapsed' % (timeout) - raise Exception(msg) + return "%s/%s" % (stack_name, stack_id) def _download_ansible_playbooks(self, client, stack_name, output_dir): stack_config = config.Config(client) @@ -578,8 +545,11 @@ class DeployUndercloud(command.Command): self._deploy_tripleo_heat_templates(orchestration_client, parsed_args) # Wait for complete.. - self._wait_for_heat_complete(orchestration_client, stack_id, - parsed_args.timeout) + status, msg = event_utils.poll_for_events( + orchestration_client, stack_id, nested_depth=6) + if status != "CREATE_COMPLETE": + raise Exception("Stack create failed; %s" % msg) + # download the ansible playbooks and execute them. ansible_dir = \ self._download_ansible_playbooks(orchestration_client,