Commit e176156e authored by Nicolas Wavrant's avatar Nicolas Wavrant

fixup

parent b6f34bfd
......@@ -74,20 +74,15 @@ def rsync(rsync_binary, source, destination, extra_args=None, dry=False):
print('DEBUG:', arg_list)
return
rsync_process = subprocess.call(arg_list)
print(rsync_process.stdout.read())
# All rsync errors are not to be considered as errors
allowed_error_message_regex = \
'^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
rsync_process_stderr = rsync_process.stderr.read()
if rsync_process.returncode in (0, 24) or \
re.match(allowed_error_message_regex, rsync_process_stderr):
return
print(rsync_process_stderr)
raise RuntimeError("An issue occured when running rsync.")
try:
subprocess.check_call(arg_list)
except subprocess.CalledProcessError as e:
# All rsync errors are not to be considered as errors
allowed_error_message_regex = \
'^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
if e.returncode not in (0, 24) or \
re.match(allowed_error_message_regex, e.output) is not None:
raise e
def getExcludePathList(path):
......
......@@ -48,12 +48,6 @@ class Config():
pass
class SubprocessCallReturnObject:
returncode = 0
stderr = StringIO('')
stdout = StringIO('')
class TestRunnerExporter(unittest.TestCase):
def setUp(self):
if not os.path.exists('test_folder'):
......@@ -132,9 +126,8 @@ class TestRunnerExporter(unittest.TestCase):
)
@mock.patch('subprocess.call')
def test_synchroniseRunnerConfigurationDirectory(self, call_mock):
call_mock.return_value = SubprocessCallReturnObject()
@mock.patch('subprocess.check_call')
def test_synchroniseRunnerConfigurationDirectory(self, check_call_mock):
self._setUpFakeInstanceFolder()
config = Config()
config.rsync_binary = 'rsync'
......@@ -143,21 +136,20 @@ class TestRunnerExporter(unittest.TestCase):
runner_exporter.synchroniseRunnerConfigurationDirectory(
config, 'backup/runner/etc/'
)
self.assertEqual(call_mock.call_count, 3)
call_mock.assert_any_call(
self.assertEqual(check_call_mock.call_count, 3)
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'config.json', 'backup/runner/etc/']
)
call_mock.assert_any_call(
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
)
call_mock.assert_any_call(
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
)
@mock.patch('subprocess.call')
def test_synchroniseRunnerWorkingDirectory(self, call_mock):
call_mock.return_value = SubprocessCallReturnObject()
@mock.patch('subprocess.check_call')
def test_synchroniseRunnerWorkingDirectory(self, check_call_mock):
self._setUpFakeInstanceFolder()
config = Config()
config.rsync_binary = 'rsync'
......@@ -167,10 +159,10 @@ class TestRunnerExporter(unittest.TestCase):
config, 'backup/runner/runner'
)
call_mock.assert_any_call(
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '--exclude=*.sock', '--exclude=*.socket', '--exclude=*.pid', '--exclude=.installed*.cfg', '--exclude=srv/backup/**', '--exclude=instance/slappart0/etc/nicolas.txt', '--exclude=instance/slappart0/etc/rafael.txt', '--exclude=srv/exporter.exclude', 'instance', 'backup/runner/runner']
)
call_mock.assert_any_call(
check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'proxy.db', 'backup/runner/runner']
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment