Add an optional warning in case the system doesn't shutdown in a
timely manner.

Signed-off-by: Jean-Marc Eurin <[email protected]>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@2975 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/abstract_ssh.py b/server/hosts/abstract_ssh.py
index 093838a..063e7cf 100644
--- a/server/hosts/abstract_ssh.py
+++ b/server/hosts/abstract_ssh.py
@@ -282,7 +282,7 @@
         return False
 
 
-    def wait_down(self, timeout=None):
+    def wait_down(self, timeout=None, warning_timer=None):
         """
         Wait until the remote host is down or the timeout expires.
 
@@ -290,19 +290,33 @@
         host fails.
 
         Args:
-                timeout: time limit in seconds before returning even
-                        if the host is not up.
+            timeout: time limit in seconds before returning even
+                     if the host is still up.
+            warning_timer: time limit in seconds that will generate
+                     a warning if the host is not down yet.
 
         Returns:
                 True if the host was found to be down, False otherwise
         """
+        current_time = time.time()
         if timeout:
-            end_time = time.time() + timeout
+            end_time = current_time + timeout
 
-        while not timeout or time.time() < end_time:
+        if warning_timer:
+            warn_time = current_time + warning_timer
+
+        while not timeout or current_time < end_time:
             if not self.is_up():
                 return True
+
+            if warning_timer and current_time > warn_time:
+                self.record("WARN", None, "shutdown",
+                            "Shutdown took longer than %ds" % warning_timer)
+                # Print the warning only once.
+                warning_timer = None
+
             time.sleep(1)
+            current_time = time.time()
 
         return False