Merge "Move undercloud backup from mistral to ansible"
This commit is contained in:
commit
cdaae4c783
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Adds a new --save-swift parameter to undercloud-backup. This is due to the
|
||||
fact that in the past the backup would be always saved on swift and the
|
||||
next backup would contain the previous backup thus increasing exponentially
|
||||
The default is false and that saves to the filesytem
|
|
@ -117,7 +117,7 @@ openstack.tripleoclient.v2 =
|
|||
undercloud_upgrade = tripleoclient.v1.undercloud:UpgradeUndercloud
|
||||
undercloud_minion_install = tripleoclient.v1.undercloud_minion:InstallUndercloudMinion
|
||||
undercloud_minion_upgrade = tripleoclient.v1.undercloud_minion:UpgradeUndercloudMinion
|
||||
undercloud_backup = tripleoclient.v1.undercloud_backup:BackupUndercloud
|
||||
undercloud_backup = tripleoclient.v2.undercloud_backup:BackupUndercloud
|
||||
tripleo_validator_group_info = tripleoclient.v1.tripleo_validator:TripleOValidatorGroupInfo
|
||||
tripleo_validator_list = tripleoclient.v1.tripleo_validator:TripleOValidatorList
|
||||
tripleo_validator_run = tripleoclient.v1.tripleo_validator:TripleOValidatorRun
|
||||
|
|
|
@ -81,6 +81,8 @@ DEFAULT_VALIDATIONS_BASEDIR = '/usr/share/openstack-tripleo-validations'
|
|||
|
||||
ANSIBLE_VALIDATION_DIR = \
|
||||
'/usr/share/openstack-tripleo-validations/playbooks'
|
||||
ANSIBLE_TRIPLEO_PLAYBOOKS = \
|
||||
'/usr/share/ansible/tripleo-playbooks'
|
||||
|
||||
VALIDATION_GROUPS_INFO = '%s/groups.yaml' % DEFAULT_VALIDATIONS_BASEDIR
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
import mock
|
||||
|
||||
from osc_lib.tests import utils
|
||||
from tripleoclient.v1 import undercloud_backup
|
||||
|
||||
from tripleoclient import constants
|
||||
from tripleoclient.v2 import undercloud_backup
|
||||
|
||||
|
||||
class TestUndercloudBackup(utils.TestCommand):
|
||||
|
@ -29,21 +31,28 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
self.app.client_manager.workflow_engine = mock.Mock()
|
||||
self.workflow = self.app.client_manager.workflow_engine
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_noargs(self, plan_mock):
|
||||
def test_undercloud_backup_noargs(self, mock_playbook):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
plan_mock.assert_called_once_with(
|
||||
mock.ANY, {'sources_path': '/home/stack/'})
|
||||
mock_playbook.assert_called_once_with(
|
||||
workdir=mock.ANY,
|
||||
playbook='cli-undercloud-backup.yaml',
|
||||
inventory='localhost,',
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={
|
||||
'sources_path': '/home/stack/'
|
||||
}
|
||||
)
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs(self, plan_mock):
|
||||
def test_undercloud_backup_withargs(self, mock_playbook):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
|
@ -55,13 +64,17 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
plan_mock.assert_called_once_with(
|
||||
mock.ANY,
|
||||
{'sources_path': '/home/stack/,/tmp/bar.yaml,/tmp/foo.yaml'})
|
||||
mock_playbook.assert_called_once_with(
|
||||
workdir=mock.ANY,
|
||||
playbook=mock.ANY,
|
||||
inventory=mock.ANY,
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={'sources_path':
|
||||
'/home/stack/,/tmp/bar.yaml,/tmp/foo.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove(self, plan_mock):
|
||||
def test_undercloud_backup_withargs_remove(self, mock_playbook):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
|
@ -77,13 +90,17 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
plan_mock.assert_called_once_with(
|
||||
mock.ANY,
|
||||
{'sources_path': '/tmp/foo.yaml'})
|
||||
mock_playbook.assert_called_once_with(
|
||||
workdir=mock.ANY,
|
||||
playbook=mock.ANY,
|
||||
inventory=mock.ANY,
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={'sources_path':
|
||||
'/tmp/foo.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove_double(self, plan_mock):
|
||||
def test_undercloud_backup_withargs_remove_double(self, mock_playbook):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
|
@ -99,13 +116,17 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
plan_mock.assert_called_once_with(
|
||||
mock.ANY,
|
||||
{'sources_path': '/home/stack/,/tmp/bar.yaml'})
|
||||
mock_playbook.assert_called_once_with(
|
||||
workdir=mock.ANY,
|
||||
playbook=mock.ANY,
|
||||
inventory=mock.ANY,
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={'sources_path':
|
||||
'/home/stack/,/tmp/bar.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove_unex(self, plan_mock):
|
||||
def test_undercloud_backup_withargs_remove_unex(self, mock_playbook):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
|
@ -117,6 +138,10 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
plan_mock.assert_called_once_with(
|
||||
mock.ANY,
|
||||
{'sources_path': '/home/stack/,/tmp/foo.yaml'})
|
||||
mock_playbook.assert_called_once_with(
|
||||
workdir=mock.ANY,
|
||||
playbook=mock.ANY,
|
||||
inventory=mock.ANY,
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars={'sources_path':
|
||||
'/home/stack/,/tmp/foo.yaml'})
|
|
@ -18,7 +18,9 @@ import logging
|
|||
|
||||
from osc_lib.command import command
|
||||
from osc_lib.i18n import _
|
||||
from tripleoclient.workflows import undercloud_backup
|
||||
|
||||
from tripleoclient import constants
|
||||
from tripleoclient import utils
|
||||
|
||||
LOG = logging.getLogger(__name__ + ".BackupUndercloud")
|
||||
|
||||
|
@ -53,12 +55,20 @@ class BackupUndercloud(command.Command):
|
|||
"i.e. --exclude-path /this/is/a/folder/ "
|
||||
" --exclude-path /this/is/a/texfile.txt")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--save-swift',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help=_("Save backup to swift. "
|
||||
"Defaults to: False "
|
||||
"Special attention should be taken that "
|
||||
"Swift itself is backed up if you call this multiple times "
|
||||
"the backup size will grow exponentially")
|
||||
)
|
||||
return parser
|
||||
|
||||
def _run_backup_undercloud(self, parsed_args):
|
||||
|
||||
clients = self.app.client_manager
|
||||
|
||||
merge_paths = sorted(list(set(parsed_args.add_path)))
|
||||
for exc in parsed_args.exclude_path:
|
||||
if exc in merge_paths:
|
||||
|
@ -69,22 +79,24 @@ class BackupUndercloud(command.Command):
|
|||
# Define the backup sources_path (files to backup).
|
||||
# This is a comma separated string.
|
||||
# I.e. "/this/is/a/folder/,/this/is/a/texfile.txt"
|
||||
workflow_input = {
|
||||
"sources_path": files_to_backup
|
||||
}
|
||||
extra_vars = {"sources_path": files_to_backup}
|
||||
if parsed_args.save_swift:
|
||||
extra_vars.update({"save_swift": True})
|
||||
|
||||
LOG.debug(_('Launch the Undercloud Backup'))
|
||||
try:
|
||||
output = undercloud_backup.backup(clients, workflow_input)
|
||||
LOG.info(output)
|
||||
except Exception as e:
|
||||
print(_("Undercloud backup finished with errors"))
|
||||
print('Output: {}'.format(e))
|
||||
LOG.info(e)
|
||||
with utils.TempDirs() as tmp:
|
||||
utils.run_ansible_playbook(
|
||||
playbook='cli-undercloud-backup.yaml',
|
||||
inventory='localhost,',
|
||||
workdir=tmp,
|
||||
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||
extra_vars=extra_vars
|
||||
)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
LOG.info(_(
|
||||
self._run_backup_undercloud(parsed_args)
|
||||
print(
|
||||
'\n'
|
||||
' #############################################################\n'
|
||||
' # Disclaimer #\n'
|
||||
|
@ -94,7 +106,5 @@ class BackupUndercloud(command.Command):
|
|||
' # backup file path will be shown on a successful execution. #\n'
|
||||
' # #\n'
|
||||
' # .-Stay safe and avoid future issues-. #\n'
|
||||
' #############################################################\n')
|
||||
' #############################################################\n'
|
||||
)
|
||||
|
||||
self._run_backup_undercloud(parsed_args)
|
Loading…
Reference in New Issue