Commit b6f34bfd authored by Nicolas Wavrant's avatar Nicolas Wavrant

check output of rsync

parent 4f3391d2
......@@ -4,6 +4,7 @@ import argparse
import errno
import glob
import os
import re
import shutil
import subprocess
import sys
......@@ -68,14 +69,25 @@ def rsync(rsync_binary, source, destination, extra_args=None, dry=False):
arg_list.extend(extra_args)
arg_list.append(source)
arg_list.append(destination)
if dry:
print('DEBUG:', arg_list)
else:
rsync_process = subprocess.check_call(arg_list)
# TODO : pipe stdout dans : (egrep -v "$IGNOREOUT" || true) || [ $? = "$IGNOREEXIT" ]
# with :
# IGNOREEXIT=24
# IGNOREOUT='^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
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.")
def getExcludePathList(path):
......
......@@ -6,6 +6,7 @@ import unittest
from datetime import datetime, timedelta
from slapos.resilient import runner_exporter
from StringIO import StringIO
tested_instance_cfg = """[buildout]
installed_develop_eggs =
......@@ -46,6 +47,13 @@ template = inline:
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'):
......@@ -124,8 +132,9 @@ class TestRunnerExporter(unittest.TestCase):
)
@mock.patch('subprocess.check_call')
def test_synchroniseRunnerConfigurationDirectory(self, check_call_mock):
@mock.patch('subprocess.call')
def test_synchroniseRunnerConfigurationDirectory(self, call_mock):
call_mock.return_value = SubprocessCallReturnObject()
self._setUpFakeInstanceFolder()
config = Config()
config.rsync_binary = 'rsync'
......@@ -134,20 +143,21 @@ class TestRunnerExporter(unittest.TestCase):
runner_exporter.synchroniseRunnerConfigurationDirectory(
config, 'backup/runner/etc/'
)
self.assertEqual(check_call_mock.call_count, 3)
check_call_mock.assert_any_call(
self.assertEqual(call_mock.call_count, 3)
call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', 'config.json', 'backup/runner/etc/']
)
check_call_mock.assert_any_call(
call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
)
check_call_mock.assert_any_call(
call_mock.assert_any_call(
['rsync', '-rlptgov', '--stats', '--safe-links', '--ignore-missing-args', '--delete', '--delete-excluded', '.project', 'backup/runner/etc/']
)
@mock.patch('subprocess.check_call')
def test_synchroniseRunnerWorkingDirectory(self, check_call_mock):
@mock.patch('subprocess.call')
def test_synchroniseRunnerWorkingDirectory(self, call_mock):
call_mock.return_value = SubprocessCallReturnObject()
self._setUpFakeInstanceFolder()
config = Config()
config.rsync_binary = 'rsync'
......@@ -157,10 +167,10 @@ class TestRunnerExporter(unittest.TestCase):
config, 'backup/runner/runner'
)
check_call_mock.assert_any_call(
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']
)
check_call_mock.assert_any_call(
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