From c06c61228878829cb3a96c261c9d3a34a47442aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Mon, 16 Apr 2018 16:35:54 +0200
Subject: [PATCH] Fixed RAID test (refs #25198).

---
 tests/test_raid.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/tests/test_raid.py b/tests/test_raid.py
index a80245ae..3bc701b8 100755
--- a/tests/test_raid.py
+++ b/tests/test_raid.py
@@ -14,33 +14,43 @@ GREEN = '\033[92m'
 RED = '\033[91m'
 DEF = '\033[0m'
 
+
 def print_red(string):
     print(RED + string + DEF)
 
+
 def print_green(string):
     print(GREEN + string + DEF)
 
+
 def check_raid(dev):
     cmd = 'mdadm -D %s' % dev
     status, output = subprocess.getstatusoutput(cmd)
-    ok = status == 0
-    print('%s status: %s' % (dev, ok))
-    return ok
+    if status != 0:
+        print_red('The mdadm command on %s failed:' % dev)
+    elif 'degraded' in output:
+        print_red('The %s RAID partition is degraded:' % dev)
+    else:
+        print_green('The %s RAID partition is ok.' % dev)
+        return True
+    print(cmd)
+    print(output)
+    return False
+
 
 if os.path.isfile('/proc/mdstat'):
     all_ok = True
     for r in glob.glob('/dev/md*'):
         # ignore /dev/md folder
-        if os.path.isfile(r):
+        if os.path.exists(r) and not os.path.isdir(r):
             all_ok = min(check_raid(r), all_ok)
     if all_ok:
         print_green('Everything fine')
     else:
         print_red('Some array is in bad shape')
-        with open('/proc/mdstat', 'r') as f:
-            d = f.read()
-        print(d)
-    sys.exit(not all_ok)
+        with open('/proc/mdstat', 'r') as fo:
+            print(fo.read())
+    sys.exit(int(not all_ok))
 else:
     print('No software RAID array found, untestable')
     sys.exit(2)
-- 
GitLab