Chromium Code Reviews| 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 abfe78f38fc9a42c60259de3abb7bced6d6087d9..ab201aea9d744c73adf95d722b8b91eb4733f238 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 @@ from pylib.utils import timeout_retry |
| _RE_DEVICE_ID = re.compile('Device ID = (\d+)') |
| -def DeviceInfo(device, options): |
| +def DeviceInfo(device, args): |
|
rnephew (Reviews Here)
2015/08/07 22:26:31
Should this transition from optprase to argparse b
|
| """Gathers info on a device via various adb calls. |
| Args: |
| @@ -96,7 +96,7 @@ def DeviceInfo(device, options): |
| dev_good = False |
| if not battery.GetCharging(): |
| battery.SetCharging(True) |
| - if not options.no_provisioning_check: |
| + if not args.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 @@ def DeviceInfo(device, options): |
| return (build_product, build_id, battery_level, errors, dev_good, json_data) |
| -def CheckForMissingDevices(options, devices): |
| +def CheckForMissingDevices(args, devices): |
| """Uses file of previous online devices to detect broken phones. |
| Args: |
| - options: out_dir parameter of options argument is used as the base |
| + args: out_dir parameter of args 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(options.out_dir) |
| + out_dir = os.path.abspath(args.out_dir) |
| device_serials = set(d.adb.GetDeviceSerial() for d in devices) |
| # last_devices denotes all known devices prior to this run |
| @@ -225,48 +225,54 @@ def KillAllAdb(): |
| def main(): |
| - 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) |
| + 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) |
| # Remove the last build's "bad devices" before checking device statuses. |
| - device_blacklist.ResetBlacklist() |
| + blacklist.Reset() |
| KillAllAdb() |
| reset_usb.reset_all_android_devices() |
| try: |
| expected_devices = set(device_list.GetPersistentDeviceList( |
| - os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME))) |
| + os.path.join(args.out_dir, device_list.LAST_DEVICES_FILENAME))) |
| except IOError: |
| expected_devices = set() |
| def all_devices_found(): |
| - devices = device_utils.DeviceUtils.HealthyDevices() |
| + devices = device_utils.DeviceUtils.HealthyDevices(blacklist) |
| device_serials = set(d.adb.GetDeviceSerial() for d in devices) |
| return not bool(expected_devices.difference(device_serials)) |
| timeout_retry.WaitFor(all_devices_found, wait_period=1, max_tries=5) |
| - devices = device_utils.DeviceUtils.HealthyDevices() |
| + devices = device_utils.DeviceUtils.HealthyDevices(blacklist) |
| device_serials = set(d.adb.GetDeviceSerial() for d in devices) |
| missing_devices = expected_devices.difference(device_serials) |
| @@ -284,7 +290,7 @@ def main(): |
| [], [], [], [], [], []) |
| if devices: |
| types, builds, batteries, errors, devices_ok, json_data = ( |
| - zip(*[DeviceInfo(dev, options) for dev in devices])) |
| + zip(*[DeviceInfo(dev, args) for dev in devices])) |
| # Write device info to file for buildbot info display. |
| if os.path.exists('/home/chrome-bot'): |
| @@ -297,7 +303,7 @@ def main(): |
| except Exception: |
| pass |
| - err_msg = CheckForMissingDevices(options, devices) or [] |
| + err_msg = CheckForMissingDevices(args, devices) or [] |
| unique_types = list(set(types)) |
| unique_builds = list(set(builds)) |
| @@ -331,7 +337,7 @@ def main(): |
| subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) |
| SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) |
| - if options.device_status_dashboard: |
| + if args.device_status_dashboard: |
| offline_devices = [ |
| device_utils.DeviceUtils(a) |
| for a in adb_wrapper.AdbWrapper.Devices(is_ready=False) |
| @@ -347,15 +353,15 @@ def main(): |
| [battery], '%', |
| 'unimportant') |
| - if options.json_output: |
| - with open(options.json_output, 'wb') as f: |
| + if args.json_output: |
| + with open(args.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)) |
| - device_blacklist.ExtendBlacklist([str(device)]) |
| + blacklist.Extend([str(device)]) |
| num_failed_devs += 1 |
| if num_failed_devs == len(devices): |