Commit 2b3b9318 authored by Nicolas Wavrant's avatar Nicolas Wavrant

fixup

parent 61e85392
...@@ -21,6 +21,7 @@ from zc.buildout.configparser import parse ...@@ -21,6 +21,7 @@ from zc.buildout.configparser import parse
os.environ['LC_ALL'] = 'C' os.environ['LC_ALL'] = 'C'
os.umask(0o77) os.umask(0o77)
@contextmanager @contextmanager
def CwdContextManager(path): def CwdContextManager(path):
""" """
...@@ -91,7 +92,7 @@ def getExcludePathList(path): ...@@ -91,7 +92,7 @@ def getExcludePathList(path):
if p: if p:
excluded_path_list.append(os.path.relpath(p, path)) excluded_path_list.append(os.path.relpath(p, path))
for partition in glob.glob(path + "/instance/slappart*"): for partition in glob.glob(os.path.join(path, "instance", "slappart*")):
if not os.path.isdir(partition): if not os.path.isdir(partition):
continue continue
...@@ -139,7 +140,7 @@ def synchroniseRunnerConfigurationDirectory(config, backup_path): ...@@ -139,7 +140,7 @@ def synchroniseRunnerConfigurationDirectory(config, backup_path):
def synchroniseRunnerWorkingDirectory(config, backup_path): def synchroniseRunnerWorkingDirectory(config, backup_path):
if os.path.exists('instance') and os.path.isdir('instance'): if os.path.isdir('instance'):
exclude_list = getExcludePathList('.') exclude_list = getExcludePathList('.')
rsync( rsync(
config.rsync_binary, 'instance', backup_path, config.rsync_binary, 'instance', backup_path,
...@@ -188,18 +189,19 @@ def writeSignatureFile(slappart_signature_method_dict, runner_working_path, sign ...@@ -188,18 +189,19 @@ def writeSignatureFile(slappart_signature_method_dict, runner_working_path, sign
signature_file.write("\n".join(sorted(signature_list))) signature_file.write("\n".join(sorted(signature_list)))
def backupFilesWereModifiedDuringExport(): def backupFilesWereModifiedDuringExport(export_start_date):
process = subprocess.Popen(['find', '-cmin', '0.1', '-type', 'f'], stdout=subprocess.PIPE) export_time = (datetime.now() - export_start_date).total_seconds()
time.sleep(1)
process = subprocess.Popen(['find', '-cmin', str(export_time / 60.), '-type', 'f', '!', '-path', '*/srv/backup/*'], stdout=subprocess.PIPE)
process.wait() process.wait()
changed_file_output = process.stdout.read() if process.stdout.read():
for line in changed_file_output.split('\n'):
if '/srv/backup/' in line:
return True return True
return False return False
def runExport(): def runExport():
print(datetime.now().isoformat()) export_start_date = datetime.now()
print(export_start_date.isoformat())
args = parseArgumentList() args = parseArgumentList()
...@@ -232,7 +234,7 @@ def runExport(): ...@@ -232,7 +234,7 @@ def runExport():
# BBB: clean software folder if it was synchronized # BBB: clean software folder if it was synchronized
# in an old instance # in an old instance
backup_software_path = os.path.join(backup_runner_path, 'software') backup_software_path = os.path.join(backup_runner_path, 'software')
if os.path.exists(backup_software_path) and os.path.isdir(backup_software_path): if os.path.isdir(backup_software_path):
shutil.rmtree(backup_software_path) shutil.rmtree(backup_software_path)
...@@ -241,7 +243,7 @@ def runExport(): ...@@ -241,7 +243,7 @@ def runExport():
# Check that export didn't happen during backup of instances # Check that export didn't happen during backup of instances
with CwdContextManager(backup_runner_path): with CwdContextManager(backup_runner_path):
if backupFilesWereModifiedDuringExport(): if backupFilesWereModifiedDuringExport(export_start_date):
print("ERROR: Some backups are not consistent, exporter should be re-run." print("ERROR: Some backups are not consistent, exporter should be re-run."
" Let's sleep %s minutes, to let the backup end..." % backup_wait_time) " Let's sleep %s minutes, to let the backup end..." % backup_wait_time)
time.sleep(backup_wait_time * 60) time.sleep(backup_wait_time * 60)
......
...@@ -4,6 +4,7 @@ import shutil ...@@ -4,6 +4,7 @@ import shutil
import time import time
import unittest import unittest
from datetime import datetime, timedelta
from slapos.resilient import runner_exporter from slapos.resilient import runner_exporter
tested_instance_cfg = """[buildout] tested_instance_cfg = """[buildout]
...@@ -203,6 +204,6 @@ class TestRunnerExporter(unittest.TestCase): ...@@ -203,6 +204,6 @@ class TestRunnerExporter(unittest.TestCase):
def test_backupFilesWereModifiedDuringExport(self): def test_backupFilesWereModifiedDuringExport(self):
self._setUpFakeInstanceFolder() self._setUpFakeInstanceFolder()
with runner_exporter.CwdContextManager('instance'): with runner_exporter.CwdContextManager('instance'):
self.assertTrue(runner_exporter.backupFilesWereModifiedDuringExport()) self.assertTrue(runner_exporter.backupFilesWereModifiedDuringExport(datetime.now() + timedelta(seconds=-5)))
time.sleep(11) time.sleep(2)
self.assertFalse(runner_exporter.backupFilesWereModifiedDuringExport()) self.assertFalse(runner_exporter.backupFilesWereModifiedDuringExport(datetime.now() + timedelta(seconds=-1)))
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