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): ...@@ -74,20 +74,15 @@ def rsync(rsync_binary, source, destination, extra_args=None, dry=False):
print('DEBUG:', arg_list) print('DEBUG:', arg_list)
return return
rsync_process = subprocess.call(arg_list) try:
print(rsync_process.stdout.read()) subprocess.check_call(arg_list)
except subprocess.CalledProcessError as e:
# All rsync errors are not to be considered as errors # All rsync errors are not to be considered as errors
allowed_error_message_regex = \ allowed_error_message_regex = \
'^(file has vanished: |rsync warning: some files vanished before they could be transferred)' '^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
rsync_process_stderr = rsync_process.stderr.read() if e.returncode not in (0, 24) or \
re.match(allowed_error_message_regex, e.output) is not None:
if rsync_process.returncode in (0, 24) or \ raise e
re.match(allowed_error_message_regex, rsync_process_stderr):
return
print(rsync_process_stderr)
raise RuntimeError("An issue occured when running rsync.")
def getExcludePathList(path): def getExcludePathList(path):
......
...@@ -48,12 +48,6 @@ class Config(): ...@@ -48,12 +48,6 @@ class Config():
pass pass
class SubprocessCallReturnObject:
returncode = 0
stderr = StringIO('')
stdout = StringIO('')
class TestRunnerExporter(unittest.TestCase): class TestRunnerExporter(unittest.TestCase):
def setUp(self): def setUp(self):
if not os.path.exists('test_folder'): if not os.path.exists('test_folder'):
...@@ -132,9 +126,8 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -132,9 +126,8 @@ class TestRunnerExporter(unittest.TestCase):
) )
@mock.patch('subprocess.call') @mock.patch('subprocess.check_call')
def test_synchroniseRunnerConfigurationDirectory(self, call_mock): def test_synchroniseRunnerConfigurationDirectory(self, check_call_mock):
call_mock.return_value = SubprocessCallReturnObject()
self._setUpFakeInstanceFolder() self._setUpFakeInstanceFolder()
config = Config() config = Config()
config.rsync_binary = 'rsync' config.rsync_binary = 'rsync'
...@@ -143,21 +136,20 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -143,21 +136,20 @@ class TestRunnerExporter(unittest.TestCase):
runner_exporter.synchroniseRunnerConfigurationDirectory( runner_exporter.synchroniseRunnerConfigurationDirectory(
config, 'backup/runner/etc/' config, 'backup/runner/etc/'
) )
self.assertEqual(call_mock.call_count, 3) self.assertEqual(check_call_mock.call_count, 3)
call_mock.assert_any_call( check_call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'config.json', 'backup/runner/etc/'] ['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/'] ['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/'] ['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
) )
@mock.patch('subprocess.call') @mock.patch('subprocess.check_call')
def test_synchroniseRunnerWorkingDirectory(self, call_mock): def test_synchroniseRunnerWorkingDirectory(self, check_call_mock):
call_mock.return_value = SubprocessCallReturnObject()
self._setUpFakeInstanceFolder() self._setUpFakeInstanceFolder()
config = Config() config = Config()
config.rsync_binary = 'rsync' config.rsync_binary = 'rsync'
...@@ -167,10 +159,10 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -167,10 +159,10 @@ class TestRunnerExporter(unittest.TestCase):
config, 'backup/runner/runner' 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'] ['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'] ['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