Migrate the openstack overcloud delete command to use Ansible
The overcloud delete command will now use the ansible playbook found within the tripleo-ansible project to process the stack delete workflow. story: 2007212 task: 2007212 Depends-On: Ic0bd173ad34d1c01a58a66d9a754acd3093a972c Change-Id: I9f461803ecf3abdf46c0b2b629e6e6708f3160cb
This commit is contained in:
parent
c7d49c3079
commit
c94f64ef9a
@ -60,7 +60,7 @@ openstack.tripleoclient.v2 =
|
||||
overcloud_container_image_build = tripleoclient.v1.container_image:BuildImage
|
||||
overcloud_container_image_prepare = tripleoclient.v1.container_image:PrepareImageFiles
|
||||
overcloud_container_image_tag_discover = tripleoclient.v1.container_image:DiscoverImageTag
|
||||
overcloud_delete = tripleoclient.v1.overcloud_delete:DeleteOvercloud
|
||||
overcloud_delete = tripleoclient.v2.overcloud_delete:DeleteOvercloud
|
||||
overcloud_credentials = tripleoclient.v1.overcloud_credentials:OvercloudCredentials
|
||||
overcloud_deploy = tripleoclient.v1.overcloud_deploy:DeployOvercloud
|
||||
overcloud_export = tripleoclient.v1.overcloud_export:ExportOvercloud
|
||||
|
@ -27,6 +27,11 @@ WS_URL = "ws://0.0.0.0"
|
||||
WSS_URL = "wss://0.0.0.0"
|
||||
|
||||
|
||||
class FakeOptions(object):
|
||||
def __init__(self):
|
||||
self.debug = True
|
||||
|
||||
|
||||
class FakeApp(object):
|
||||
def __init__(self):
|
||||
_stdout = None
|
||||
@ -36,6 +41,7 @@ class FakeApp(object):
|
||||
self.stderr = sys.stderr
|
||||
self.restapi = None
|
||||
self.command_options = None
|
||||
self.options = FakeOptions()
|
||||
|
||||
|
||||
class FakeStackObject(object):
|
||||
|
@ -1,57 +0,0 @@
|
||||
# Copyright 2016 Red Hat, Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
from tripleoclient.tests.v1.overcloud_deploy import fakes
|
||||
from tripleoclient.v1 import overcloud_delete
|
||||
|
||||
|
||||
class TestDeleteOvercloud(fakes.TestDeployOvercloud):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeleteOvercloud, self).setUp()
|
||||
|
||||
self.cmd = overcloud_delete.DeleteOvercloud(self.app, None)
|
||||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
|
||||
@mock.patch(
|
||||
'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.stack_name = "foobar"
|
||||
orchestration_client.stacks.get.return_value = stack
|
||||
|
||||
self.cmd._plan_undeploy(clients, 'overcloud')
|
||||
|
||||
@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
|
||||
|
||||
stack = mock.Mock()
|
||||
stack.id = 12345
|
||||
stack.stack_name = "foobar"
|
||||
orchestration_client.stacks.get.return_value = stack
|
||||
|
||||
self.cmd._plan_undeploy(clients, 'overcloud')
|
@ -0,0 +1,64 @@
|
||||
# Copyright 2016 Red Hat, Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import mock
|
||||
from osc_lib import exceptions
|
||||
|
||||
from tripleoclient import constants
|
||||
from tripleoclient.tests import fakes
|
||||
from tripleoclient.tests.v1.overcloud_deploy import fakes as deploy_fakes
|
||||
from tripleoclient.v2 import overcloud_delete
|
||||
|
||||
|
||||
class TestDeleteOvercloud(deploy_fakes.TestDeployOvercloud):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeleteOvercloud, self).setUp()
|
||||
self.app = fakes.FakeApp()
|
||||
self.cmd = overcloud_delete.DeleteOvercloud(self.app, None)
|
||||
|
||||
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
|
||||
def test_plan_undeploy(self, mock_run_playbook):
|
||||
arglist = ["overcast", "-y"]
|
||||
verifylist = [
|
||||
("stack", "overcast"),
|
||||
("yes", True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_run_playbook.assert_called_once_with(
|
||||
'cli-overcloud-delete.yaml',
|
||||
'undercloud,',
|
||||
constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={
|
||||
"stack_name": "overcast",
|
||||
},
|
||||
verbosity=3,
|
||||
)
|
||||
|
||||
def test_no_confirmation(self):
|
||||
arglist = ["overcast", ]
|
||||
verifylist = [
|
||||
("stack", "overcast"),
|
||||
("yes", False),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action, parsed_args)
|
@ -20,9 +20,8 @@ from osc_lib.i18n import _
|
||||
from osc_lib import utils as osc_utils
|
||||
|
||||
from tripleoclient import command
|
||||
from tripleoclient import constants
|
||||
from tripleoclient import utils
|
||||
from tripleoclient.workflows import plan_management
|
||||
from tripleoclient.workflows import stack_management
|
||||
|
||||
|
||||
class DeleteOvercloud(command.Command):
|
||||
@ -44,37 +43,7 @@ class DeleteOvercloud(command.Command):
|
||||
|
||||
def _validate_args(self, parsed_args):
|
||||
if parsed_args.stack in (None, ''):
|
||||
raise oscexc.CommandError(
|
||||
"You must specify a stack name")
|
||||
|
||||
def _plan_undeploy(self, clients, stack_name):
|
||||
orchestration_client = clients.orchestration
|
||||
|
||||
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.plan_undeploy(
|
||||
clients,
|
||||
plan=stack.stack_name
|
||||
)
|
||||
except Exception as e:
|
||||
raise oscexc.CommandError(
|
||||
"Error occurred during stack delete {}".
|
||||
format(e))
|
||||
|
||||
def _plan_delete(self, clients, stack_name):
|
||||
print("Deleting plan {s}...".format(s=stack_name))
|
||||
try:
|
||||
plan_management.delete_deployment_plan(
|
||||
clients,
|
||||
container=stack_name)
|
||||
except Exception as err:
|
||||
raise oscexc.CommandError(
|
||||
"Error occurred while deleting plan {}".format(err))
|
||||
raise oscexc.CommandError("You must specify a stack name")
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action({args})".format(args=parsed_args))
|
||||
@ -89,8 +58,14 @@ class DeleteOvercloud(command.Command):
|
||||
if not confirm:
|
||||
raise oscexc.CommandError("Action not confirmed, exiting.")
|
||||
|
||||
clients = self.app.client_manager
|
||||
utils.run_ansible_playbook(
|
||||
"cli-overcloud-delete.yaml",
|
||||
'undercloud,',
|
||||
constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={
|
||||
"stack_name": parsed_args.stack
|
||||
},
|
||||
verbosity=3 if self.app.options.debug else 1
|
||||
)
|
||||
|
||||
self._plan_undeploy(clients, parsed_args.stack)
|
||||
self._plan_delete(clients, parsed_args.stack)
|
||||
print("Success.")
|
Loading…
x
Reference in New Issue
Block a user