Merge "Unprovision composable networks command"

This commit is contained in:
Zuul 2021-07-01 03:47:25 +00:00 committed by Gerrit Code Review
commit 6bd803168e
3 changed files with 90 additions and 0 deletions

View File

@ -59,6 +59,7 @@ openstack.tripleoclient.v2 =
overcloud_network_provision = tripleoclient.v2.overcloud_network:OvercloudNetworkProvision
overcloud_network_vip_extract = tripleoclient.v2.overcloud_network:OvercloudVirtualIPsExtract
overcloud_network_vip_provision = tripleoclient.v2.overcloud_network:OvercloudVirtualIPsProvision
overcloud_network_unprovision = tripleoclient.v2.overcloud_network:OvercloudNetworkUnprovision
overcloud_node_configure = tripleoclient.v1.overcloud_node:ConfigureNode
overcloud_node_delete = tripleoclient.v1.overcloud_node:DeleteNode
overcloud_node_import = tripleoclient.v2.overcloud_node:ImportNode

View File

@ -119,3 +119,41 @@ class TestOvercloudNetworkProvision(fakes.FakePlaybookExecution):
self.assertRaises(osc_lib_exc.CommandError,
self.cmd.take_action, parsed_args)
class TestOvercloudNetworkUnprovision(fakes.FakePlaybookExecution):
def setUp(self):
super(TestOvercloudNetworkUnprovision, self).setUp()
# Get the command object to test
app_args = mock.Mock()
app_args.verbose_level = 1
self.app.options = fakes.FakeOptions()
self.cmd = overcloud_network.OvercloudNetworkUnprovision(self.app,
None)
self.cmd.app_args = mock.Mock(verbose_level=1)
@mock.patch('tripleoclient.utils.TempDirs', autospect=True)
@mock.patch('os.path.abspath', autospect=True)
@mock.patch('os.path.exists', autospect=True)
@mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True)
def test_overcloud_network_unprovision(self, mock_playbook,
mock_path_exists,
mock_abspath, mock_tempdirs):
arglist = ['--yes', 'network_data_v2.yaml']
parsed_args = self.check_parser(self.cmd, arglist, [])
mock_abspath.side_effect = ['/test/network_data_v2.yaml']
mock_path_exists.side_effect = [True]
self.cmd.take_action(parsed_args)
mock_playbook.assert_called_once_with(
workdir=mock.ANY,
playbook='cli-overcloud-network-unprovision.yaml',
inventory=mock.ANY,
playbook_dir=mock.ANY,
verbosity=3,
extra_vars={
"network_data_path": '/test/network_data_v2.yaml'
}
)

View File

@ -254,3 +254,54 @@ class OvercloudVirtualIPsProvision(command.Command):
verbosity=oooutils.playbook_verbosity(self=self),
extra_vars=extra_vars,
)
class OvercloudNetworkUnprovision(command.Command):
log = logging.getLogger(__name__ + ".OvercloudNetworkUnprovision")
def get_parser(self, prog_name):
parser = super(OvercloudNetworkUnprovision, self).get_parser(prog_name)
parser.add_argument('networks_file',
metavar='<network_data.yaml>',
help=_('Configuration file describing the network '
'deployment.'))
parser.add_argument('-y', '--yes',
help=_('Skip yes/no prompt (assume yes).'),
default=False,
action="store_true")
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
networks_file_path = os.path.abspath(parsed_args.networks_file)
if not parsed_args.yes:
confirm = oooutils.prompt_user_for_confirmation(
message=_("Are you sure you want to unprovision the networks "
"mentioned in file %s [y/N]? " % networks_file_path),
logger=self.log)
if not confirm:
raise oscexc.CommandError("Action not confirmed, exiting.")
if not os.path.exists(networks_file_path):
raise oscexc.CommandError(
"Network configuration file does not exist:"
" %s" % parsed_args.networks_file)
extra_vars = {
"network_data_path": networks_file_path,
}
with oooutils.TempDirs() as tmp:
oooutils.run_ansible_playbook(
playbook='cli-overcloud-network-unprovision.yaml',
inventory='localhost,',
workdir=tmp,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=oooutils.playbook_verbosity(self=self),
extra_vars=extra_vars,
)