| Index: build/android/buildbot/bb_device_status_check.py
|
| diff --git a/build/android/buildbot/bb_device_status_check.py b/build/android/buildbot/bb_device_status_check.py
|
| index 65fc5fed30f6c07a5d4098979ea6b9a854e3b241..52261ac549031b4d197cbde1c5a0a23918fc6976 100755
|
| --- a/build/android/buildbot/bb_device_status_check.py
|
| +++ b/build/android/buildbot/bb_device_status_check.py
|
| @@ -5,9 +5,9 @@
|
| # found in the LICENSE file.
|
|
|
| """A class to keep track of devices across builds and report state."""
|
| -import argparse
|
| import json
|
| import logging
|
| +import optparse
|
| import os
|
| import psutil
|
| import re
|
| @@ -41,7 +41,7 @@
|
|
|
| _RE_DEVICE_ID = re.compile('Device ID = (\d+)')
|
|
|
| -def DeviceInfo(device, args):
|
| +def DeviceInfo(device, options):
|
| """Gathers info on a device via various adb calls.
|
|
|
| Args:
|
| @@ -96,7 +96,7 @@
|
| dev_good = False
|
| if not battery.GetCharging():
|
| battery.SetCharging(True)
|
| - if not args.no_provisioning_check:
|
| + if not options.no_provisioning_check:
|
| setup_wizard_disabled = (
|
| device.GetProp('ro.setupwizard.mode') == 'DISABLED')
|
| if not setup_wizard_disabled and device.build_type != 'user':
|
| @@ -114,16 +114,16 @@
|
| return (build_product, build_id, battery_level, errors, dev_good, json_data)
|
|
|
|
|
| -def CheckForMissingDevices(args, devices):
|
| +def CheckForMissingDevices(options, devices):
|
| """Uses file of previous online devices to detect broken phones.
|
|
|
| Args:
|
| - args: out_dir parameter of args 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.
|
| devices: A list of DeviceUtils instance for the currently visible and
|
| online attached devices.
|
| """
|
| - out_dir = os.path.abspath(args.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
|
| @@ -224,9 +224,9 @@
|
| pass
|
|
|
|
|
| -def RecoverDevices(blacklist, output_directory):
|
| +def RecoverDevices(args):
|
| # Remove the last build's "bad devices" before checking device statuses.
|
| - blacklist.Reset()
|
| + device_blacklist.ResetBlacklist()
|
|
|
| previous_devices = set(a.GetDeviceSerial()
|
| for a in adb_wrapper.AdbWrapper.Devices())
|
| @@ -236,7 +236,7 @@
|
|
|
| try:
|
| expected_devices = set(device_list.GetPersistentDeviceList(
|
| - os.path.join(output_directory, device_list.LAST_DEVICES_FILENAME)))
|
| + os.path.join(args.out_dir, device_list.LAST_DEVICES_FILENAME)))
|
| except IOError:
|
| expected_devices = set()
|
|
|
| @@ -249,15 +249,15 @@
|
| except device_errors.CommandFailedError:
|
| logging.exception('Failure while waiting for %s. Adding to blacklist.',
|
| str(device))
|
| - blacklist.Extend([str(device)])
|
| + device_blacklist.ExtendBlacklist([str(device)])
|
| except device_errors.CommandTimeoutError:
|
| logging.exception('Timed out while waiting for %s. Adding to blacklist.',
|
| str(device))
|
| - blacklist.Extend([str(device)])
|
| + device_blacklist.ExtendBlacklist([str(device)])
|
|
|
| device_utils.DeviceUtils.parallel(all_devices).pMap(blacklisting_recovery)
|
|
|
| - devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
|
| + devices = device_utils.DeviceUtils.HealthyDevices()
|
| device_serials = set(d.adb.GetDeviceSerial() for d in devices)
|
|
|
| missing_devices = expected_devices.difference(device_serials)
|
| @@ -275,41 +275,35 @@
|
|
|
|
|
| def main():
|
| - parser = argparse.ArgumentParser()
|
| - parser.add_argument('--out-dir',
|
| - help='Directory where the device path is stored',
|
| - default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
|
| - parser.add_argument('--no-provisioning-check', action='store_true',
|
| - help='Will not check if devices are provisioned '
|
| - 'properly.')
|
| - parser.add_argument('--device-status-dashboard', action='store_true',
|
| - help='Output device status data for dashboard.')
|
| - parser.add_argument('--restart-usb', action='store_true',
|
| - help='DEPRECATED. '
|
| - 'This script now always tries to reset USB.')
|
| - parser.add_argument('--json-output',
|
| - help='Output JSON information into a specified file.')
|
| - parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
|
| - parser.add_argument('-v', '--verbose', action='count', default=1,
|
| - help='Log more information.')
|
| -
|
| - args = parser.parse_args()
|
| -
|
| - run_tests_helper.SetLogLevel(args.verbose)
|
| -
|
| - if args.blacklist_file:
|
| - blacklist = device_blacklist.Blacklist(args.blacklist_file)
|
| - else:
|
| - # TODO(jbudorick): Remove this once bots pass the blacklist file.
|
| - blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON)
|
| -
|
| - devices = RecoverDevices(blacklist, args.out_dir)
|
| + parser = optparse.OptionParser()
|
| + parser.add_option('', '--out-dir',
|
| + help='Directory where the device path is stored',
|
| + default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
|
| + parser.add_option('--no-provisioning-check', action='store_true',
|
| + help='Will not check if devices are provisioned properly.')
|
| + parser.add_option('--device-status-dashboard', action='store_true',
|
| + help='Output device status data for dashboard.')
|
| + parser.add_option('--restart-usb', action='store_true',
|
| + help='DEPRECATED. '
|
| + 'This script now always tries to reset USB.')
|
| + parser.add_option('--json-output',
|
| + help='Output JSON information into a specified file.')
|
| + parser.add_option('-v', '--verbose', action='count', default=1,
|
| + help='Log more information.')
|
| +
|
| + options, args = parser.parse_args()
|
| + if args:
|
| + parser.error('Unknown options %s' % args)
|
| +
|
| + run_tests_helper.SetLogLevel(options.verbose)
|
| +
|
| + devices = RecoverDevices(options)
|
|
|
| types, builds, batteries, errors, devices_ok, json_data = (
|
| [], [], [], [], [], [])
|
| if devices:
|
| types, builds, batteries, errors, devices_ok, json_data = (
|
| - zip(*[DeviceInfo(dev, args) for dev in devices]))
|
| + zip(*[DeviceInfo(dev, options) for dev in devices]))
|
|
|
| # Write device info to file for buildbot info display.
|
| if os.path.exists('/home/chrome-bot'):
|
| @@ -322,7 +316,7 @@
|
| except Exception:
|
| pass
|
|
|
| - err_msg = CheckForMissingDevices(args, devices) or []
|
| + err_msg = CheckForMissingDevices(options, devices) or []
|
|
|
| unique_types = list(set(types))
|
| unique_builds = list(set(builds))
|
| @@ -356,7 +350,7 @@
|
| subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name)
|
| SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg))
|
|
|
| - if args.device_status_dashboard:
|
| + if options.device_status_dashboard:
|
| offline_devices = [
|
| device_utils.DeviceUtils(a)
|
| for a in adb_wrapper.AdbWrapper.Devices(is_ready=False)
|
| @@ -372,15 +366,15 @@
|
| [battery], '%',
|
| 'unimportant')
|
|
|
| - if args.json_output:
|
| - with open(args.json_output, 'wb') as f:
|
| + if options.json_output:
|
| + with open(options.json_output, 'wb') as f:
|
| f.write(json.dumps(json_data, indent=4))
|
|
|
| num_failed_devs = 0
|
| for device_ok, device in zip(devices_ok, devices):
|
| if not device_ok:
|
| logging.warning('Blacklisting %s', str(device))
|
| - blacklist.Extend([str(device)])
|
| + device_blacklist.ExtendBlacklist([str(device)])
|
| num_failed_devs += 1
|
|
|
| if num_failed_devs == len(devices):
|
|
|