diff --git a/releasenotes/notes/add-node-unprovision-overcloud-delete-c7dd063912d4ebca.yaml b/releasenotes/notes/add-node-unprovision-overcloud-delete-c7dd063912d4ebca.yaml new file mode 100644 index 000000000..fe6c1bff2 --- /dev/null +++ b/releasenotes/notes/add-node-unprovision-overcloud-delete-c7dd063912d4ebca.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added options for "overcloud delete" command to unprovision nodes + and network ports provisioned with "overcloud deploy". diff --git a/tripleoclient/tests/v2/overcloud_delete/test_overcloud_delete.py b/tripleoclient/tests/v2/overcloud_delete/test_overcloud_delete.py index af52fe42c..5fc8e6c14 100644 --- a/tripleoclient/tests/v2/overcloud_delete/test_overcloud_delete.py +++ b/tripleoclient/tests/v2/overcloud_delete/test_overcloud_delete.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. # +import tempfile import mock from osc_lib import exceptions @@ -32,7 +33,7 @@ class TestDeleteOvercloud(deploy_fakes.TestDeployOvercloud): @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) @mock.patch('os.chdir', autospec=True) @mock.patch('tempfile.mkdtemp', autospec=True) - def test_plan_undeploy(self, mock_mkdir, mock_cd, mock_run_playbook): + def test_overcloud_delete(self, mock_mkdir, mock_cd, mock_run_playbook): arglist = ["overcast", "-y"] verifylist = [ ("stack", "overcast"), @@ -54,6 +55,43 @@ class TestDeleteOvercloud(deploy_fakes.TestDeployOvercloud): verbosity=3, ) + @mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True) + @mock.patch('os.chdir', autospec=True) + @mock.patch('tempfile.mkdtemp', autospec=True) + def test_overcloud_delete_unprovision(self, mock_mkdir, + mock_cd, mock_run_playbook): + arglist = ["overcast", "-y", + '--network-ports'] + verifylist = [ + ("stack", "overcast"), + ("yes", True), + ("network_ports", True) + ] + + with tempfile.NamedTemporaryFile() as inp: + inp.write(b'- name: Compute\n- name: Controller\n') + inp.flush() + arglist.extend(['-b', inp.name]) + verifylist.append(('baremetal_deployment', inp.name)) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + + mock_run_playbook.assert_called_with( + 'cli-overcloud-node-unprovision.yaml', + 'localhost,', + mock.ANY, + constants.ANSIBLE_TRIPLEO_PLAYBOOKS, + extra_vars={ + "stack_name": "overcast", + "baremetal_deployment": mock.ANY, + "all": True, + "prompt": False, + "manage_network_ports": True, + }, + verbosity=3, + ) + self.assertEqual(mock_run_playbook.call_count, 2) + def test_no_confirmation(self): arglist = ["overcast", ] verifylist = [ diff --git a/tripleoclient/v2/overcloud_delete.py b/tripleoclient/v2/overcloud_delete.py index 21d41f942..ac5f57845 100644 --- a/tripleoclient/v2/overcloud_delete.py +++ b/tripleoclient/v2/overcloud_delete.py @@ -14,6 +14,7 @@ # import logging +import yaml from osc_lib import exceptions as oscexc from osc_lib.i18n import _ @@ -51,6 +52,14 @@ class DeleteOvercloud(command.Command): 'manually cleanup FreeIPA later.'), default=False, action="store_true") + parser.add_argument('-b', '--baremetal-deployment', + metavar='', + help=_('Configuration file describing the ' + 'baremetal deployment')) + parser.add_argument('--network-ports', + help=_('Enable unprovisioning of network ports'), + default=False, + action="store_true") return parser def _validate_args(self, parsed_args): @@ -89,4 +98,23 @@ class DeleteOvercloud(command.Command): } ) + if parsed_args.baremetal_deployment: + with open(parsed_args.baremetal_deployment, 'r') as fp: + roles = yaml.safe_load(fp) + + with utils.TempDirs() as tmp: + utils.run_ansible_playbook( + playbook='cli-overcloud-node-unprovision.yaml', + workdir=tmp, + inventory='localhost,', + playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, + verbosity=utils.playbook_verbosity(self=self), + extra_vars={ + "stack_name": parsed_args.stack, + "baremetal_deployment": roles, + "all": True, + "prompt": False, + "manage_network_ports": parsed_args.network_ports, + } + ) print("Success.")