Add exclude-path to undercloud backups
This patch adds the option to exclude files when executing an Undercloud backup Change-Id: If8902980c93212401e5ff30828f6f03da6eece0e Closes-Bug: 1767385
This commit is contained in:
parent
c79dabc47b
commit
1a05c694b8
|
@ -58,3 +58,65 @@ class TestUndercloudBackup(utils.TestCommand):
|
|||
plan_mock.assert_called_once_with(
|
||||
mock.ANY,
|
||||
{'sources_path': '/home/stack/,/tmp/bar.yaml,/tmp/foo.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove(self, plan_mock):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
'--exclude-path',
|
||||
'/tmp/bar.yaml',
|
||||
'--exclude-path',
|
||||
'/home/stack/',
|
||||
'--add-path',
|
||||
'/tmp/bar.yaml'
|
||||
]
|
||||
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': '/tmp/foo.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove_double(self, plan_mock):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
'--add-path',
|
||||
'/tmp/bar.yaml',
|
||||
'--exclude-path',
|
||||
'/tmp/foo.yaml',
|
||||
'--exclude-path',
|
||||
'/tmp/foo.yaml'
|
||||
]
|
||||
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/,/tmp/bar.yaml'})
|
||||
|
||||
@mock.patch('tripleoclient.workflows.undercloud_backup.backup',
|
||||
autospec=True)
|
||||
def test_undercloud_backup_withargs_remove_unex(self, plan_mock):
|
||||
arglist = [
|
||||
'--add-path',
|
||||
'/tmp/foo.yaml',
|
||||
'--exclude-path',
|
||||
'/tmp/non-existing-path.yaml'
|
||||
]
|
||||
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/,/tmp/foo.yaml'})
|
||||
|
|
|
@ -43,13 +43,28 @@ class BackupUndercloud(command.Command):
|
|||
"i.e. --add-path /this/is/a/folder/ "
|
||||
" --add-path /this/is/a/texfile.txt")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--exclude-path",
|
||||
default=[],
|
||||
action="append",
|
||||
help=_("Exclude path when performing the Undercloud Backup, "
|
||||
"this option can be specified multiple times. "
|
||||
"Defaults to: none "
|
||||
"i.e. --exclude-path /this/is/a/folder/ "
|
||||
" --exclude-path /this/is/a/texfile.txt")
|
||||
)
|
||||
return parser
|
||||
|
||||
def _run_backup_undercloud(self, parsed_args):
|
||||
|
||||
clients = self.app.client_manager
|
||||
|
||||
files_to_backup = ','.join(sorted(list(set(parsed_args.add_path))))
|
||||
merge_paths = sorted(list(set(parsed_args.add_path)))
|
||||
for exc in parsed_args.exclude_path:
|
||||
if exc in merge_paths:
|
||||
merge_paths.remove(exc)
|
||||
|
||||
files_to_backup = ','.join(merge_paths)
|
||||
|
||||
# Define the backup sources_path (files to backup).
|
||||
# This is a comma separated string.
|
||||
|
|
Loading…
Reference in New Issue