diff --git a/tripleoclient/tests/v1/undercloud/test_undercloud_backup.py b/tripleoclient/tests/v1/undercloud/test_undercloud_backup.py index c561decb3..d55b4dbd9 100644 --- a/tripleoclient/tests/v1/undercloud/test_undercloud_backup.py +++ b/tripleoclient/tests/v1/undercloud/test_undercloud_backup.py @@ -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'}) diff --git a/tripleoclient/v1/undercloud_backup.py b/tripleoclient/v1/undercloud_backup.py index 616f71521..810a8f532 100644 --- a/tripleoclient/v1/undercloud_backup.py +++ b/tripleoclient/v1/undercloud_backup.py @@ -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.