Add node, port unprovision to overcloud delete

This adds ``--baremetal-deployment`` and ``--network-ports``
options to ``overcloud delete`` command, so that nodes and
ports would be unprovisioned when deleting overcloud.

Change-Id: Ic799a71601294c822080151a38aa636370503c66
(cherry picked from commit 352211d88c)
This commit is contained in:
ramishra 2021-05-17 08:09:49 +05:30 committed by Sandeep Yadav
parent 7de125711d
commit ea451c4dec
3 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
Added options for "overcloud delete" command to unprovision nodes
and network ports provisioned with "overcloud deploy".

View File

@ -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 = [

View File

@ -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='<baremetal_deployment.yaml>',
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.")