From d628b7a05b6d1d911a32292aa54d33b98566e630 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Thu, 1 Jun 2017 12:22:40 +0200
Subject: [PATCH] add space check for local backups too

---
 tests/test_backup.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/test_backup.py b/tests/test_backup.py
index cfea1332..9648d2b8 100755
--- a/tests/test_backup.py
+++ b/tests/test_backup.py
@@ -55,8 +55,10 @@ def test_last_backup_is_recent(server):
         return False
 
 
-def test_backup_space(server):
-    cmd = 'ssh -o StrictHostKeyChecking=no %s df -h /backup | tail -n 1' % (server)
+def test_backup_space(server=None, path="/backup"):
+    cmd = 'df -h %s | tail -n 1' % path
+    if server:
+        cmd = 'ssh -o StrictHostKeyChecking=no %s ' % server + cmd
     status, out = subprocess.getstatusoutput(cmd)
     if status == 0:
         dev, total, used, free, used_perc, mount = out.strip().split()
@@ -71,7 +73,6 @@ def test_backup_space(server):
         print('Failed to check backup space')
         return False
 
-
 def check_local_backup(path):
     all_ok = True
     backup_folder = os.path.dirname(path)
@@ -106,6 +107,7 @@ def check_local_backups(paths):
         status, out = subprocess.getstatusoutput(cmd)
         for bf in out.split('\n'):
             all_ok = min(check_local_backup(bf), all_ok)
+        all_ok = min(test_backup_space(path=f), all_ok)
     return all_ok
 
 
@@ -123,7 +125,7 @@ if os.path.isfile('../utils.py'):
             if not test_last_backup_is_recent(BACKUP_SERVER):
                 sys.exit(1)
             else:
-                if not test_backup_space(BACKUP_SERVER):
+                if not test_backup_space(server=BACKUP_SERVER):
                     sys.exit(1)
                 else:
                     sys.exit(0)
-- 
GitLab