Merge pull request #46515 from gtmanfred/develop

allow excluding multiple directories in rsync
This commit is contained in:
Nicole Thomas 2018-04-10 14:34:02 -04:00 committed by GitHub
commit fa9c3c0e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -56,7 +56,11 @@ def _check(delete, force, update, passwordfile, exclude, excludefrom, dryrun, rs
if exclude:
exclude = False
if exclude:
options.extend(['--exclude', exclude])
if isinstance(exclude, list):
for ex_ in exclude:
options.extend(['--exclude', ex_])
else:
options.extend(['--exclude', exclude])
if dryrun:
options.append('--dry-run')
return options
@ -133,10 +137,9 @@ def rsync(src,
.. code-block:: bash
salt '*' rsync.rsync {src} {dst} {delete=True} {update=True} {passwordfile=/etc/pass.crt} {exclude=xx} {rsh}
salt '*' rsync.rsync {src} {dst} {delete=True} {excludefrom=/xx.ini} {rsh}
salt '*' rsync.rsync {src} {dst} {delete=True} {excludefrom=/xx.ini} additional_opts='["--partial", "--bwlimit=5000"]'
salt '*' rsync.rsync /path/to/src /path/to/dest delete=True update=True passwordfile=/etc/pass.crt exclude=exclude/dir
salt '*' rsync.rsync /path/to/src delete=True excludefrom=/xx.ini
salt '*' rsync.rsync /path/to/src delete=True exclude='[exclude1/dir,exclude2/dir]' additional_opts='["--partial", "--bwlimit=5000"]'
'''
if not src:
src = __salt__['config.option']('rsync.src')

View File

@ -53,3 +53,33 @@ class RsyncTestCase(TestCase, LoaderModuleMockMixin):
self.assertRaises(CommandExecutionError, rsync.version)
self.assertEqual(rsync.version(), 'C')
def test_rsync_excludes_list(self):
'''
Test for rsync files from src to dst with a list of excludes
'''
mock = {
'config.option': MagicMock(return_value=False),
'cmd.run_all': MagicMock()
}
with patch.dict(rsync.__salt__, mock):
rsync.rsync('src', 'dst', exclude=['test/one', 'test/two'])
mock['cmd.run_all'].assert_called_once_with(
['rsync', '-avz', '--exclude', 'test/one', '--exclude', 'test/two', 'src', 'dst'],
python_shell=False,
)
def test_rsync_excludes_str(self):
'''
Test for rsync files from src to dst with one exclude
'''
mock = {
'config.option': MagicMock(return_value=False),
'cmd.run_all': MagicMock()
}
with patch.dict(rsync.__salt__, mock):
rsync.rsync('src', 'dst', exclude='test/one')
mock['cmd.run_all'].assert_called_once_with(
['rsync', '-avz', '--exclude', 'test/one', 'src', 'dst'],
python_shell=False,
)