diff options
author | Karsten Tausche <karsten@fairphone.com> | 2019-01-22 11:30:22 +0100 |
---|---|---|
committer | Chase Qi <chase.qi@linaro.org> | 2019-03-14 10:38:11 +0800 |
commit | 9fc64443ef62dc2f57fc12a6cf61a42094336afe (patch) | |
tree | c64726801bf36a2d76c6abbc3b0bdd3c2cb27919 /automated/android | |
parent | 82dc6eb51ff843b45f8f504686c1becc1ecaba88 (diff) |
Tradefed MultiNode: Refactor timeout handling
Use timeout parameter of python subprocess commands instead of the
system timeout command.
Issue: INFRA-137
Change-Id: Id939f31d3d047a9d2c5d18ea4dd0151f04b567e4
Signed-off-by: Karsten Tausche <karsten@fairphone.com>
Diffstat (limited to 'automated/android')
-rw-r--r-- | automated/android/multinode/tradefed/utils.py | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/automated/android/multinode/tradefed/utils.py b/automated/android/multinode/tradefed/utils.py index 14ecac6..d470885 100644 --- a/automated/android/multinode/tradefed/utils.py +++ b/automated/android/multinode/tradefed/utils.py @@ -2,6 +2,7 @@ import logging import re import shutil import subprocess +import sys import time sys.path.insert(0, "../../../lib/") @@ -80,21 +81,24 @@ class Device: return self._is_available def check_available(self, timeout_secs=30): - return ( - subprocess.run( - [ - "timeout", - str(timeout_secs), - "adb", - "-s", - self.serial_or_address, - "shell", - "echo", - "%s:" % self.serial_or_address, - "OK", - ] - ).returncode == 0 - ) + try: + return ( + subprocess.run( + [ + "adb", + "-s", + self.serial_or_address, + "shell", + "echo", + "%s:" % self.serial_or_address, + "OK", + ], + timeout=timeout_secs, + ).returncode == 0 + ) + except subprocess.TimeoutExpired as e: + print(e) + return False def try_reconnect(self, reconnectTimeoutSecs=60): # NOTE: When running inside LAVA, self.is_tcpip_device == (self.worker_job_id is not None). @@ -106,19 +110,19 @@ class Device: # NOTE: If the boot/reboot process takes longer than the specified timeout, this # function will return failure, but the device can still become accessible in the next # iteration of device availability checks. - fastbootRebootTimeoutSecs = ( - 10 - ) # There is no point in waiting longer for fastboot - subprocess.run( - [ - "timeout", - str(fastbootRebootTimeoutSecs), - "fastboot", - "-s", - self.serial_or_address, - "reboot", - ] - ) + + # There is no point in waiting longer for `fastboot reboot`: + fastbootRebootTimeoutSecs = 10 + try: + subprocess.run( + ["fastboot", "-s", self.serial_or_address, "reboot"], + timeout=fastbootRebootTimeoutSecs, + ) + except subprocess.TimeoutExpired: + # Blocking `fastboot reboot` does not necessarily indicate a + # failure. + pass + bootTimeoutSecs = max( 10, int(reconnectTimeoutSecs) - fastbootRebootTimeoutSecs ) @@ -132,18 +136,17 @@ class Device: 5 ) # adb connect ~often~ fails when called ~directly~ after disconnect. - if ( - subprocess.run( - [ - "timeout", - str(reconnectTimeoutSecs), - "adb", - "connect", - self.serial_or_address, - ] - ).returncode != 0 - ): + try: + if ( + subprocess.run( + ["adb", "connect", self.serial_or_address], + timeout=reconnectTimeoutSecs, + ).returncode != 0 + ): + return False + except subprocess.TimeoutExpired: return False + if not self.check_available(): return False # reestablish logcat connection |