Migrate overcloud delete to full workflow
Previously, the overcloud delete only used a workflow to delete the plan. This uses a workflow for stack deletion too. Change-Id: I954416ddcef78625244018e1d885b396164e87fb Closes-Bug: #1657461 Depends-On: Ideeb8b443c862851cd54624a33222d76e14e5751
This commit is contained in:
parent
076df58f30
commit
d6a2db92fc
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
fixes:
|
||||
- Fixes `bug 1657461
|
||||
<https://bugs.launchpad.net/tripleo/+bug/1657461>`__ so the
|
||||
overcloud stack is actually deleted. This calls the newly
|
||||
created stack delete workflow.
|
|
@ -28,20 +28,21 @@ class TestDeleteOvercloud(fakes.TestDeployOvercloud):
|
|||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
|
||||
@mock.patch('tripleoclient.utils.wait_for_stack_ready',
|
||||
autospec=True)
|
||||
def test_stack_delete(self, wait_for_stack_ready_mock):
|
||||
@mock.patch(
|
||||
'tripleoclient.workflows.stack_management.delete_stack', autospec=True)
|
||||
def test_stack_delete(self, mock_delete_stack):
|
||||
clients = self.app.client_manager
|
||||
orchestration_client = clients.orchestration
|
||||
|
||||
self.cmd._stack_delete(orchestration_client, 'overcloud')
|
||||
stack = mock.Mock()
|
||||
stack.id = 12345
|
||||
orchestration_client.stacks.get.return_value = stack
|
||||
|
||||
self.cmd._stack_delete(clients, 'overcloud')
|
||||
|
||||
orchestration_client.stacks.get.assert_called_once_with('overcloud')
|
||||
wait_for_stack_ready_mock.assert_called_once_with(
|
||||
orchestration_client=orchestration_client,
|
||||
stack_name='overcloud',
|
||||
action='DELETE'
|
||||
)
|
||||
mock_delete_stack.assert_called_once_with(
|
||||
clients.workflow_engine, stack=12345)
|
||||
|
||||
def test_stack_delete_no_stack(self):
|
||||
clients = self.app.client_manager
|
||||
|
@ -49,7 +50,7 @@ class TestDeleteOvercloud(fakes.TestDeployOvercloud):
|
|||
type(orchestration_client.stacks.get).return_value = None
|
||||
self.cmd.log.warning = mock.MagicMock()
|
||||
|
||||
self.cmd._stack_delete(orchestration_client, 'overcloud')
|
||||
self.cmd._stack_delete(clients, 'overcloud')
|
||||
|
||||
orchestration_client.stacks.get.assert_called_once_with('overcloud')
|
||||
self.cmd.log.warning.assert_called_once_with(
|
||||
|
|
|
@ -22,6 +22,7 @@ from osc_lib import utils as osc_utils
|
|||
|
||||
from tripleoclient import utils
|
||||
from tripleoclient.workflows import plan_management
|
||||
from tripleoclient.workflows import stack_management
|
||||
|
||||
|
||||
class DeleteOvercloud(command.Command):
|
||||
|
@ -46,7 +47,9 @@ class DeleteOvercloud(command.Command):
|
|||
raise oscexc.CommandError(
|
||||
"You must specify a stack name")
|
||||
|
||||
def _stack_delete(self, orchestration_client, stack_name):
|
||||
def _stack_delete(self, clients, stack_name):
|
||||
orchestration_client = clients.orchestration
|
||||
|
||||
print("Deleting stack {s}...".format(s=stack_name))
|
||||
stack = utils.get_stack(orchestration_client, stack_name)
|
||||
if stack is None:
|
||||
|
@ -54,15 +57,13 @@ class DeleteOvercloud(command.Command):
|
|||
format(s=stack_name))
|
||||
else:
|
||||
try:
|
||||
utils.wait_for_stack_ready(
|
||||
orchestration_client=orchestration_client,
|
||||
stack_name=stack_name,
|
||||
action='DELETE')
|
||||
stack_management.delete_stack(
|
||||
clients.workflow_engine,
|
||||
stack=stack.id
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.error("Exception while waiting for stack to delete "
|
||||
"{}".format(e))
|
||||
raise oscexc.CommandError(
|
||||
"Error occurred while waiting for stack to delete {}".
|
||||
"Error occurred during stack delete {}".
|
||||
format(e))
|
||||
|
||||
def _plan_delete(self, workflow_client, stack_name):
|
||||
|
@ -89,9 +90,8 @@ class DeleteOvercloud(command.Command):
|
|||
raise oscexc.CommandError("Action not confirmed, exiting.")
|
||||
|
||||
clients = self.app.client_manager
|
||||
orchestration_client = clients.orchestration
|
||||
workflow_client = self.app.client_manager.workflow_engine
|
||||
workflow_client = clients.workflow_engine
|
||||
|
||||
self._stack_delete(orchestration_client, parsed_args.stack)
|
||||
self._stack_delete(clients, parsed_args.stack)
|
||||
self._plan_delete(workflow_client, parsed_args.stack)
|
||||
print("Success.")
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright 2017 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from __future__ import print_function
|
||||
|
||||
import uuid
|
||||
|
||||
from tripleoclient.exceptions import InvalidConfiguration
|
||||
from tripleoclient.workflows import base
|
||||
|
||||
|
||||
def delete_stack(clients, stack):
|
||||
"""Deletes the stack named in the workflow_input.
|
||||
|
||||
:param workflow_client: Workflow client
|
||||
:param stack: Name or ID of stack to delete
|
||||
"""
|
||||
|
||||
workflow_client = clients.workflow_engine
|
||||
tripleoclient = clients.tripleoclient
|
||||
|
||||
workflow_input = {
|
||||
'stack': stack,
|
||||
'queue_name': str(uuid.uuid4()),
|
||||
}
|
||||
|
||||
queue_name = workflow_input['queue_name']
|
||||
|
||||
execution = base.start_workflow(
|
||||
workflow_client,
|
||||
'tripleo.stack.v1.delete_stack',
|
||||
workflow_input=workflow_input
|
||||
)
|
||||
|
||||
with tripleoclient.messaging_websocket(queue_name) as ws:
|
||||
rtn_message = ws.wait_for_message(execution.id)
|
||||
if rtn_message['status'] != "SUCCESS":
|
||||
raise InvalidConfiguration(rtn_message['message'])
|
Loading…
Reference in New Issue