From c408399109b3b28261269da7ebe4b98a4a3448bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Tue, 16 May 2017 19:07:35 +0200
Subject: [PATCH] test if sufficient space is available on the backup server,
 refs #20957

---
 tests/test_backup.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tests/test_backup.py b/tests/test_backup.py
index aea304cd..f67e50aa 100755
--- a/tests/test_backup.py
+++ b/tests/test_backup.py
@@ -50,6 +50,22 @@ 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)
+    status, out = subprocess.getstatusoutput(cmd)
+    if status == 0:
+        dev, total, used, free, used_perc, mount = out.strip().split()
+        used_perc = int(used_perc.replace('%',''))
+        if used_perc > 80:
+            print('There is less than 20% of available space for backups')
+            return False
+        else:
+            return True
+    else:
+        print('Failed to check backup space')
+        return False
+
+
 os.chdir(os.path.dirname(__file__))
 if os.path.isfile('../utils.py'):
     es_utils = imp.load_source('es_utils', '../utils.py')
@@ -63,7 +79,10 @@ if os.path.isfile('../utils.py'):
             if not test_last_backup_is_recent(BURP_SERVER):
                 sys.exit(1)
             else:
-                sys.exit(0)
+                if not test_backup_space(BURP_SERVER):
+                    sys.exit(1)
+                else:
+                    sys.exit(0)
     else:
         print('No BURP_SERVER defined in config, untestable')
         sys.exit(2)
-- 
GitLab