Allow for multiple retries when attempting to hard reset a
a machine using conmux.

Signed-off-by: Travis Miller <raphtee@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@3435 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/serial.py b/server/hosts/serial.py
index 9960cf7..576396a 100644
--- a/server/hosts/serial.py
+++ b/server/hosts/serial.py
@@ -114,7 +114,7 @@
 
 
     def hardreset(self, timeout=DEFAULT_REBOOT_TIMEOUT, wait=True,
-                  conmux_command='hardreset'):
+                  conmux_command='hardreset', num_attempts=1):
         """
         Reach out and slap the box in the power switch.
         Args:
@@ -133,7 +133,17 @@
                     'Hard reset unavailable')
             self.record("GOOD", None, "reboot.start", "hard reset")
             if wait:
-                self.wait_for_restart(timeout)
+                for _ in xrange(num_attempts):
+                    try:
+                        self.wait_for_restart(timeout)
+                    except error.AutoservShutdownError:
+                        msg = "Serial console failed to respond to hard reset"
+                        logging.warning(msg)
+                    else:
+                        break
+                else:
+                    msg = "Host did not shutdown"
+                    raise error.AutoservShutdownError(msg)
 
         if self.job:
             self.job.disable_warnings("POWER_FAILURE")