Merge "Support remove and revert actions"

This commit is contained in:
Zuul 2022-08-13 19:16:44 +00:00 committed by Gerrit Code Review
commit cfbd209d01
2 changed files with 112 additions and 4 deletions

View File

@ -403,7 +403,89 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY, workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml', playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory, inventory=parsed_args.inventory,
tags=None, tags='create_snapshots',
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
extra_vars={}
)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_overcloud_snapshot_revert_remove(self,
mock_playbook,
mock_access,
mock_isfile):
arglist = [
'--remove',
'--revert',
]
verifylist = []
mock_isfile.return_value = True
mock_access.return_value = True
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaisesRegex(
RuntimeError,
'--revert and --remove are mutually exclusive',
self.cmd.take_action,
parsed_args)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_overcloud_snapshot_revert(self,
mock_playbook,
mock_access,
mock_isfile):
arglist = [
'--revert',
]
verifylist = []
mock_isfile.return_value = True
mock_access.return_value = True
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_playbook.assert_called_once_with(
workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory,
tags='revert_snapshots',
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
extra_vars={}
)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_overcloud_snapshot_remove(self,
mock_playbook,
mock_access,
mock_isfile):
arglist = [
'--remove',
]
verifylist = []
mock_isfile.return_value = True
mock_access.return_value = True
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_playbook.assert_called_once_with(
workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory,
tags='remove_snapshots',
skip_tags=None, skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3, verbosity=3,
@ -425,7 +507,7 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY, workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml', playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory, inventory=parsed_args.inventory,
tags=None, tags='create_snapshots',
skip_tags=None, skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3, verbosity=3,
@ -458,7 +540,7 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY, workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml', playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory, inventory=parsed_args.inventory,
tags=None, tags='create_snapshots',
skip_tags=None, skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3, verbosity=3,

View File

@ -293,6 +293,22 @@ class BackupSnapshot(command.Command):
"Defaults to: " + INVENTORY) "Defaults to: " + INVENTORY)
) )
parser.add_argument(
'--remove',
default=False,
action='store_true',
help=_("Removes all the snapshot volumes "
"that were created.")
)
parser.add_argument(
'--revert',
default=False,
action='store_true',
help=_("Reverts all the disks to the moment "
"when the snapshot was created.")
)
parser.add_argument( parser.add_argument(
'--extra-vars', '--extra-vars',
default=None, default=None,
@ -339,11 +355,21 @@ class BackupSnapshot(command.Command):
_('The inventory file {} does not exist or is not ' _('The inventory file {} does not exist or is not '
'readable'.format(parsed_args.inventory))) 'readable'.format(parsed_args.inventory)))
if parsed_args.remove is True and parsed_args.revert is True:
raise RuntimeError(
_('--revert and --remove are mutually exclusive'))
if parsed_args.remove is True and parsed_args.revert is False:
tags = 'remove_snapshots'
if parsed_args.revert is True and parsed_args.remove is False:
tags = 'revert_snapshots'
if parsed_args.remove is False and parsed_args.revert is False:
tags = 'create_snapshots'
self.log.debug(_('Starting Overcloud Snapshot')) self.log.debug(_('Starting Overcloud Snapshot'))
self._run_ansible_playbook( self._run_ansible_playbook(
playbook='cli-overcloud-snapshot.yaml', playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory, inventory=parsed_args.inventory,
tags=None, tags=tags,
skip_tags=None, skip_tags=None,
extra_vars=extra_vars extra_vars=extra_vars
) )