Add an option to wait_for_restart to not log errors unless we want it to, this is necessary for hard reboot testing with retries

Signed-off-by: Scott Zawalski <scottz@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3990 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/serial.py b/server/hosts/serial.py
index 576396a..6daffdd 100644
--- a/server/hosts/serial.py
+++ b/server/hosts/serial.py
@@ -117,12 +117,12 @@
                   conmux_command='hardreset', num_attempts=1):
         """
         Reach out and slap the box in the power switch.
-        Args:
-                conmux_command: The command to run via the conmux interface
-                timeout: timelimit in seconds before the machine is
-                considered unreachable
-                wait: Whether or not to wait for the machine to reboot
-
+        @params conmux_command: The command to run via the conmux interface
+        @params timeout: timelimit in seconds before the machine is
+                         considered unreachable
+        @params wait: Whether or not to wait for the machine to reboot
+        @params num_attempts: Number of times to attempt hard reset erroring
+                              on the last attempt.
         """
         conmux_command = "'~$%s'" % conmux_command
         def reboot():
@@ -133,17 +133,23 @@
                     'Hard reset unavailable')
             self.record("GOOD", None, "reboot.start", "hard reset")
             if wait:
-                for _ in xrange(num_attempts):
+                warning_msg = ('Serial console failed to respond to hard reset '
+                               'attempt (%s/%s)')
+                for attempt in xrange(num_attempts-1):
                     try:
-                        self.wait_for_restart(timeout)
+                        self.wait_for_restart(timeout, log_failure=False)
                     except error.AutoservShutdownError:
-                        msg = "Serial console failed to respond to hard reset"
-                        logging.warning(msg)
+                        logging.warning(warning_msg, attempt, num_attempts)
                     else:
                         break
                 else:
-                    msg = "Host did not shutdown"
-                    raise error.AutoservShutdownError(msg)
+                    # Run on num_attempts=1 or last retry
+                    try:
+                        self.wait_for_restart(timeout)
+                    except error.AutoservShutdwonError:
+                        logging.warning(warning_msg, num_attempts, num_attempts)
+                        msg = "Host did not shutdown"
+                        raise error.AutoservShutdownError(msg)
 
         if self.job:
             self.job.disable_warnings("POWER_FAILURE")