| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Provisions Android devices with settings required for bots. | 7 """Provisions Android devices with settings required for bots. |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 ./provision_devices.py [-d <device serial number>] | 10 ./provision_devices.py [-d <device serial number>] |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 | 42 |
| 43 class _PHASES(object): | 43 class _PHASES(object): |
| 44 WIPE = 'wipe' | 44 WIPE = 'wipe' |
| 45 PROPERTIES = 'properties' | 45 PROPERTIES = 'properties' |
| 46 FINISH = 'finish' | 46 FINISH = 'finish' |
| 47 | 47 |
| 48 ALL = [WIPE, PROPERTIES, FINISH] | 48 ALL = [WIPE, PROPERTIES, FINISH] |
| 49 | 49 |
| 50 | 50 |
| 51 def ProvisionDevices(args): | 51 def ProvisionDevices(options): |
| 52 if args.blacklist_file: | 52 devices = device_utils.DeviceUtils.HealthyDevices() |
| 53 blacklist = device_blacklist.Blacklist(args.blacklist_file) | 53 if options.device: |
| 54 else: | 54 devices = [d for d in devices if d == options.device] |
| 55 # TODO(jbudorick): Remove once the bots have switched over. | |
| 56 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) | |
| 57 | |
| 58 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) | |
| 59 if args.device: | |
| 60 devices = [d for d in devices if d == args.device] | |
| 61 if not devices: | 55 if not devices: |
| 62 raise device_errors.DeviceUnreachableError(args.device) | 56 raise device_errors.DeviceUnreachableError(options.device) |
| 63 | 57 |
| 64 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 58 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
| 65 parallel_devices.pMap(ProvisionDevice, blacklist, args) | 59 parallel_devices.pMap(ProvisionDevice, options) |
| 66 if args.auto_reconnect: | 60 if options.auto_reconnect: |
| 67 _LaunchHostHeartbeat() | 61 _LaunchHostHeartbeat() |
| 68 blacklisted_devices = blacklist.Read() | 62 blacklist = device_blacklist.ReadBlacklist() |
| 69 if args.output_device_blacklist: | 63 if options.output_device_blacklist: |
| 70 with open(args.output_device_blacklist, 'w') as f: | 64 with open(options.output_device_blacklist, 'w') as f: |
| 71 json.dump(blacklisted_devices, f) | 65 json.dump(blacklist, f) |
| 72 if all(d in blacklisted_devices for d in devices): | 66 if all(d in blacklist for d in devices): |
| 73 raise device_errors.NoDevicesError | 67 raise device_errors.NoDevicesError |
| 74 return 0 | 68 return 0 |
| 75 | 69 |
| 76 | 70 |
| 77 def ProvisionDevice(device, blacklist, options): | 71 def ProvisionDevice(device, options): |
| 78 if options.reboot_timeout: | 72 if options.reboot_timeout: |
| 79 reboot_timeout = options.reboot_timeout | 73 reboot_timeout = options.reboot_timeout |
| 80 elif (device.build_version_sdk >= | 74 elif (device.build_version_sdk >= |
| 81 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): | 75 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): |
| 82 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP | 76 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP |
| 83 else: | 77 else: |
| 84 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP | 78 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP |
| 85 | 79 |
| 86 def should_run_phase(phase_name): | 80 def should_run_phase(phase_name): |
| 87 return not options.phases or phase_name in options.phases | 81 return not options.phases or phase_name in options.phases |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 | 97 |
| 104 if should_run_phase(_PHASES.PROPERTIES): | 98 if should_run_phase(_PHASES.PROPERTIES): |
| 105 run_phase(SetProperties) | 99 run_phase(SetProperties) |
| 106 | 100 |
| 107 if should_run_phase(_PHASES.FINISH): | 101 if should_run_phase(_PHASES.FINISH): |
| 108 run_phase(FinishProvisioning, reboot=False) | 102 run_phase(FinishProvisioning, reboot=False) |
| 109 | 103 |
| 110 except device_errors.CommandTimeoutError: | 104 except device_errors.CommandTimeoutError: |
| 111 logging.exception('Timed out waiting for device %s. Adding to blacklist.', | 105 logging.exception('Timed out waiting for device %s. Adding to blacklist.', |
| 112 str(device)) | 106 str(device)) |
| 113 blacklist.Extend([str(device)]) | 107 device_blacklist.ExtendBlacklist([str(device)]) |
| 114 | 108 |
| 115 except device_errors.CommandFailedError: | 109 except device_errors.CommandFailedError: |
| 116 logging.exception('Failed to provision device %s. Adding to blacklist.', | 110 logging.exception('Failed to provision device %s. Adding to blacklist.', |
| 117 str(device)) | 111 str(device)) |
| 118 blacklist.Extend([str(device)]) | 112 device_blacklist.ExtendBlacklist([str(device)]) |
| 119 | 113 |
| 120 | 114 |
| 121 def WipeDevice(device, options): | 115 def WipeDevice(device, options): |
| 122 """Wipes data from device, keeping only the adb_keys for authorization. | 116 """Wipes data from device, keeping only the adb_keys for authorization. |
| 123 | 117 |
| 124 After wiping data on a device that has been authorized, adb can still | 118 After wiping data on a device that has been authorized, adb can still |
| 125 communicate with the device, but after reboot the device will need to be | 119 communicate with the device, but after reboot the device will need to be |
| 126 re-authorized because the adb keys file is stored in /data/misc/adb/. | 120 re-authorized because the adb keys file is stored in /data/misc/adb/. |
| 127 Thus, adb_keys file is rewritten so the device does not need to be | 121 Thus, adb_keys file is rewritten so the device does not need to be |
| 128 re-authorized. | 122 re-authorized. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 # --min-battery-level 95 | 304 # --min-battery-level 95 |
| 311 # Some perf bots run benchmarks with USB charging disabled which leads | 305 # Some perf bots run benchmarks with USB charging disabled which leads |
| 312 # to gradual draining of the battery. We must wait for a full charge | 306 # to gradual draining of the battery. We must wait for a full charge |
| 313 # before starting a run in order to keep the devices online. | 307 # before starting a run in order to keep the devices online. |
| 314 | 308 |
| 315 parser = argparse.ArgumentParser( | 309 parser = argparse.ArgumentParser( |
| 316 description='Provision Android devices with settings required for bots.') | 310 description='Provision Android devices with settings required for bots.') |
| 317 parser.add_argument('-d', '--device', metavar='SERIAL', | 311 parser.add_argument('-d', '--device', metavar='SERIAL', |
| 318 help='the serial number of the device to be provisioned' | 312 help='the serial number of the device to be provisioned' |
| 319 ' (the default is to provision all devices attached)') | 313 ' (the default is to provision all devices attached)') |
| 320 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') | |
| 321 parser.add_argument('--phase', action='append', choices=_PHASES.ALL, | 314 parser.add_argument('--phase', action='append', choices=_PHASES.ALL, |
| 322 dest='phases', | 315 dest='phases', |
| 323 help='Phases of provisioning to run. ' | 316 help='Phases of provisioning to run. ' |
| 324 '(If omitted, all phases will be run.)') | 317 '(If omitted, all phases will be run.)') |
| 325 parser.add_argument('--skip-wipe', action='store_true', default=False, | 318 parser.add_argument('--skip-wipe', action='store_true', default=False, |
| 326 help="don't wipe device data during provisioning") | 319 help="don't wipe device data during provisioning") |
| 327 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, | 320 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, |
| 328 help='when wiping the device, max number of seconds to' | 321 help='when wiping the device, max number of seconds to' |
| 329 ' wait after each reboot ' | 322 ' wait after each reboot ' |
| 330 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) | 323 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 358 args = parser.parse_args() | 351 args = parser.parse_args() |
| 359 constants.SetBuildType(args.target) | 352 constants.SetBuildType(args.target) |
| 360 | 353 |
| 361 run_tests_helper.SetLogLevel(args.verbose) | 354 run_tests_helper.SetLogLevel(args.verbose) |
| 362 | 355 |
| 363 return ProvisionDevices(args) | 356 return ProvisionDevices(args) |
| 364 | 357 |
| 365 | 358 |
| 366 if __name__ == '__main__': | 359 if __name__ == '__main__': |
| 367 sys.exit(main()) | 360 sys.exit(main()) |
| OLD | NEW |