[autotest] Add 10 min timeout when re-program EC/BIOS

Without the timeout, firmware provision will stuck long time before test/
special task timeout kicks in.

retry.timeout does not work with process started in code. refer to CL 288366

BUG=None
TEST=local test

Change-Id: Icefcb8841ff61a300087cb1c012f68ad96c4cb0a
Reviewed-on: https://chromium-review.googlesource.com/288974
Trybot-Ready: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/server/cros/servo/firmware_programmer.py b/server/cros/servo/firmware_programmer.py
index 6f79253..4d7c166 100644
--- a/server/cros/servo/firmware_programmer.py
+++ b/server/cros/servo/firmware_programmer.py
@@ -22,6 +22,9 @@
 from autotest_lib.server.cros.faft.config.config import Config as FAFTConfig
 
 
+# Number of seconds for program EC/BIOS to time out.
+FIRMWARE_PROGRAM_TIMEOUT_SEC = 600
+
 class ProgrammerError(Exception):
     """Local exception class wrapper."""
     pass
@@ -90,7 +93,8 @@
         self._set_servo_state()
         try:
             logging.debug("Programmer command: %s", self._program_cmd)
-            self._servo.system(self._program_cmd)
+            self._servo.system(self._program_cmd,
+                               timeout=FIRMWARE_PROGRAM_TIMEOUT_SEC)
         finally:
             self._restore_servo_state()
 
@@ -132,7 +136,8 @@
             for section in vpd_sections + gbb_section:
                 self._servo.system(' '.join([
                     'flashrom', '-V', '-p', programmer,
-                    '-r', self._fw_main, '-i', '%s:%s' % section]))
+                    '-r', self._fw_main, '-i', '%s:%s' % section]),
+                    timeout=FIRMWARE_PROGRAM_TIMEOUT_SEC)
 
             # Pack the saved VPD into new firmware
             self._servo.system('cp %s %s' % (self._fw_path, self._fw_main))
@@ -144,7 +149,8 @@
                     '-w', self._fw_main]
             for section in vpd_sections:
                 pack_cmd.extend(['-i', '%s:%s' % section])
-            self._servo.system(' '.join(pack_cmd))
+            self._servo.system(' '.join(pack_cmd),
+                               timeout=FIRMWARE_PROGRAM_TIMEOUT_SEC)
 
             # Read original HWID. The output format is:
             #    hardware_id: RAMBI TEST A_A 0128
@@ -159,7 +165,7 @@
             # Flash the new firmware
             self._servo.system(' '.join([
                     'flashrom', '-V', '-p', programmer,
-                    '-w', self._fw_main]))
+                    '-w', self._fw_main]), timeout=FIRMWARE_PROGRAM_TIMEOUT_SEC)
         finally:
             self._restore_servo_state()
 
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index dab3dc2..25abd2c 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -10,7 +10,6 @@
 import logging, re, time, xmlrpclib
 
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.common_lib import utils
 from autotest_lib.server.cros.servo import firmware_programmer
 
 
@@ -618,23 +617,24 @@
         return dest_path
 
 
-    def system(self, command, timeout=None):
+    def system(self, command, timeout=3600):
         """Execute the passed in command on the servod host.
 
         @param command Command to be executed.
-        @param timeout Maximum number of seconds of runtime allowed.
+        @param timeout Maximum number of seconds of runtime allowed. Default to
+                       1 hour.
         """
         logging.info('Will execute on servo host: %s', command)
         self._servo_host.run(command, timeout=timeout)
 
 
-    def system_output(self, command, timeout=None,
+    def system_output(self, command, timeout=3600,
                       ignore_status=False, args=()):
         """Execute the passed in command on the servod host, return stdout.
 
         @param command a string, the command to execute
         @param timeout an int, max number of seconds to wait til command
-               execution completes
+               execution completes. Default to 1 hour.
         @param ignore_status a Boolean, if true - ignore command's nonzero exit
                status, otherwise an exception will be thrown
         @param args a tuple of strings, each becoming a separate command line