Commit 46865bb3 authored by perezju's avatar perezju Committed by Commit bot

[devil refactor] Prepare clients for DeviceUnreachableError

The catapult CL [1] will introduce a change where running adb commands
may now raise device_errors.DeviceUnreachableError if the device is
no longer found.

This change adjusts clients that were hoping to catch this kind of
error as a device_errors.[Adb]CommandFailedError.

[1]: https://codereview.chromium.org/2808763004/

BUG=https://github.com/catapult-project/catapult/issues/3476

Review-Url: https://codereview.chromium.org/2811993002
Cr-Commit-Position: refs/heads/master@{#464383}
parent a612e798
...@@ -113,7 +113,8 @@ def main(): ...@@ -113,7 +113,8 @@ def main():
device.Install(apk, reinstall=args.keep_data, device.Install(apk, reinstall=args.keep_data,
allow_downgrade=args.downgrade, allow_downgrade=args.downgrade,
timeout=args.timeout) timeout=args.timeout)
except device_errors.CommandFailedError: except (device_errors.CommandFailedError,
device_errors.DeviceUnreachableError):
logging.exception('Failed to install %s', args.apk_name) logging.exception('Failed to install %s', args.apk_name)
if blacklist: if blacklist:
blacklist.Extend([str(device)], reason='install_failure') blacklist.Extend([str(device)], reason='install_failure')
...@@ -129,4 +130,3 @@ def main(): ...@@ -129,4 +130,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
...@@ -137,7 +137,8 @@ def ProvisionDevice(device, blacklist, options): ...@@ -137,7 +137,8 @@ def ProvisionDevice(device, blacklist, options):
if blacklist: if blacklist:
blacklist.Extend([str(device)], reason='provision_timeout') blacklist.Extend([str(device)], reason='provision_timeout')
except device_errors.CommandFailedError: except (device_errors.CommandFailedError,
device_errors.DeviceUnreachableError):
logging.exception('Failed to provision device %s. Adding to blacklist.', logging.exception('Failed to provision device %s. Adding to blacklist.',
str(device)) str(device))
if blacklist: if blacklist:
......
...@@ -172,6 +172,8 @@ class _ApkDelegate(object): ...@@ -172,6 +172,8 @@ class _ApkDelegate(object):
logging.exception('gtest shard failed.') logging.exception('gtest shard failed.')
except device_errors.CommandTimeoutError: except device_errors.CommandTimeoutError:
logging.exception('gtest shard timed out.') logging.exception('gtest shard timed out.')
except device_errors.DeviceUnreachableError:
logging.exception('gtest shard device unreachable.')
except Exception: except Exception:
device.ForceStop(self._package) device.ForceStop(self._package)
raise raise
......
...@@ -245,7 +245,8 @@ class DeviceTestShard(TestShard): ...@@ -245,7 +245,8 @@ class DeviceTestShard(TestShard):
result_type = self._RunSingleTest(test) result_type = self._RunSingleTest(test)
except device_errors.CommandTimeoutError: except device_errors.CommandTimeoutError:
result_type = base_test_result.ResultType.TIMEOUT result_type = base_test_result.ResultType.TIMEOUT
except device_errors.CommandFailedError: except (device_errors.CommandFailedError,
device_errors.DeviceUnreachableError):
logging.exception('Exception when executing %s.', test) logging.exception('Exception when executing %s.', test)
result_type = base_test_result.ResultType.FAIL result_type = base_test_result.ResultType.FAIL
finally: finally:
......
...@@ -49,6 +49,8 @@ def _ListTombstones(device): ...@@ -49,6 +49,8 @@ def _ListTombstones(device):
datetime.datetime.fromtimestamp(entry['st_mtime'])) datetime.datetime.fromtimestamp(entry['st_mtime']))
except device_errors.CommandFailedError: except device_errors.CommandFailedError:
logging.exception('Could not retrieve tombstones.') logging.exception('Could not retrieve tombstones.')
except device_errors.DeviceUnreachableError:
logging.exception('Device unreachable retrieving tombstones.')
except device_errors.CommandTimeoutError: except device_errors.CommandTimeoutError:
logging.exception('Timed out retrieving tombstones.') logging.exception('Timed out retrieving tombstones.')
......
...@@ -793,7 +793,8 @@ class ChromiumAndroidDriver(driver.Driver): ...@@ -793,7 +793,8 @@ class ChromiumAndroidDriver(driver.Driver):
log_callback('installing apk if necessary') log_callback('installing apk if necessary')
self._device.Install(driver_host_path) self._device.Install(driver_host_path)
except (device_errors.CommandFailedError, except (device_errors.CommandFailedError,
device_errors.CommandTimeoutError) as exc: device_errors.CommandTimeoutError,
device_errors.DeviceUnreachableError) as exc:
self._abort('Failed to install %s onto device: %s' % (driver_host_path, str(exc))) self._abort('Failed to install %s onto device: %s' % (driver_host_path, str(exc)))
def _push_fonts(self, log_callback): def _push_fonts(self, log_callback):
......
...@@ -230,7 +230,8 @@ class AndroidProfileTool(object): ...@@ -230,7 +230,8 @@ class AndroidProfileTool(object):
self._device.PushChangedFiles([(self._cygprofile_tests, device_path)]) self._device.PushChangedFiles([(self._cygprofile_tests, device_path)])
try: try:
self._device.RunShellCommand(device_path, check_return=True) self._device.RunShellCommand(device_path, check_return=True)
except device_errors.CommandFailedError: except (device_errors.CommandFailedError,
device_errors.DeviceUnreachableError):
# TODO(jbudorick): Let the exception propagate up once clients can # TODO(jbudorick): Let the exception propagate up once clients can
# handle it. # handle it.
logging.exception('Failure while running cygprofile_unittests:') logging.exception('Failure while running cygprofile_unittests:')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment