From b64127a01ed5c16bfb8bbfa4d25c67d4577a9dc3 Mon Sep 17 00:00:00 2001 From: apetrich Date: Wed, 7 Nov 2018 14:19:25 +0100 Subject: [PATCH] Change the overcloud delete command to use undeploy_plan We don't have a CLI command to properly undeploy the overcloud. There is a workflow for it, and the GUI uses the right workflow, but the CLI doesn't support it yet. Updating "openstack overcloud delete" command to call the proper workflow Added a release note because this is not a backwards compatible change Change-Id: If14a7876445b052cd255cdd5142ff400a815ace9 Closes-Bug: #1802102 (cherry picked from commit 2ac2e9b57de791c6c5936bb63d979d9c47f186a5) --- ...ove-to-undeploy-plan-067e6070b5f24fa3.yaml | 7 ++++ .../overcloud_delete/test_overcloud_delete.py | 37 +++++++++++++++---- tripleoclient/v1/overcloud_delete.py | 10 ++--- tripleoclient/workflows/stack_management.py | 10 ++--- 4 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 releasenotes/notes/move-to-undeploy-plan-067e6070b5f24fa3.yaml diff --git a/releasenotes/notes/move-to-undeploy-plan-067e6070b5f24fa3.yaml b/releasenotes/notes/move-to-undeploy-plan-067e6070b5f24fa3.yaml new file mode 100644 index 000000000..796e198f7 --- /dev/null +++ b/releasenotes/notes/move-to-undeploy-plan-067e6070b5f24fa3.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + openstack overcloud delete PLAN_NAME now instead of deleting the stack and + the plan instead it undeploys the plan to maintain the correct status + internally and deletes the stack. This is a backwards incompatible change + because we are no longer deleting the plan as it was done previously. diff --git a/tripleoclient/tests/v1/overcloud_delete/test_overcloud_delete.py b/tripleoclient/tests/v1/overcloud_delete/test_overcloud_delete.py index 7b9dada36..4dd069da3 100644 --- a/tripleoclient/tests/v1/overcloud_delete/test_overcloud_delete.py +++ b/tripleoclient/tests/v1/overcloud_delete/test_overcloud_delete.py @@ -29,28 +29,51 @@ class TestDeleteOvercloud(fakes.TestDeployOvercloud): self.workflow = self.app.client_manager.workflow_engine @mock.patch( - 'tripleoclient.workflows.stack_management.delete_stack', autospec=True) - def test_stack_delete(self, mock_delete_stack): + 'tripleoclient.workflows.stack_management.plan_undeploy', + autospec=True) + def test_plan_undeploy(self, mock_plan_undeploy): clients = self.app.client_manager orchestration_client = clients.orchestration stack = mock.Mock() stack.id = 12345 + stack.name = "foobar" orchestration_client.stacks.get.return_value = stack - self.cmd._stack_delete(clients, 'overcloud') + self.cmd._plan_undeploy(clients, 'overcloud') orchestration_client.stacks.get.assert_called_once_with('overcloud') - mock_delete_stack.assert_called_once_with( - clients, stack=12345) + mock_plan_undeploy.assert_called_once_with( + clients, plan="foobar") - def test_stack_delete_no_stack(self): + @mock.patch( + 'tripleoclient.workflows.stack_management.base.start_workflow', + autospec=True) + def test_plan_undeploy_wf_params(self, mock_plan_undeploy_wf): + clients = self.app.client_manager + orchestration_client = clients.orchestration + workflow_engine = clients.workflow_engine + + stack = mock.Mock() + stack.id = 12345 + stack.name = "foobar" + orchestration_client.stacks.get.return_value = stack + + self.cmd._plan_undeploy(clients, 'overcloud') + + orchestration_client.stacks.get.assert_called_once_with('overcloud') + mock_plan_undeploy_wf.assert_called_once_with( + workflow_engine, + "tripleo.deployment.v1.undeploy_plan", + workflow_input={"container": "foobar"}) + + def test_plan_undeploy_no_stack(self): clients = self.app.client_manager orchestration_client = clients.orchestration type(orchestration_client.stacks.get).return_value = None self.cmd.log.warning = mock.MagicMock() - self.cmd._stack_delete(clients, 'overcloud') + self.cmd._plan_undeploy(clients, 'overcloud') orchestration_client.stacks.get.assert_called_once_with('overcloud') self.cmd.log.warning.assert_called_once_with( diff --git a/tripleoclient/v1/overcloud_delete.py b/tripleoclient/v1/overcloud_delete.py index cb2e69a6e..e49e164dc 100644 --- a/tripleoclient/v1/overcloud_delete.py +++ b/tripleoclient/v1/overcloud_delete.py @@ -47,19 +47,19 @@ class DeleteOvercloud(command.Command): raise oscexc.CommandError( "You must specify a stack name") - def _stack_delete(self, clients, stack_name): + def _plan_undeploy(self, clients, stack_name): orchestration_client = clients.orchestration - print("Deleting stack {s}...".format(s=stack_name)) + print("Undeploying stack {s}...".format(s=stack_name)) stack = utils.get_stack(orchestration_client, stack_name) if stack is None: self.log.warning("No stack found ('{s}'), skipping delete". format(s=stack_name)) else: try: - stack_management.delete_stack( + stack_management.plan_undeploy( clients, - stack=stack.id + plan=stack.name ) except Exception as e: raise oscexc.CommandError( @@ -91,6 +91,6 @@ class DeleteOvercloud(command.Command): clients = self.app.client_manager - self._stack_delete(clients, parsed_args.stack) + self._plan_undeploy(clients, parsed_args.stack) self._plan_delete(clients, parsed_args.stack) print("Success.") diff --git a/tripleoclient/workflows/stack_management.py b/tripleoclient/workflows/stack_management.py index 3b78ad002..077efe956 100644 --- a/tripleoclient/workflows/stack_management.py +++ b/tripleoclient/workflows/stack_management.py @@ -18,24 +18,24 @@ from tripleoclient.exceptions import InvalidConfiguration from tripleoclient.workflows import base -def delete_stack(clients, stack): - """Deletes the stack named in the workflow_input. +def plan_undeploy(clients, plan): + """Undeploy the plan and deletes the stack named in the workflow_input. :param workflow_client: Workflow client - :param stack: Name or ID of stack to delete + :param plan: Name or ID of plan to delete """ workflow_client = clients.workflow_engine tripleoclient = clients.tripleoclient workflow_input = { - 'stack': stack + 'container': plan } with tripleoclient.messaging_websocket() as ws: execution = base.start_workflow( workflow_client, - 'tripleo.stack.v1.delete_stack', + 'tripleo.deployment.v1.undeploy_plan', workflow_input=workflow_input )