[autotest] Add retry to adb command passed but return value failed to be parsed.

For some reason, an adb command can pass but the return value is not in the
desired format of "ADB_CMD_OUTPUT:<value>"

BUG=b:29759939
TEST=local run command through adb_host

Change-Id: If026b67586d18fea478801daf6df13f624a610b0
Reviewed-on: https://chromium-review.googlesource.com/361021
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Bindu Mahadev <bmahadev@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
diff --git a/server/hosts/adb_host.py b/server/hosts/adb_host.py
index 8d15a1e..c0c7124 100644
--- a/server/hosts/adb_host.py
+++ b/server/hosts/adb_host.py
@@ -79,7 +79,7 @@
 WAIT_UP_AFTER_WIPE_TIME_SECONDS = 1200
 
 # Default timeout for retrying adb/fastboot command.
-DEFAULT_COMMAND_RETRY_TIMEOUT_SECONDS = 10
+DEFAULT_COMMAND_RETRY_TIMEOUT_SECONDS = 20
 
 OS_TYPE_ANDROID = 'android'
 OS_TYPE_BRILLO = 'brillo'
@@ -140,6 +140,12 @@
     """Generic error for Android installation related exceptions."""
 
 
+class AutoservRunParseError(error.AutoservRunError):
+    """Error when a command return successfully but the return value is failed
+    to be parsed.
+    """
+
+
 class ADBHost(abstract_ssh.AbstractSSHHost):
     """This class represents a host running an ADB server."""
 
@@ -462,6 +468,8 @@
             self._enable_native_crash_logging()
 
 
+    @retry.retry(AutoservRunParseError,
+                 timeout_min=DEFAULT_COMMAND_RETRY_TIMEOUT_SECONDS/60.0)
     def run(self, command, timeout=3600, ignore_status=False,
             ignore_timeout=False, stdout_tee=utils.TEE_TO_LOGS,
             stderr_tee=utils.TEE_TO_LOGS, connect_timeout=30, options='',
@@ -493,6 +501,8 @@
                  ignore_timeout is True.
 
         @raises AutoservRunError: If the command failed.
+        @raises AutoservRunParseError: If the command finished but failed to
+                pass the return value.
         @raises AutoservSSHTimeout: Ssh connection has timed out.
         """
         command = ('"%s; echo %s:\$?"' %
@@ -509,7 +519,7 @@
 
         parse_output = re.match(CMD_OUTPUT_REGEX, result.stdout)
         if not parse_output and not ignore_status:
-            raise error.AutoservRunError(
+            raise AutoservRunParseError(
                     'Failed to parse the exit code for command: %s' %
                     command, result)
         elif parse_output: