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

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

Issue 1304303006: [Android] Don't use a device blacklist if one isn't provided. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add blacklist to host_info and the old buildbot scripts Created 5 years, 3 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/adb_reverse_forwarder.py ('k') | build/android/buildbot/bb_device_steps.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 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 except (psutil.NoSuchProcess, psutil.AccessDenied): 48 except (psutil.NoSuchProcess, psutil.AccessDenied):
49 pass 49 pass
50 for p in GetAllAdb(): 50 for p in GetAllAdb():
51 try: 51 try:
52 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name, 52 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name,
53 ' '.join(p.cmdline)) 53 ' '.join(p.cmdline))
54 except (psutil.NoSuchProcess, psutil.AccessDenied): 54 except (psutil.NoSuchProcess, psutil.AccessDenied):
55 pass 55 pass
56 56
57 57
58 def _IsBlacklisted(serial, blacklist):
59 return blacklist and serial in blacklist.Read()
60
61
58 def _BatteryStatus(device, blacklist): 62 def _BatteryStatus(device, blacklist):
59 battery_info = {} 63 battery_info = {}
60 try: 64 try:
61 battery = battery_utils.BatteryUtils(device) 65 battery = battery_utils.BatteryUtils(device)
62 battery_info = battery.GetBatteryInfo(timeout=5) 66 battery_info = battery.GetBatteryInfo(timeout=5)
63 battery_level = int(battery_info.get('level', 100)) 67 battery_level = int(battery_info.get('level', 100))
64 68
65 if battery_level < 15: 69 if battery_level < 15:
66 logging.error('Critically low battery level (%d)', battery_level) 70 logging.error('Critically low battery level (%d)', battery_level)
67 battery = battery_utils.BatteryUtils(device) 71 battery = battery_utils.BatteryUtils(device)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 else 'unknown') 135 else 'unknown')
132 usb_status = bool(serial in usb_devices) 136 usb_status = bool(serial in usb_devices)
133 137
134 device_status = { 138 device_status = {
135 'serial': serial, 139 'serial': serial,
136 'adb_status': adb_status, 140 'adb_status': adb_status,
137 'usb_status': usb_status, 141 'usb_status': usb_status,
138 } 142 }
139 143
140 if adb_status == 'device': 144 if adb_status == 'device':
141 if not serial in blacklist.Read(): 145 if not _IsBlacklisted(serial, blacklist):
142 try: 146 try:
143 build_product = device.build_product 147 build_product = device.build_product
144 build_id = device.build_id 148 build_id = device.build_id
145 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) 149 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True)
146 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') 150 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress')
147 battery_info = _BatteryStatus(device, blacklist) 151 battery_info = _BatteryStatus(device, blacklist)
148 imei_slice = _IMEISlice(device) 152 imei_slice = _IMEISlice(device)
149 153
150 if (device.product_name == 'mantaray' and 154 if (device.product_name == 'mantaray' and
151 battery_info.get('AC powered', None) != 'true'): 155 battery_info.get('AC powered', None) != 'true'):
(...skipping 21 matching lines...) Expand all
173 177
174 except device_errors.CommandTimeoutError: 178 except device_errors.CommandTimeoutError:
175 logging.exception('Timeout while getting device status for %s.', 179 logging.exception('Timeout while getting device status for %s.',
176 str(device)) 180 str(device))
177 if blacklist: 181 if blacklist:
178 blacklist.Extend([serial]) 182 blacklist.Extend([serial])
179 183
180 elif blacklist: 184 elif blacklist:
181 blacklist.Extend([serial]) 185 blacklist.Extend([serial])
182 186
183 device_status['blacklisted'] = serial in blacklist.Read() 187 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist)
184 188
185 return device_status 189 return device_status
186 190
187 parallel_devices = device_utils.DeviceUtils.parallel(devices) 191 parallel_devices = device_utils.DeviceUtils.parallel(devices)
188 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) 192 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None)
189 return statuses 193 return statuses
190 194
191 195
192 def RecoverDevices(devices, blacklist): 196 def RecoverDevices(devices, blacklist):
193 """Attempts to recover any inoperable devices in the provided list. 197 """Attempts to recover any inoperable devices in the provided list.
(...skipping 22 matching lines...) Expand all
216 logging.debug('Should restart USB for:') 220 logging.debug('Should restart USB for:')
217 for d in should_restart_usb: 221 for d in should_restart_usb:
218 logging.debug(' %s', d) 222 logging.debug(' %s', d)
219 logging.debug('Should restart ADB for:') 223 logging.debug('Should restart ADB for:')
220 for d in should_restart_adb: 224 for d in should_restart_adb:
221 logging.debug(' %s', d) 225 logging.debug(' %s', d)
222 logging.debug('Should reboot:') 226 logging.debug('Should reboot:')
223 for d in should_reboot_device: 227 for d in should_reboot_device:
224 logging.debug(' %s', d) 228 logging.debug(' %s', d)
225 229
226 blacklist.Reset() 230 if blacklist:
231 blacklist.Reset()
227 232
228 if should_restart_adb: 233 if should_restart_adb:
229 KillAllAdb() 234 KillAllAdb()
230 for serial in should_restart_usb: 235 for serial in should_restart_usb:
231 try: 236 try:
232 reset_usb.reset_android_usb(serial) 237 reset_usb.reset_android_usb(serial)
233 except (IOError, device_errors.DeviceUnreachableError): 238 except (IOError, device_errors.DeviceUnreachableError):
234 logging.exception('Unable to reset USB for %s.', serial) 239 logging.exception('Unable to reset USB for %s.', serial)
235 if blacklist: 240 if blacklist:
236 blacklist.Extend([serial]) 241 blacklist.Extend([serial])
237 242
238 def blacklisting_recovery(device): 243 def blacklisting_recovery(device):
239 if blacklist and device.adb.GetDeviceSerial() in blacklist.Read(): 244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist):
240 logging.debug('%s is blacklisted, skipping recovery.', str(device)) 245 logging.debug('%s is blacklisted, skipping recovery.', str(device))
241 return 246 return
242 247
243 if device in should_reboot_device: 248 if device in should_reboot_device:
244 try: 249 try:
245 device.WaitUntilFullyBooted() 250 device.WaitUntilFullyBooted()
246 return 251 return
247 except (device_errors.CommandTimeoutError, 252 except (device_errors.CommandTimeoutError,
248 device_errors.CommandFailedError): 253 device_errors.CommandFailedError):
249 logging.exception('Failure while waiting for %s. ' 254 logging.exception('Failure while waiting for %s. '
(...skipping 25 matching lines...) Expand all
275 parser.add_argument('--json-output', 280 parser.add_argument('--json-output',
276 help='Output JSON information into a specified file.') 281 help='Output JSON information into a specified file.')
277 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') 282 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
278 parser.add_argument('-v', '--verbose', action='count', default=1, 283 parser.add_argument('-v', '--verbose', action='count', default=1,
279 help='Log more information.') 284 help='Log more information.')
280 285
281 args = parser.parse_args() 286 args = parser.parse_args()
282 287
283 run_tests_helper.SetLogLevel(args.verbose) 288 run_tests_helper.SetLogLevel(args.verbose)
284 289
285 if args.blacklist_file: 290 blacklist = (device_blacklist.Blacklist(args.blacklist_file)
286 blacklist = device_blacklist.Blacklist(args.blacklist_file) 291 if args.blacklist_file
287 else: 292 else None)
288 # TODO(jbudorick): Remove this once bots pass the blacklist file.
289 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON)
290 293
291 last_devices_path = os.path.join( 294 last_devices_path = os.path.join(
292 args.out_dir, device_list.LAST_DEVICES_FILENAME) 295 args.out_dir, device_list.LAST_DEVICES_FILENAME)
293 try: 296 try:
294 expected_devices = set( 297 expected_devices = set(
295 device_list.GetPersistentDeviceList(last_devices_path)) 298 device_list.GetPersistentDeviceList(last_devices_path))
296 except IOError: 299 except IOError:
297 expected_devices = set() 300 expected_devices = set()
298 301
299 usb_devices = set(lsusb.get_android_devices()) 302 usb_devices = set(lsusb.get_android_devices())
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 except Exception: # pylint: disable=broad-except 354 except Exception: # pylint: disable=broad-except
352 pass 355 pass
353 356
354 # Dump the device statuses to JSON. 357 # Dump the device statuses to JSON.
355 if args.json_output: 358 if args.json_output:
356 with open(args.json_output, 'wb') as f: 359 with open(args.json_output, 'wb') as f:
357 f.write(json.dumps(statuses, indent=4)) 360 f.write(json.dumps(statuses, indent=4))
358 361
359 live_devices = [status['serial'] for status in statuses 362 live_devices = [status['serial'] for status in statuses
360 if (status['adb_status'] == 'device' 363 if (status['adb_status'] == 'device'
361 and status['serial'] not in blacklist.Read())] 364 and not _IsBlacklisted(status['serial'], blacklist))]
362 365
363 # If all devices failed, or if there are no devices, it's an infra error. 366 # If all devices failed, or if there are no devices, it's an infra error.
364 return 0 if live_devices else constants.INFRA_EXIT_CODE 367 return 0 if live_devices else constants.INFRA_EXIT_CODE
365 368
366 369
367 if __name__ == '__main__': 370 if __name__ == '__main__':
368 sys.exit(main()) 371 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/adb_reverse_forwarder.py ('k') | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698