Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: build/android/provision_devices.py

Issue 1281923003: [Android] Add --blacklist-file as a command-line option. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix telemetry_unittests Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/host_heartbeat.py ('k') | build/android/pylib/device/device_blacklist.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(options): 51 def ProvisionDevices(args):
52 devices = device_utils.DeviceUtils.HealthyDevices() 52 if args.blacklist_file:
53 if options.device: 53 blacklist = device_blacklist.Blacklist(args.blacklist_file)
54 devices = [d for d in devices if d == options.device] 54 else:
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]
55 if not devices: 61 if not devices:
56 raise device_errors.DeviceUnreachableError(options.device) 62 raise device_errors.DeviceUnreachableError(args.device)
57 63
58 parallel_devices = device_utils.DeviceUtils.parallel(devices) 64 parallel_devices = device_utils.DeviceUtils.parallel(devices)
59 parallel_devices.pMap(ProvisionDevice, options) 65 parallel_devices.pMap(ProvisionDevice, blacklist, args)
60 if options.auto_reconnect: 66 if args.auto_reconnect:
61 _LaunchHostHeartbeat() 67 _LaunchHostHeartbeat()
62 blacklist = device_blacklist.ReadBlacklist() 68 blacklisted_devices = blacklist.Read()
63 if options.output_device_blacklist: 69 if args.output_device_blacklist:
64 with open(options.output_device_blacklist, 'w') as f: 70 with open(args.output_device_blacklist, 'w') as f:
65 json.dump(blacklist, f) 71 json.dump(blacklisted_devices, f)
66 if all(d in blacklist for d in devices): 72 if all(d in blacklisted_devices for d in devices):
67 raise device_errors.NoDevicesError 73 raise device_errors.NoDevicesError
68 return 0 74 return 0
69 75
70 76
71 def ProvisionDevice(device, options): 77 def ProvisionDevice(device, blacklist, options):
72 if options.reboot_timeout: 78 if options.reboot_timeout:
73 reboot_timeout = options.reboot_timeout 79 reboot_timeout = options.reboot_timeout
74 elif (device.build_version_sdk >= 80 elif (device.build_version_sdk >=
75 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 81 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
76 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP 82 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP
77 else: 83 else:
78 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP 84 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP
79 85
80 def should_run_phase(phase_name): 86 def should_run_phase(phase_name):
81 return not options.phases or phase_name in options.phases 87 return not options.phases or phase_name in options.phases
(...skipping 15 matching lines...) Expand all
97 103
98 if should_run_phase(_PHASES.PROPERTIES): 104 if should_run_phase(_PHASES.PROPERTIES):
99 run_phase(SetProperties) 105 run_phase(SetProperties)
100 106
101 if should_run_phase(_PHASES.FINISH): 107 if should_run_phase(_PHASES.FINISH):
102 run_phase(FinishProvisioning, reboot=False) 108 run_phase(FinishProvisioning, reboot=False)
103 109
104 except device_errors.CommandTimeoutError: 110 except device_errors.CommandTimeoutError:
105 logging.exception('Timed out waiting for device %s. Adding to blacklist.', 111 logging.exception('Timed out waiting for device %s. Adding to blacklist.',
106 str(device)) 112 str(device))
107 device_blacklist.ExtendBlacklist([str(device)]) 113 blacklist.Extend([str(device)])
108 114
109 except device_errors.CommandFailedError: 115 except device_errors.CommandFailedError:
110 logging.exception('Failed to provision device %s. Adding to blacklist.', 116 logging.exception('Failed to provision device %s. Adding to blacklist.',
111 str(device)) 117 str(device))
112 device_blacklist.ExtendBlacklist([str(device)]) 118 blacklist.Extend([str(device)])
113 119
114 120
115 def WipeDevice(device, options): 121 def WipeDevice(device, options):
116 """Wipes data from device, keeping only the adb_keys for authorization. 122 """Wipes data from device, keeping only the adb_keys for authorization.
117 123
118 After wiping data on a device that has been authorized, adb can still 124 After wiping data on a device that has been authorized, adb can still
119 communicate with the device, but after reboot the device will need to be 125 communicate with the device, but after reboot the device will need to be
120 re-authorized because the adb keys file is stored in /data/misc/adb/. 126 re-authorized because the adb keys file is stored in /data/misc/adb/.
121 Thus, adb_keys file is rewritten so the device does not need to be 127 Thus, adb_keys file is rewritten so the device does not need to be
122 re-authorized. 128 re-authorized.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 # --min-battery-level 95 310 # --min-battery-level 95
305 # Some perf bots run benchmarks with USB charging disabled which leads 311 # Some perf bots run benchmarks with USB charging disabled which leads
306 # to gradual draining of the battery. We must wait for a full charge 312 # to gradual draining of the battery. We must wait for a full charge
307 # before starting a run in order to keep the devices online. 313 # before starting a run in order to keep the devices online.
308 314
309 parser = argparse.ArgumentParser( 315 parser = argparse.ArgumentParser(
310 description='Provision Android devices with settings required for bots.') 316 description='Provision Android devices with settings required for bots.')
311 parser.add_argument('-d', '--device', metavar='SERIAL', 317 parser.add_argument('-d', '--device', metavar='SERIAL',
312 help='the serial number of the device to be provisioned' 318 help='the serial number of the device to be provisioned'
313 ' (the default is to provision all devices attached)') 319 ' (the default is to provision all devices attached)')
320 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
314 parser.add_argument('--phase', action='append', choices=_PHASES.ALL, 321 parser.add_argument('--phase', action='append', choices=_PHASES.ALL,
315 dest='phases', 322 dest='phases',
316 help='Phases of provisioning to run. ' 323 help='Phases of provisioning to run. '
317 '(If omitted, all phases will be run.)') 324 '(If omitted, all phases will be run.)')
318 parser.add_argument('--skip-wipe', action='store_true', default=False, 325 parser.add_argument('--skip-wipe', action='store_true', default=False,
319 help="don't wipe device data during provisioning") 326 help="don't wipe device data during provisioning")
320 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, 327 parser.add_argument('--reboot-timeout', metavar='SECS', type=int,
321 help='when wiping the device, max number of seconds to' 328 help='when wiping the device, max number of seconds to'
322 ' wait after each reboot ' 329 ' wait after each reboot '
323 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) 330 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT)
(...skipping 27 matching lines...) Expand all
351 args = parser.parse_args() 358 args = parser.parse_args()
352 constants.SetBuildType(args.target) 359 constants.SetBuildType(args.target)
353 360
354 run_tests_helper.SetLogLevel(args.verbose) 361 run_tests_helper.SetLogLevel(args.verbose)
355 362
356 return ProvisionDevices(args) 363 return ProvisionDevices(args)
357 364
358 365
359 if __name__ == '__main__': 366 if __name__ == '__main__':
360 sys.exit(main()) 367 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/host_heartbeat.py ('k') | build/android/pylib/device/device_blacklist.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698