Merge "Add --db-only option in undercloud_backup."

This commit is contained in:
Zuul 2021-06-16 06:00:45 +00:00 committed by Gerrit Code Review
commit c1ef843790
2 changed files with 101 additions and 21 deletions

View File

@ -261,6 +261,35 @@ class TestUndercloudBackup(utils.TestCommand):
extra_vars=None
)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_undercloud_backup_db_only(self,
mock_playbook,
mock_access,
mock_isfile):
arglist = [
'--db-only'
]
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-undercloud-db-backup.yaml',
inventory=parsed_args.inventory,
tags=None,
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
extra_vars=None
)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
@ -322,6 +351,37 @@ class TestUndercloudBackup(utils.TestCommand):
extra_vars=extra_vars_dict
)
@mock.patch('os.path.isfile')
@mock.patch('os.access')
@mock.patch('tripleoclient.utils.run_ansible_playbook',
autospec=True)
def test_undercloud_backup_db_only_with_setup_options(self,
mock_playbook,
mock_access,
mock_isfile):
arglist = [
'--db-only',
'--setup-nfs',
'--setup-rear'
]
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-undercloud-db-backup.yaml',
inventory=parsed_args.inventory,
tags=None,
skip_tags=None,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=3,
extra_vars=None
)
@mock.patch('tripleoclient.utils.run_ansible_playbook', autospec=True)
def test_undercloud_backup_setup_nfs_rear_with_inventory(self,
mock_playbook):

View File

@ -73,6 +73,15 @@ class BackupUndercloud(command.Command):
"install and configure ReaR.")
)
parser.add_argument(
'--db-only',
default=False,
action='store_true',
help=_("Perform a DB backup of the 'Undercloud' host. "
"The DB backup file will be stored in /home/stack "
"with the name openstack-backup-mysql-<timestamp>.sql.")
)
parser.add_argument(
'--inventory',
action='store',
@ -161,6 +170,17 @@ class BackupUndercloud(command.Command):
_('The inventory file {} does not exist or is not '
'readable'.format(parsed_args.inventory)))
if parsed_args.db_only is True:
self._run_ansible_playbook(
playbook='cli-undercloud-db-backup.yaml',
inventory=parsed_args.inventory,
tags=None,
skip_tags=None,
extra_vars=extra_vars
)
else:
if parsed_args.setup_nfs is True or parsed_args.init == 'nfs':
self._run_ansible_playbook(