From 569f360d8d3901b280082b974849cbe7a8e1dcae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Thu, 2 Mar 2017 15:50:28 +0100
Subject: [PATCH] initial implementation of backup test, refs #20687

---
 tests/test_backup.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100755 tests/test_backup.py

diff --git a/tests/test_backup.py b/tests/test_backup.py
new file mode 100755
index 00000000..1aa9ede1
--- /dev/null
+++ b/tests/test_backup.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright 2017, Florent Thiery
+'''
+Criticality: Medium
+Checks that the server backups are not older than a day 
+'''
+import os
+import sys
+import subprocess
+import imp
+
+os.chdir(os.path.dirname(__file__))
+
+def test_ssh(server):
+    return subprocess.getstatus('ssh %s ls /tmp' % server) == 0
+
+def test_last_backup_is_recent(server, client):
+    path = '/backup/%s/current' % client
+    cmd = 'ssh %s ls -l %s | grep current' % (server, path)
+    status, out = subprocess.getstatusoutput(cmd).strip()
+    if status == 0:
+        date = out.split(' ')[-1]
+        print(date)
+    else:
+        return False
+
+if os.path.isfile('../utils.py'):
+    es_utils = imp.load_source('es_utils', '../utils.py')
+    conf = es_utils.load_conf()
+    BURP_SERVER = conf.get('BURP_SERVER') 
+    BURP_CLIENT_NAME = conf.get('BURP_CLIENT_NAME', 'localhost')
+    if BURP_SERVER:
+        if not test_ssh(BURP_SERVER):
+            print('Failed to ssh into backup server')
+            sys.exit(1)
+        else:
+            test_last_backup_is_recent(BURP_SERVER, BURP_CLIENT_NAME)
+
+    else:
+        sys.exit(2)
+else:
+    sys.exit(2)
-- 
GitLab