Merge "Change the overcloud delete command to use undeploy_plan"

This commit is contained in:
Zuul 2018-12-06 15:02:25 +00:00 committed by Gerrit Code Review
commit f3e5bd5c75
4 changed files with 47 additions and 17 deletions

View File

@ -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.

View File

@ -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(

View File

@ -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.")

View File

@ -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
)