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

Side by Side Diff: build/android/buildbot/bb_device_status_check.py

Issue 1768423002: Make the status reporting of devices in status_check more verbose. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up if block Created 4 years, 9 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 | « 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 2013 The Chromium Authors. All rights reserved. 3 # Copyright 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 """A class to keep track of devices across builds and report state.""" 7 """A class to keep track of devices across builds and report state."""
8 8
9 import argparse 9 import argparse
10 import json 10 import json
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 adb_devices = { 128 adb_devices = {
129 a[0].GetDeviceSerial(): a 129 a[0].GetDeviceSerial(): a
130 for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True) 130 for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True)
131 } 131 }
132 usb_devices = set(lsusb.get_android_devices()) 132 usb_devices = set(lsusb.get_android_devices())
133 133
134 def blacklisting_device_status(device): 134 def blacklisting_device_status(device):
135 serial = device.adb.GetDeviceSerial() 135 serial = device.adb.GetDeviceSerial()
136 adb_status = ( 136 adb_status = (
137 adb_devices[serial][1] if serial in adb_devices 137 adb_devices[serial][1] if serial in adb_devices
138 else 'unknown') 138 else 'missing')
139 usb_status = bool(serial in usb_devices) 139 usb_status = bool(serial in usb_devices)
140 140
141 device_status = { 141 device_status = {
142 'serial': serial, 142 'serial': serial,
143 'adb_status': adb_status, 143 'adb_status': adb_status,
144 'usb_status': usb_status, 144 'usb_status': usb_status,
145 } 145 }
146 146
147 if adb_status == 'device': 147 if not _IsBlacklisted(serial, blacklist):
148 if not _IsBlacklisted(serial, blacklist): 148 if adb_status == 'device':
149 try: 149 try:
150 build_product = device.build_product 150 build_product = device.build_product
151 build_id = device.build_id 151 build_id = device.build_id
152 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) 152 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True)
153 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') 153 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress')
154 battery_info = _BatteryStatus(device, blacklist) 154 battery_info = _BatteryStatus(device, blacklist)
155 imei_slice = _IMEISlice(device) 155 imei_slice = _IMEISlice(device)
156 156
157 if (device.product_name == 'mantaray' and 157 if (device.product_name == 'mantaray' and
158 battery_info.get('AC powered', None) != 'true'): 158 battery_info.get('AC powered', None) != 'true'):
(...skipping 18 matching lines...) Expand all
177 str(device)) 177 str(device))
178 if blacklist: 178 if blacklist:
179 blacklist.Extend([serial], reason='status_check_failure') 179 blacklist.Extend([serial], reason='status_check_failure')
180 180
181 except device_errors.CommandTimeoutError: 181 except device_errors.CommandTimeoutError:
182 logging.exception('Timeout while getting device status for %s.', 182 logging.exception('Timeout while getting device status for %s.',
183 str(device)) 183 str(device))
184 if blacklist: 184 if blacklist:
185 blacklist.Extend([serial], reason='status_check_timeout') 185 blacklist.Extend([serial], reason='status_check_timeout')
186 186
187 elif blacklist: 187 else:
jbudorick 2016/03/08 23:13:27 er, this should stay elif blacklist s.t. it doesn'
bpastene 2016/03/08 23:36:31 Done.
188 blacklist.Extend([serial], reason=adb_status) 188 blacklist.Extend([serial],
189 reason=adb_status if usb_status else 'offline')
189 190
190 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist) 191 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist)
191 192
192 return device_status 193 return device_status
193 194
194 parallel_devices = device_utils.DeviceUtils.parallel(devices) 195 parallel_devices = device_utils.DeviceUtils.parallel(devices)
195 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) 196 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None)
196 return statuses 197 return statuses
197 198
198 199
199 def RecoverDevices(devices, blacklist): 200 def RecoverDevices(devices, blacklist):
200 """Attempts to recover any inoperable devices in the provided list. 201 """Attempts to recover any inoperable devices in the provided list.
201 202
202 Args: 203 Args:
203 devices: The list of devices to attempt to recover. 204 devices: The list of devices to attempt to recover.
204 blacklist: The current device blacklist, which will be used then 205 blacklist: The current device blacklist, which will be used then
205 reset. 206 reset.
206 Returns: 207 Returns:
207 Nothing. 208 Nothing.
208 """ 209 """
209 210
210 statuses = DeviceStatus(devices, blacklist) 211 statuses = DeviceStatus(devices, blacklist)
211 212
212 should_restart_usb = set( 213 should_restart_usb = set(
213 status['serial'] for status in statuses 214 status['serial'] for status in statuses
214 if (not status['usb_status'] 215 if (not status['usb_status']
215 or status['adb_status'] in ('offline', 'unknown'))) 216 or status['adb_status'] in ('offline', 'missing')))
216 should_restart_adb = should_restart_usb.union(set( 217 should_restart_adb = should_restart_usb.union(set(
217 status['serial'] for status in statuses 218 status['serial'] for status in statuses
218 if status['adb_status'] == 'unauthorized')) 219 if status['adb_status'] == 'unauthorized'))
219 should_reboot_device = should_restart_adb.union(set( 220 should_reboot_device = should_restart_adb.union(set(
220 status['serial'] for status in statuses 221 status['serial'] for status in statuses
221 if status['blacklisted'])) 222 if status['blacklisted']))
222 223
223 logging.debug('Should restart USB for:') 224 logging.debug('Should restart USB for:')
224 for d in should_restart_usb: 225 for d in should_restart_usb:
225 logging.debug(' %s', d) 226 logging.debug(' %s', d)
226 logging.debug('Should restart ADB for:') 227 logging.debug('Should restart ADB for:')
227 for d in should_restart_adb: 228 for d in should_restart_adb:
228 logging.debug(' %s', d) 229 logging.debug(' %s', d)
229 logging.debug('Should reboot:') 230 logging.debug('Should reboot:')
230 for d in should_reboot_device: 231 for d in should_reboot_device:
231 logging.debug(' %s', d) 232 logging.debug(' %s', d)
232 233
233 if blacklist: 234 if blacklist:
234 blacklist.Reset() 235 blacklist.Reset()
235 236
236 if should_restart_adb: 237 if should_restart_adb:
237 KillAllAdb() 238 KillAllAdb()
238 for serial in should_restart_usb: 239 for serial in should_restart_usb:
239 try: 240 try:
240 reset_usb.reset_android_usb(serial) 241 reset_usb.reset_android_usb(serial)
241 except (IOError, device_errors.DeviceUnreachableError): 242 except IOError:
242 logging.exception('Unable to reset USB for %s.', serial) 243 logging.exception('Unable to reset USB for %s.', serial)
243 if blacklist: 244 if blacklist:
244 blacklist.Extend([serial], reason='usb_failure') 245 blacklist.Extend([serial], reason='usb_failure')
246 except device_errors.DeviceUnreachableError:
247 logging.exception('Unable to reset USB for %s.', serial)
248 if blacklist:
249 blacklist.Extend([serial], reason='offline')
245 250
246 def blacklisting_recovery(device): 251 def blacklisting_recovery(device):
247 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): 252 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist):
248 logging.debug('%s is blacklisted, skipping recovery.', str(device)) 253 logging.debug('%s is blacklisted, skipping recovery.', str(device))
249 return 254 return
250 255
251 if str(device) in should_reboot_device: 256 if str(device) in should_reboot_device:
252 try: 257 try:
253 device.WaitUntilFullyBooted(retries=0) 258 device.WaitUntilFullyBooted(retries=0)
254 return 259 return
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if status['adb_status'] == 'device': 393 if status['adb_status'] == 'device':
389 f.write('{serial} {adb_status} {build_product} {build_id} ' 394 f.write('{serial} {adb_status} {build_product} {build_id} '
390 '{temperature:.1f}C {level}%\n'.format( 395 '{temperature:.1f}C {level}%\n'.format(
391 serial=status['serial'], 396 serial=status['serial'],
392 adb_status=status['adb_status'], 397 adb_status=status['adb_status'],
393 build_product=status['type'], 398 build_product=status['type'],
394 build_id=status['build'], 399 build_id=status['build'],
395 temperature=float(status['battery']['temperature']) / 10, 400 temperature=float(status['battery']['temperature']) / 10,
396 level=status['battery']['level'] 401 level=status['battery']['level']
397 )) 402 ))
398 else: 403 elif status.get('usb_status', False):
399 f.write('{serial} {adb_status}'.format( 404 f.write('{serial} {adb_status}\n'.format(
400 serial=status['serial'], 405 serial=status['serial'],
401 adb_status=status['adb_status'] 406 adb_status=status['adb_status']
402 )) 407 ))
408 else:
409 f.write('{serial} offline\n'.format(
410 serial=status['serial']
411 ))
403 except Exception: # pylint: disable=broad-except 412 except Exception: # pylint: disable=broad-except
404 pass 413 pass
405 414
406 # Dump the device statuses to JSON. 415 # Dump the device statuses to JSON.
407 if args.json_output: 416 if args.json_output:
408 with open(args.json_output, 'wb') as f: 417 with open(args.json_output, 'wb') as f:
409 f.write(json.dumps(statuses, indent=4)) 418 f.write(json.dumps(statuses, indent=4))
410 419
411 live_devices = [status['serial'] for status in statuses 420 live_devices = [status['serial'] for status in statuses
412 if (status['adb_status'] == 'device' 421 if (status['adb_status'] == 'device'
413 and not _IsBlacklisted(status['serial'], blacklist))] 422 and not _IsBlacklisted(status['serial'], blacklist))]
414 423
415 # If all devices failed, or if there are no devices, it's an infra error. 424 # If all devices failed, or if there are no devices, it's an infra error.
416 return 0 if live_devices else exit_codes.INFRA 425 return 0 if live_devices else exit_codes.INFRA
417 426
418 427
419 if __name__ == '__main__': 428 if __name__ == '__main__':
420 sys.exit(main()) 429 sys.exit(main())
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