Support remove and revert actions

The CLI should not only support creating snapshots, but it also
must support two other actions: remove and revert. Remove deletes
all the snapshots that were created in a previous execution,
while revert loads the information stored in the snapshots to the
main disks, leaving them in the same state they were when the
snapshots were created.

Change-Id: I75925c749acd26cbdf62991e7e0ec87d906d5def
This commit is contained in:
Juan Larriba
2022-07-14 15:01:04 +02:00
parent 80612ac58b
commit 9909d9b176
2 changed files with 112 additions and 4 deletions

View File

@@ -403,7 +403,89 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml',
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,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
@@ -425,7 +507,7 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory,
tags=None,
tags='create_snapshots',
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
@@ -458,7 +540,7 @@ class TestOvercloudSnapshot(utils.TestCommand):
workdir=mock.ANY,
playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory,
tags=None,
tags='create_snapshots',
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,

View File

@@ -293,6 +293,22 @@ class BackupSnapshot(command.Command):
"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(
'--extra-vars',
default=None,
@@ -339,11 +355,21 @@ class BackupSnapshot(command.Command):
_('The inventory file {} does not exist or is not '
'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._run_ansible_playbook(
playbook='cli-overcloud-snapshot.yaml',
inventory=parsed_args.inventory,
tags=None,
tags=tags,
skip_tags=None,
extra_vars=extra_vars
)