mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #46515 from gtmanfred/develop
allow excluding multiple directories in rsync
This commit is contained in:
commit
fa9c3c0e7c
@ -56,7 +56,11 @@ def _check(delete, force, update, passwordfile, exclude, excludefrom, dryrun, rs
|
|||||||
if exclude:
|
if exclude:
|
||||||
exclude = False
|
exclude = False
|
||||||
if exclude:
|
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:
|
if dryrun:
|
||||||
options.append('--dry-run')
|
options.append('--dry-run')
|
||||||
return options
|
return options
|
||||||
@ -133,10 +137,9 @@ def rsync(src,
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
salt '*' rsync.rsync {src} {dst} {delete=True} {update=True} {passwordfile=/etc/pass.crt} {exclude=xx} {rsh}
|
salt '*' rsync.rsync /path/to/src /path/to/dest delete=True update=True passwordfile=/etc/pass.crt exclude=exclude/dir
|
||||||
salt '*' rsync.rsync {src} {dst} {delete=True} {excludefrom=/xx.ini} {rsh}
|
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"]'
|
||||||
salt '*' rsync.rsync {src} {dst} {delete=True} {excludefrom=/xx.ini} additional_opts='["--partial", "--bwlimit=5000"]'
|
|
||||||
'''
|
'''
|
||||||
if not src:
|
if not src:
|
||||||
src = __salt__['config.option']('rsync.src')
|
src = __salt__['config.option']('rsync.src')
|
||||||
|
@ -53,3 +53,33 @@ class RsyncTestCase(TestCase, LoaderModuleMockMixin):
|
|||||||
self.assertRaises(CommandExecutionError, rsync.version)
|
self.assertRaises(CommandExecutionError, rsync.version)
|
||||||
|
|
||||||
self.assertEqual(rsync.version(), 'C')
|
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,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user