From 574c91ae1ba23ec24ccd1936a2499e6e024816d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Wed, 8 Nov 2017 14:50:37 +0100
Subject: [PATCH] cancel tests if a raid operation is in progress, refs #21696

---
 tester.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tester.py b/tester.py
index 3ef45cf9..06f154d0 100755
--- a/tester.py
+++ b/tester.py
@@ -10,6 +10,7 @@ import re
 import subprocess
 import sys
 import uuid
+import glob
 
 import utils
 from utils import log
@@ -39,6 +40,18 @@ def strip_colors(text):
     return re.sub(r'\033\[[\d;]+m', '', text)
 
 
+def raid_idle():
+    idle = True
+    devs = glob.glob('/sys/block/md*/md/sync_action')
+    for d in devs:
+        with open(d, 'r') as f:
+            sync_state = f.read()
+            if sync_state != "idle":
+                idle = False
+                print("State in %s is %s" % (d, sync_state))
+    return idle
+
+
 class Tester():
     USAGE = '''%s [-e] [-f] [-b] [-d] [-h] [msuser]
     -e: send email with report.
@@ -101,7 +114,12 @@ class Tester():
         tests = self.discover_tests(basic_only, msuser)
         if not tests:
             sys.exit(1)
-        exit_code = self.run_tests(tests, email, email_if_fail)
+
+        if raid_idle():
+            exit_code = self.run_tests(tests, email, email_if_fail)
+        else:
+            print('A RAID check or operation is in progress, aborting tests')
+            exit_code = 1
         sys.exit(exit_code)
 
     def parse_file_header(self, path):
-- 
GitLab