From 27c02a58c9d8bf36b5c86b8f914702fb84ebd945 Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Tue, 16 Jun 2020 10:34:44 -0400 Subject: [PATCH] [train-only] Store overcloud status locally After undercloud upgrade, there maybe a need to check for the overcloud status. With mistral and swift dropped from the undercloud in wallaby, we need to store the status locally before upgrading undercloud. This is train-only as ussuri/victoria are already EOL. Resolves: rhbz#2093228 Change-Id: I1f00077b1e91a41da135e7abaa0a16d9f4b82e8c --- .../overcloud_deploy/test_overcloud_deploy.py | 12 ++++----- tripleoclient/utils.py | 26 ++++++++++++++++++ tripleoclient/v1/overcloud_deploy.py | 27 +++++++++++++------ tripleoclient/v1/overcloud_upgrade.py | 4 ++- tripleoclient/workflows/deployment.py | 20 ++++++++++---- 5 files changed, 69 insertions(+), 20 deletions(-) diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index d9bf267ed..aab3be128 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -1413,8 +1413,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.assertTrue(fixture.mock_config_download.called) self.assertTrue(fixture.mock_set_deployment_status.called) self.assertEqual( - 'deploying', - fixture.mock_set_deployment_status.call_args[0][1]) + 'DEPLOY_SUCCESS', + fixture.mock_set_deployment_status.call_args[-1]['status']) mock_copy.assert_called_once() @mock.patch('tripleoclient.utils.get_stack_output_item', @@ -1452,8 +1452,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.assertTrue(fixture.mock_config_download.called) self.assertTrue(fixture.mock_set_deployment_status.called) self.assertEqual( - 'deploying', - fixture.mock_set_deployment_status.call_args[0][1]) + 'DEPLOY_SUCCESS', + fixture.mock_set_deployment_status.call_args[-1]['status']) mock_copy.assert_called_once() @mock.patch('tripleoclient.utils.get_stack_output_item', @@ -1501,8 +1501,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): self.assertTrue(fixture.mock_config_download.called) self.assertTrue(fixture.mock_set_deployment_status.called) self.assertEqual( - 'failed', - fixture.mock_set_deployment_status.call_args[0][1]) + 'DEPLOY_FAILED', + fixture.mock_set_deployment_status.call_args[-1]['status']) @mock.patch('tripleoclient.utils.get_stack_output_item', autospec=True) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index afd085f7d..b74155486 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -2011,6 +2011,32 @@ def ansible_symlink(): run_command(cmd, name='ansible-playbook-3-symlink') +def get_default_working_dir(stack): + return os.path.join( + os.path.expanduser('~'), + "overcloud-deploy", stack) + + +def get_status_yaml(stack_name, working_dir): + status_yaml = os.path.join( + working_dir, + '%s-deployment_status.yaml' % stack_name) + return status_yaml + + +def update_deployment_status(stack_name, status, working_dir): + """Update the deployment status.""" + + if not os.path.exists(working_dir): + makedirs(working_dir) + contents = yaml.safe_dump( + {'deployment_status': status}, + default_flow_style=False) + + safe_write(get_status_yaml(stack_name, working_dir), + contents) + + def check_file_for_enabled_service(env_file): """Checks environment file for the said service. diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 65972af8d..ac0125fd1 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -1058,7 +1058,7 @@ class DeployOvercloud(command.Command): def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) - deploy_status = 'success' + deploy_status = 'DEPLOY_SUCCESS' deploy_message = 'without error' self._setup_clients(parsed_args) @@ -1105,6 +1105,7 @@ class DeployOvercloud(command.Command): # Get a new copy of the stack after stack update/create. If it was # a create then the previous stack object would be None. stack = utils.get_stack(self.orchestration_client, parsed_args.stack) + working_dir = utils.get_default_working_dir(parsed_args.stack) if parsed_args.update_plan_only: # If we are only updating the plan, then we either wont have a @@ -1129,8 +1130,11 @@ class DeployOvercloud(command.Command): if parsed_args.config_download: print("Deploying overcloud configuration") deployment.set_deployment_status( - self.clients, 'deploying', - plan=stack.stack_name) + clients=self.clients, + status='DEPLOYING', + working_dir=working_dir, + plan=stack.stack_name, + ) if not parsed_args.config_download_only: deployment.get_hosts_and_enable_ssh_admin( @@ -1172,13 +1176,21 @@ class DeployOvercloud(command.Command): ), forks=parsed_args.ansible_forks ) + deployment.set_deployment_status( + clients=self.clients, + status=deploy_status, + working_dir=working_dir, + plan=stack.stack_name) except Exception as deploy_e: - deploy_status = 'failed' + deploy_status = 'DEPLOY_FAILED' deploy_message = 'with error' deploy_trace = deploy_e deployment.set_deployment_status( - self.clients, deploy_status, - plan=stack.stack_name) + clients=self.clients, + status=deploy_status, + working_dir=working_dir, + plan=stack.stack_name, + ) finally: # Copy clouds.yaml to the cloud user directory user = getpwuid(os.stat(constants.CLOUD_HOME_DIR).st_uid).pw_name @@ -1195,8 +1207,7 @@ class DeployOvercloud(command.Command): print("Overcloud Horizon Dashboard URL: {0}".format(horizon_url)) print("Overcloud rc file: {0}".format(rcpath)) print("Overcloud Deployed {0}".format(deploy_message)) - - if deploy_status == 'failed': + if deploy_status == 'DEPLOY_FAILED': raise(deploy_trace) diff --git a/tripleoclient/v1/overcloud_upgrade.py b/tripleoclient/v1/overcloud_upgrade.py index d1fb2c6e9..771e80e74 100644 --- a/tripleoclient/v1/overcloud_upgrade.py +++ b/tripleoclient/v1/overcloud_upgrade.py @@ -304,7 +304,9 @@ class UpgradeConverge(UpgradePrepare): def take_action(self, parsed_args): super(UpgradeConverge, self).take_action(parsed_args) + working_dir = oooutils.get_default_working_dir(parsed_args.stack) deployment.set_deployment_status( self.clients, - status='success', + status='DEPLOY_SUCCESS', + working_dir=working_dir, plan=parsed_args.stack) diff --git a/tripleoclient/workflows/deployment.py b/tripleoclient/workflows/deployment.py index 6190044e5..25d3c3b5c 100644 --- a/tripleoclient/workflows/deployment.py +++ b/tripleoclient/workflows/deployment.py @@ -107,9 +107,12 @@ def deploy_and_wait(log, clients, stack, plan_name, verbose_level, verbose_events = verbose_level >= 1 create_result = utils.wait_for_stack_ready( orchestration_client, plan_name, marker, action, verbose_events) + working_dir = utils.get_default_working_dir(plan_name) if not create_result: shell.OpenStackShell().run(["stack", "failures", "list", plan_name]) - set_deployment_status(clients, 'failed', plan=plan_name) + set_deployment_status(clients, 'DEPLOY_FAILED', + working_dir=working_dir, + plan=plan_name) if stack is None: raise exceptions.DeploymentError("Heat Stack create failed.") else: @@ -473,15 +476,17 @@ def get_deployment_status(clients, **workflow_input): payload.get('message', ''))) -def set_deployment_status(clients, status='success', **workflow_input): +def set_deployment_status(clients, status='success', + working_dir='/home/stack/overcloud-deploy/overcloud', + **workflow_input): workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient - if status == 'success': + if status == 'DEPLOY_SUCCESS': workflow = 'tripleo.deployment.v1.set_deployment_status_success' - elif status == 'failed': + elif status == 'DEPLOY_FAILED': workflow = 'tripleo.deployment.v1.set_deployment_status_failed' - elif status == 'deploying': + elif status == 'DEPLOYING': workflow = 'tripleo.deployment.v1.set_deployment_status_deploying' else: raise Exception("Can't set unknown deployment status: %s" % status) @@ -498,6 +503,11 @@ def set_deployment_status(clients, status='success', **workflow_input): # Just continue until workflow is done continue + utils.update_deployment_status( + stack_name=workflow_input['plan'], + status=status, + working_dir=working_dir) + if payload['status'] != 'SUCCESS': raise exceptions.WorkflowServiceError( 'Exception setting deployment status: {}'.format(