Commit f953e418 authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Remove hand-rolled adb devices call from bb_device_status_check.

BUG=489219,267773

Review URL: https://codereview.chromium.org/1123263005

Cr-Commit-Position: refs/heads/master@{#330702}
parent 84251bbd
...@@ -27,9 +27,9 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ...@@ -27,9 +27,9 @@ sys.path.append(os.path.join(os.path.dirname(__file__),
import perf_tests_results_helper # pylint: disable=F0401 import perf_tests_results_helper # pylint: disable=F0401
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from pylib import android_commands
from pylib import constants from pylib import constants
from pylib.cmd_helper import GetCmdOutput from pylib.cmd_helper import GetCmdOutput
from pylib.device import adb_wrapper
from pylib.device import battery_utils from pylib.device import battery_utils
from pylib.device import device_blacklist from pylib.device import device_blacklist
from pylib.device import device_errors from pylib.device import device_errors
...@@ -39,17 +39,16 @@ from pylib.utils import run_tests_helper ...@@ -39,17 +39,16 @@ from pylib.utils import run_tests_helper
_RE_DEVICE_ID = re.compile('Device ID = (\d+)') _RE_DEVICE_ID = re.compile('Device ID = (\d+)')
def DeviceInfo(serial, options): def DeviceInfo(device, options):
"""Gathers info on a device via various adb calls. """Gathers info on a device via various adb calls.
Args: Args:
serial: The serial of the attached device to construct info about. device: A DeviceUtils instance for the device to construct info about.
Returns: Returns:
Tuple of device type, build id, report as a string, error messages, and Tuple of device type, build id, report as a string, error messages, and
boolean indicating whether or not device can be used for testing. boolean indicating whether or not device can be used for testing.
""" """
device = device_utils.DeviceUtils(serial)
battery = battery_utils.BatteryUtils(device) battery = battery_utils.BatteryUtils(device)
build_product = '' build_product = ''
...@@ -64,7 +63,7 @@ def DeviceInfo(serial, options): ...@@ -64,7 +63,7 @@ def DeviceInfo(serial, options):
build_id = device.build_id build_id = device.build_id
json_data = { json_data = {
'serial': serial, 'serial': device.adb.GetDeviceSerial(),
'type': build_product, 'type': build_product,
'build': build_id, 'build': build_id,
'build_detail': device.GetProp('ro.build.fingerprint'), 'build_detail': device.GetProp('ro.build.fingerprint'),
...@@ -79,7 +78,7 @@ def DeviceInfo(serial, options): ...@@ -79,7 +78,7 @@ def DeviceInfo(serial, options):
battery_level = int(battery_info.get('level', battery_level)) battery_level = int(battery_info.get('level', battery_level))
json_data['battery'] = battery_info json_data['battery'] = battery_info
except device_errors.CommandFailedError: except device_errors.CommandFailedError:
logging.exception('Failed to get battery information for %s', serial) logging.exception('Failed to get battery information for %s', str(device))
try: try:
for l in device.RunShellCommand(['dumpsys', 'iphonesubinfo'], for l in device.RunShellCommand(['dumpsys', 'iphonesubinfo'],
...@@ -88,7 +87,7 @@ def DeviceInfo(serial, options): ...@@ -88,7 +87,7 @@ def DeviceInfo(serial, options):
if m: if m:
json_data['imei_slice'] = m.group(1)[-6:] json_data['imei_slice'] = m.group(1)[-6:]
except device_errors.CommandFailedError: except device_errors.CommandFailedError:
logging.exception('Failed to get IMEI slice for %s', serial) logging.exception('Failed to get IMEI slice for %s', str(device))
if battery_level < 15: if battery_level < 15:
errors += ['Device critically low in battery.'] errors += ['Device critically low in battery.']
...@@ -113,16 +112,17 @@ def DeviceInfo(serial, options): ...@@ -113,16 +112,17 @@ def DeviceInfo(serial, options):
return (build_product, build_id, battery_level, errors, dev_good, json_data) return (build_product, build_id, battery_level, errors, dev_good, json_data)
def CheckForMissingDevices(options, adb_online_devs): def CheckForMissingDevices(options, devices):
"""Uses file of previous online devices to detect broken phones. """Uses file of previous online devices to detect broken phones.
Args: Args:
options: out_dir parameter of options argument is used as the base options: out_dir parameter of options argument is used as the base
directory to load and update the cache file. directory to load and update the cache file.
adb_online_devs: A list of serial numbers of the currently visible devices: A list of DeviceUtils instance for the currently visible and
and online attached devices. online attached devices.
""" """
out_dir = os.path.abspath(options.out_dir) out_dir = os.path.abspath(options.out_dir)
device_serials = set(d.adb.GetDeviceSerial() for d in devices)
# last_devices denotes all known devices prior to this run # last_devices denotes all known devices prior to this run
last_devices_path = os.path.join(out_dir, device_list.LAST_DEVICES_FILENAME) last_devices_path = os.path.join(out_dir, device_list.LAST_DEVICES_FILENAME)
...@@ -140,7 +140,7 @@ def CheckForMissingDevices(options, adb_online_devs): ...@@ -140,7 +140,7 @@ def CheckForMissingDevices(options, adb_online_devs):
except IOError: except IOError:
last_missing_devices = [] last_missing_devices = []
missing_devs = list(set(last_devices) - set(adb_online_devs)) missing_devs = list(set(last_devices) - device_serials)
new_missing_devs = list(set(missing_devs) - set(last_missing_devices)) new_missing_devs = list(set(missing_devs) - set(last_missing_devices))
if new_missing_devs and os.environ.get('BUILDBOT_SLAVENAME'): if new_missing_devs and os.environ.get('BUILDBOT_SLAVENAME'):
...@@ -160,7 +160,7 @@ def CheckForMissingDevices(options, adb_online_devs): ...@@ -160,7 +160,7 @@ def CheckForMissingDevices(options, adb_online_devs):
'\n'.join(map(str, new_missing_devs))) '\n'.join(map(str, new_missing_devs)))
SendEmail(from_address, to_addresses, cc_addresses, subject, msg) SendEmail(from_address, to_addresses, cc_addresses, subject, msg)
all_known_devices = list(set(adb_online_devs) | set(last_devices)) all_known_devices = list(device_serials | set(last_devices))
device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) device_list.WritePersistentDeviceList(last_devices_path, all_known_devices)
device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs) device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs)
...@@ -171,27 +171,10 @@ def CheckForMissingDevices(options, adb_online_devs): ...@@ -171,27 +171,10 @@ def CheckForMissingDevices(options, adb_online_devs):
if missing_devs: if missing_devs:
devices_missing_msg = '%d devices not detected.' % len(missing_devs) devices_missing_msg = '%d devices not detected.' % len(missing_devs)
bb_annotations.PrintSummaryText(devices_missing_msg) bb_annotations.PrintSummaryText(devices_missing_msg)
return ['Current online devices: %s' % ', '.join(d for d in device_serials),
# TODO(navabi): Debug by printing both output from GetCmdOutput and '%s are no longer visible. Were they removed?' % missing_devs]
# GetAttachedDevices to compare results.
crbug_link = ('https://code.google.com/p/chromium/issues/entry?summary='
'%s&comment=%s&labels=Restrict-View-Google,OS-Android,Infra' %
(urllib.quote('Device Offline'),
urllib.quote('Buildbot: %s %s\n'
'Build: %s\n'
'(please don\'t change any labels)' %
(os.environ.get('BUILDBOT_BUILDERNAME'),
os.environ.get('BUILDBOT_SLAVENAME'),
os.environ.get('BUILDBOT_BUILDNUMBER')))))
return ['Current online devices: %s' % adb_online_devs,
'%s are no longer visible. Were they removed?' % missing_devs,
'SHERIFF:',
'@@@STEP_LINK@Click here to file a bug@%s@@@' % crbug_link,
'Cache file: %s' % last_devices_path,
'adb devices: %s' % GetCmdOutput(['adb', 'devices']),
'adb devices(GetAttachedDevices): %s' % adb_online_devs]
else: else:
new_devs = set(adb_online_devs) - set(last_devices) new_devs = device_serials - set(last_devices)
if new_devs and os.path.exists(last_devices_path): if new_devs and os.path.exists(last_devices_path):
bb_annotations.PrintWarning() bb_annotations.PrintWarning()
bb_annotations.PrintSummaryText( bb_annotations.PrintSummaryText(
...@@ -303,11 +286,12 @@ def main(): ...@@ -303,11 +286,12 @@ def main():
os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME)) os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME))
except IOError: except IOError:
expected_devices = [] expected_devices = []
devices = android_commands.GetAttachedDevices() devices = device_utils.DeviceUtils.HealthyDevices()
device_serials = [d.adb.GetDeviceSerial() for d in devices]
# Only restart usb if devices are missing. # Only restart usb if devices are missing.
if set(expected_devices) != set(devices): if set(expected_devices) != set(device_serials):
logging.warning('expected_devices: %s', expected_devices) logging.warning('expected_devices: %s', expected_devices)
logging.warning('devices: %s', devices) logging.warning('devices: %s', device_serials)
KillAllAdb() KillAllAdb()
retries = 5 retries = 5
usb_restarted = True usb_restarted = True
...@@ -320,8 +304,9 @@ def main(): ...@@ -320,8 +304,9 @@ def main():
while retries: while retries:
logging.info('retry adb devices...') logging.info('retry adb devices...')
time.sleep(1) time.sleep(1)
devices = android_commands.GetAttachedDevices() devices = device_utils.DeviceUtils.HealthyDevices()
if set(expected_devices) == set(devices): device_serials = [d.adb.GetDeviceSerial() for d in devices]
if set(expected_devices) == set(device_serials):
# All devices are online, keep going. # All devices are online, keep going.
break break
if not usb_restarted and devices: if not usb_restarted and devices:
...@@ -330,10 +315,6 @@ def main(): ...@@ -330,10 +315,6 @@ def main():
break break
retries -= 1 retries -= 1
# TODO(navabi): Test to make sure this fails and then fix call
offline_devices = android_commands.GetAttachedDevices(
hardware=False, emulator=False, offline=True)
types, builds, batteries, errors, devices_ok, json_data = ( types, builds, batteries, errors, devices_ok, json_data = (
[], [], [], [], [], []) [], [], [], [], [], [])
if devices: if devices:
...@@ -369,9 +350,9 @@ def main(): ...@@ -369,9 +350,9 @@ def main():
logging.info(' WiFi IP: %s', j.get('wifi_ip')) logging.info(' WiFi IP: %s', j.get('wifi_ip'))
for serial, dev_errors in zip(devices, errors): for dev, dev_errors in zip(devices, errors):
if dev_errors: if dev_errors:
err_msg += ['%s errors:' % serial] err_msg += ['%s errors:' % str(dev)]
err_msg += [' %s' % error for error in dev_errors] err_msg += [' %s' % error for error in dev_errors]
if err_msg: if err_msg:
...@@ -386,13 +367,18 @@ def main(): ...@@ -386,13 +367,18 @@ def main():
SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg))
if options.device_status_dashboard: if options.device_status_dashboard:
offline_devices = [
device_utils.DeviceUtils(a)
for a in adb_wrapper.AdbWrapper.Devices(is_ready=False)
if a.GetState() == 'offline']
perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices',
[len(devices)], 'devices') [len(devices)], 'devices')
perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices',
[len(offline_devices)], 'devices', [len(offline_devices)], 'devices',
'unimportant') 'unimportant')
for serial, battery in zip(devices, batteries): for dev, battery in zip(devices, batteries):
perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev),
[battery], '%', [battery], '%',
'unimportant') 'unimportant')
......
...@@ -175,6 +175,8 @@ class AdbWrapper(object): ...@@ -175,6 +175,8 @@ class AdbWrapper(object):
"""Get the list of active attached devices. """Get the list of active attached devices.
Args: Args:
is_ready: Whether the devices should be limited to only those that are
ready for use.
timeout: (optional) Timeout per try in seconds. timeout: (optional) Timeout per try in seconds.
retries: (optional) Number of retries to attempt. retries: (optional) Number of retries to attempt.
......
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