From 9be4f9cb4d360cecb4e76119431866ba67625a55 Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Wed, 16 Sep 2020 12:13:13 +0100 Subject: [PATCH] overcloud status report the correct cd for the given plan Choose the most recent execution with the correct plan_name in the input field. Also push the filtering/ordering up to the mistral REST API where possible. Change-Id: I12c28237053bcbd52b60f2abda2194fd7d80c2b5 Closes-bug: #1895824 --- tripleo_common/actions/deployment.py | 19 ++++--- .../tests/actions/test_deployment.py | 50 ++++++++++++++++--- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/tripleo_common/actions/deployment.py b/tripleo_common/actions/deployment.py index 9b398880c..bec735fec 100644 --- a/tripleo_common/actions/deployment.py +++ b/tripleo_common/actions/deployment.py @@ -450,14 +450,17 @@ class DeploymentStatusAction(base.TripleOAction): # Will get set to new status if an update is required status_update = None - cd_execs = workflow_client.executions.find( - workflow_name='tripleo.deployment.v1.config_download_deploy') - cd_execs.sort(key=lambda x: x.updated_at) - if cd_execs: - cd_exec = workflow_client.executions.get(cd_execs[-1].id) - cd_status = cd_exec.state - ansible_status = json.loads( - cd_exec.output).get('deployment_status') + for cd_exec in workflow_client.executions.list( + sort_keys="updated_at", + sort_dirs="desc", + fields=['input', 'output', 'state'], + workflow_name='tripleo.deployment.v1.config_download_deploy' + ): + if json.loads(cd_exec.input).get('plan_name') == self.plan: + cd_status = cd_exec.state + ansible_status = json.loads( + cd_exec.output).get('deployment_status') + break def update_status(status): # If we need to update the status return it diff --git a/tripleo_common/tests/actions/test_deployment.py b/tripleo_common/tests/actions/test_deployment.py index e56c79ba6..67ee7cfe3 100644 --- a/tripleo_common/tests/actions/test_deployment.py +++ b/tripleo_common/tests/actions/test_deployment.py @@ -751,8 +751,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_SUCCESS"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -782,8 +783,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_SUCCESS"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -813,8 +815,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_SUCCESS"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -844,8 +847,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_SUCCESS"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -875,8 +879,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_FAILED"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -906,8 +911,9 @@ class DeploymentStatusActionTest(base.TestCase): execution.updated_at = 1 execution.state = 'SUCCESS' execution.output = '{"deployment_status":"DEPLOY_SUCCESS"}' + execution.input = '{"plan_name":"overcloud"}' mistral().executions.get.return_value = execution - mistral().executions.find.return_value = [execution] + mistral().executions.list.return_value = [execution] action = deployment.DeploymentStatusAction(self.plan) result = action.run(self.ctx) @@ -915,6 +921,38 @@ class DeploymentStatusActionTest(base.TestCase): self.assertEqual(result['status_update'], None) self.assertEqual(result['deployment_status'], None) + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_object_client') + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_workflow_client') + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') + def test_get_deployment_status_different_plan( + self, heat, mistral, swift): + + mock_stack = mock.Mock() + mock_stack.stack_status = 'COMPLETE' + heat().stacks.get.return_value = mock_stack + + body = 'deployment_status: DEPLOY_SUCCESS' + swift().get_object.return_value = [mock.Mock(), body] + + execution = mock.Mock() + execution.updated_at = 1 + execution.state = 'SUCCESS' + execution.output = '{"deployment_status":"DEPLOY_FAILED"}' + execution.input = '{"plan_name":"foobar"}' + mistral().executions.get.return_value = execution + mistral().executions.list.return_value = [execution] + + action = deployment.DeploymentStatusAction(self.plan) + result = action.run(self.ctx) + + self.assertEqual(result['stack_status'], 'COMPLETE') + self.assertEqual(result['cd_status'], None) + self.assertEqual(result['deployment_status'], 'DEPLOY_SUCCESS') + self.assertEqual(result['status_update'], None) + class DeploymentFailuresActionTest(base.TestCase):