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

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: 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 47
48 class _PHASES(object): 48 class _PHASES(object):
49 WIPE = 'wipe' 49 WIPE = 'wipe'
50 PROPERTIES = 'properties' 50 PROPERTIES = 'properties'
51 FINISH = 'finish' 51 FINISH = 'finish'
52 52
53 ALL = [WIPE, PROPERTIES, FINISH] 53 ALL = [WIPE, PROPERTIES, FINISH]
54 54
55 55
56 def ProvisionDevices(options): 56 def ProvisionDevices(args):
57 devices = device_utils.DeviceUtils.HealthyDevices() 57 if args.blacklist_file:
58 if options.device: 58 blacklist = device_blacklist.Blacklist(args.blacklist_file)
59 devices = [d for d in devices if d == options.device] 59 else:
60 # TODO(jbudorick): Remove once the bots have switched over.
61 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON)
62
63 devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
64 if args.device:
65 devices = [d for d in devices if d == args.device]
60 if not devices: 66 if not devices:
61 raise device_errors.DeviceUnreachableError(options.device) 67 raise device_errors.DeviceUnreachableError(args.device)
62 68
63 parallel_devices = device_utils.DeviceUtils.parallel(devices) 69 parallel_devices = device_utils.DeviceUtils.parallel(devices)
64 parallel_devices.pMap(ProvisionDevice, options) 70 parallel_devices.pMap(ProvisionDevice, blacklist, args)
65 if options.auto_reconnect: 71 if args.auto_reconnect:
66 _LaunchHostHeartbeat() 72 _LaunchHostHeartbeat()
67 blacklist = device_blacklist.ReadBlacklist() 73 blacklisted_devices = blacklist.Read()
68 if options.output_device_blacklist: 74 if args.output_device_blacklist:
69 with open(options.output_device_blacklist, 'w') as f: 75 with open(args.output_device_blacklist, 'w') as f:
70 json.dump(blacklist, f) 76 json.dump(blacklisted_devices, f)
71 if all(d in blacklist for d in devices): 77 if all(d in blacklisted_devices for d in devices):
72 raise device_errors.NoDevicesError 78 raise device_errors.NoDevicesError
73 return 0 79 return 0
74 80
75 81
76 def ProvisionDevice(device, options): 82 def ProvisionDevice(device, blacklist, options):
77 if options.reboot_timeout: 83 if options.reboot_timeout:
78 reboot_timeout = options.reboot_timeout 84 reboot_timeout = options.reboot_timeout
79 elif (device.build_version_sdk >= 85 elif (device.build_version_sdk >=
80 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 86 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
81 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP 87 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP
82 else: 88 else:
83 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP 89 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP
84 90
85 def should_run_phase(phase_name): 91 def should_run_phase(phase_name):
86 return not options.phases or phase_name in options.phases 92 return not options.phases or phase_name in options.phases
(...skipping 16 matching lines...) Expand all
103 if should_run_phase(_PHASES.PROPERTIES): 109 if should_run_phase(_PHASES.PROPERTIES):
104 run_phase(SetProperties) 110 run_phase(SetProperties)
105 111
106 if should_run_phase(_PHASES.FINISH): 112 if should_run_phase(_PHASES.FINISH):
107 run_phase(FinishProvisioning, reboot=False) 113 run_phase(FinishProvisioning, reboot=False)
108 114
109 except (errors.WaitForResponseTimedOutError, 115 except (errors.WaitForResponseTimedOutError,
110 device_errors.CommandTimeoutError): 116 device_errors.CommandTimeoutError):
111 logging.exception('Timed out waiting for device %s. Adding to blacklist.', 117 logging.exception('Timed out waiting for device %s. Adding to blacklist.',
112 str(device)) 118 str(device))
113 device_blacklist.ExtendBlacklist([str(device)]) 119 blacklist.Extend([str(device)])
114 120
115 except device_errors.CommandFailedError: 121 except device_errors.CommandFailedError:
116 logging.exception('Failed to provision device %s. Adding to blacklist.', 122 logging.exception('Failed to provision device %s. Adding to blacklist.',
117 str(device)) 123 str(device))
118 device_blacklist.ExtendBlacklist([str(device)]) 124 blacklist.Extend([str(device)])
119 125
120 126
121 def WipeDevice(device, options): 127 def WipeDevice(device, options):
122 """Wipes data from device, keeping only the adb_keys for authorization. 128 """Wipes data from device, keeping only the adb_keys for authorization.
123 129
124 After wiping data on a device that has been authorized, adb can still 130 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 131 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/. 132 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 133 Thus, adb_keys file is rewritten so the device does not need to be
128 re-authorized. 134 re-authorized.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 # --min-battery-level 95 316 # --min-battery-level 95
311 # Some perf bots run benchmarks with USB charging disabled which leads 317 # 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 318 # 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. 319 # before starting a run in order to keep the devices online.
314 320
315 parser = argparse.ArgumentParser( 321 parser = argparse.ArgumentParser(
316 description='Provision Android devices with settings required for bots.') 322 description='Provision Android devices with settings required for bots.')
317 parser.add_argument('-d', '--device', metavar='SERIAL', 323 parser.add_argument('-d', '--device', metavar='SERIAL',
318 help='the serial number of the device to be provisioned' 324 help='the serial number of the device to be provisioned'
319 ' (the default is to provision all devices attached)') 325 ' (the default is to provision all devices attached)')
326 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
320 parser.add_argument('--phase', action='append', choices=_PHASES.ALL, 327 parser.add_argument('--phase', action='append', choices=_PHASES.ALL,
321 dest='phases', 328 dest='phases',
322 help='Phases of provisioning to run. ' 329 help='Phases of provisioning to run. '
323 '(If omitted, all phases will be run.)') 330 '(If omitted, all phases will be run.)')
324 parser.add_argument('--skip-wipe', action='store_true', default=False, 331 parser.add_argument('--skip-wipe', action='store_true', default=False,
325 help="don't wipe device data during provisioning") 332 help="don't wipe device data during provisioning")
326 parser.add_argument('--reboot-timeout', metavar='SECS', type=int, 333 parser.add_argument('--reboot-timeout', metavar='SECS', type=int,
327 help='when wiping the device, max number of seconds to' 334 help='when wiping the device, max number of seconds to'
328 ' wait after each reboot ' 335 ' wait after each reboot '
329 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT) 336 '(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT)
(...skipping 27 matching lines...) Expand all
357 args = parser.parse_args() 364 args = parser.parse_args()
358 constants.SetBuildType(args.target) 365 constants.SetBuildType(args.target)
359 366
360 run_tests_helper.SetLogLevel(args.verbose) 367 run_tests_helper.SetLogLevel(args.verbose)
361 368
362 return ProvisionDevices(args) 369 return ProvisionDevices(args)
363 370
364 371
365 if __name__ == '__main__': 372 if __name__ == '__main__':
366 sys.exit(main()) 373 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698