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

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

Issue 442173002: If device does not come back after provisioning, add to bad devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add check to see for no good devices after reboot. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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>]
11 """ 11 """
12 12
13 import logging 13 import logging
14 import optparse 14 import optparse
15 import os 15 import os
16 import re 16 import re
17 import subprocess 17 import subprocess
18 import sys 18 import sys
19 import time 19 import time
20 20
21 from pylib import android_commands 21 from pylib import android_commands
22 from pylib import constants 22 from pylib import constants
23 from pylib import device_settings 23 from pylib import device_settings
24 from pylib.device import device_blacklist
24 from pylib.device import device_errors 25 from pylib.device import device_errors
25 from pylib.device import device_utils 26 from pylib.device import device_utils
26 27
27 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 28 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT,
28 'third_party', 'android_testrunner')) 29 'third_party', 'android_testrunner'))
29 import errors 30 import errors
30 31
31 def KillHostHeartbeat(): 32 def KillHostHeartbeat():
32 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) 33 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
33 stdout, _ = ps.communicate() 34 stdout, _ = ps.communicate()
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 148
148 if devices_to_reboot: 149 if devices_to_reboot:
149 try: 150 try:
150 device_utils.DeviceUtils.parallel(devices_to_reboot).Reboot(True) 151 device_utils.DeviceUtils.parallel(devices_to_reboot).Reboot(True)
151 except errors.DeviceUnresponsiveError: 152 except errors.DeviceUnresponsiveError:
152 pass 153 pass
153 for device_serial in devices_to_reboot: 154 for device_serial in devices_to_reboot:
154 device.WaitUntilFullyBooted(timeout=90) 155 device.WaitUntilFullyBooted(timeout=90)
155 156
156 157
158 def ProvisionDevice(device_serial, is_perf, disable_location):
159 device = device_utils.DeviceUtils(device_serial)
160 device.old_interface.EnableAdbRoot()
161 _ConfigureLocalProperties(device, is_perf)
162 device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS
163 if disable_location:
164 device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING)
165 else:
166 device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING)
167 device_settings.ConfigureContentSettingsDict(device, device_settings_map)
168 device_settings.SetLockScreenSettings(device)
169 if is_perf:
170 # TODO(tonyg): We eventually want network on. However, currently radios
171 # can cause perfbots to drain faster than they charge.
172 device_settings.ConfigureContentSettingsDict(
173 device, device_settings.NETWORK_DISABLED_SETTINGS)
174 # Some perf bots run benchmarks with USB charging disabled which leads
175 # to gradual draining of the battery. We must wait for a full charge
176 # before starting a run in order to keep the devices online.
177 try:
178 battery_info = device.old_interface.GetBatteryInfo()
179 except Exception as e:
180 battery_info = {}
181 logging.error('Unable to obtain battery info for %s, %s',
182 device_serial, e)
183
184 while int(battery_info.get('level', 100)) < 95:
185 if not device.old_interface.IsDeviceCharging():
186 if device.old_interface.CanControlUsbCharging():
187 device.old_interface.EnableUsbCharging()
188 else:
189 logging.error('Device is not charging')
190 break
191 logging.info('Waiting for device to charge. Current level=%s',
192 battery_info.get('level', 0))
193 time.sleep(60)
194 battery_info = device.old_interface.GetBatteryInfo()
195 device.RunShellCommand('date -u %f' % time.time(), as_root=True)
196
197
157 def ProvisionDevices(options): 198 def ProvisionDevices(options):
158 is_perf = 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower() 199 is_perf = 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower()
159 # TODO(jbudorick): Parallelize provisioning of all attached devices after 200 # TODO(jbudorick): Parallelize provisioning of all attached devices after
160 # switching from AndroidCommands. 201 # switching from AndroidCommands.
161 if options.device is not None: 202 if options.device is not None:
162 devices = [options.device] 203 devices = [options.device]
163 else: 204 else:
164 devices = android_commands.GetAttachedDevices() 205 devices = android_commands.GetAttachedDevices()
165 206
166 # Wipe devices (unless --skip-wipe was specified) 207 # Wipe devices (unless --skip-wipe was specified)
167 if not options.skip_wipe: 208 if not options.skip_wipe:
168 WipeDevicesIfPossible(devices) 209 WipeDevicesIfPossible(devices)
169 210
211 bad_devices = []
170 # Provision devices 212 # Provision devices
171 for device_serial in devices: 213 for device_serial in devices:
172 device = device_utils.DeviceUtils(device_serial) 214 try:
173 device.old_interface.EnableAdbRoot() 215 ProvisionDevice(device_serial, is_perf, options.disable_location)
174 _ConfigureLocalProperties(device, is_perf) 216 except errors.WaitForResponseTimedOutError:
175 device_settings_map = device_settings.DETERMINISTIC_DEVICE_SETTINGS 217 logging.info('Timed out waiting for device %s. Adding to blacklist.',
176 if options.disable_location: 218 device_serial)
177 device_settings_map.update(device_settings.DISABLE_LOCATION_SETTING) 219 bad_devices.append(device_serial)
178 else: 220 # Device black list is reset by bb_device_status_check.py per build.
179 device_settings_map.update(device_settings.ENABLE_LOCATION_SETTING) 221 device_blacklist.ExtendBlacklist([device_serial])
180 device_settings.ConfigureContentSettingsDict(device, device_settings_map) 222 devices = [device for device in devices if device not in bad_devices]
181 device_settings.SetLockScreenSettings(device)
182 if is_perf:
183 # TODO(tonyg): We eventually want network on. However, currently radios
184 # can cause perfbots to drain faster than they charge.
185 device_settings.ConfigureContentSettingsDict(
186 device, device_settings.NETWORK_DISABLED_SETTINGS)
187 # Some perf bots run benchmarks with USB charging disabled which leads
188 # to gradual draining of the battery. We must wait for a full charge
189 # before starting a run in order to keep the devices online.
190 try:
191 battery_info = device.old_interface.GetBatteryInfo()
192 except Exception as e:
193 battery_info = {}
194 logging.error('Unable to obtain battery info for %s, %s',
195 device_serial, e)
196 223
197 while int(battery_info.get('level', 100)) < 95: 224 # If there are no good devices
198 if not device.old_interface.IsDeviceCharging(): 225 if not devices:
199 if device.old_interface.CanControlUsbCharging(): 226 raise device_errors.NoDevicesError
200 device.old_interface.EnableUsbCharging() 227
201 else:
202 logging.error('Device is not charging')
203 break
204 logging.info('Waiting for device to charge. Current level=%s',
205 battery_info.get('level', 0))
206 time.sleep(60)
207 battery_info = device.old_interface.GetBatteryInfo()
208 device.RunShellCommand('date -u %f' % time.time(), as_root=True)
209 try: 228 try:
210 device_utils.DeviceUtils.parallel(devices).Reboot(True) 229 device_utils.DeviceUtils.parallel(devices).Reboot(True)
211 except errors.DeviceUnresponsiveError: 230 except errors.DeviceUnresponsiveError:
212 pass 231 pass
232
233 bad_devices = []
213 for device_serial in devices: 234 for device_serial in devices:
214 device = device_utils.DeviceUtils(device_serial) 235 device = device_utils.DeviceUtils(device_serial)
215 device.WaitUntilFullyBooted(timeout=90) 236 try:
216 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') 237 device.WaitUntilFullyBooted(timeout=90)
217 for prop in props: 238 (_, prop) = device.old_interface.GetShellCommandStatusAndOutput('getprop')
218 print prop 239 for p in prop:
240 print p
241 except errors.WaitForResponseTimedOutError:
242 logging.info('Timed out waiting for device %s. Adding to blacklist.',
243 device_serial)
244 bad_devices.append(device_serial)
245 # Device black list is reset by bb_device_status_check.py per build.
246 device_blacklist.ExtendBlacklist([device_serial])
247 devices = [device for device in devices if device not in bad_devices]
248
249 # If there are no good devices
250 if not devices:
251 raise device_errors.NoDevicesError
252
219 if options.auto_reconnect: 253 if options.auto_reconnect:
220 PushAndLaunchAdbReboot(devices, options.target) 254 PushAndLaunchAdbReboot(devices, options.target)
221 255
222 256
223 def main(argv): 257 def main(argv):
224 logging.basicConfig(level=logging.INFO) 258 logging.basicConfig(level=logging.INFO)
225 259
226 parser = optparse.OptionParser() 260 parser = optparse.OptionParser()
227 parser.add_option('--skip-wipe', action='store_true', default=False, 261 parser.add_option('--skip-wipe', action='store_true', default=False,
228 help="Don't wipe device data during provisioning.") 262 help="Don't wipe device data during provisioning.")
(...skipping 10 matching lines...) Expand all
239 273
240 if args: 274 if args:
241 print >> sys.stderr, 'Unused args %s' % args 275 print >> sys.stderr, 'Unused args %s' % args
242 return 1 276 return 1
243 277
244 ProvisionDevices(options) 278 ProvisionDevices(options)
245 279
246 280
247 if __name__ == '__main__': 281 if __name__ == '__main__':
248 sys.exit(main(sys.argv)) 282 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698