OLD | NEW |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 battery = battery_utils.BatteryUtils(device) | 65 battery = battery_utils.BatteryUtils(device) |
66 battery_info = battery.GetBatteryInfo(timeout=5) | 66 battery_info = battery.GetBatteryInfo(timeout=5) |
67 battery_level = int(battery_info.get('level', 100)) | 67 battery_level = int(battery_info.get('level', 100)) |
68 | 68 |
69 if battery_level < 15: | 69 if battery_level < 15: |
70 logging.error('Critically low battery level (%d)', battery_level) | 70 logging.error('Critically low battery level (%d)', battery_level) |
71 battery = battery_utils.BatteryUtils(device) | 71 battery = battery_utils.BatteryUtils(device) |
72 if not battery.GetCharging(): | 72 if not battery.GetCharging(): |
73 battery.SetCharging(True) | 73 battery.SetCharging(True) |
74 if blacklist: | 74 if blacklist: |
75 blacklist.Extend([device.adb.GetDeviceSerial()]) | 75 blacklist.Extend([device.adb.GetDeviceSerial()], reason='low_battery') |
76 | 76 |
77 except device_errors.CommandFailedError: | 77 except device_errors.CommandFailedError: |
78 logging.exception('Failed to get battery information for %s', | 78 logging.exception('Failed to get battery information for %s', |
79 str(device)) | 79 str(device)) |
80 | 80 |
81 return battery_info | 81 return battery_info |
82 | 82 |
83 | 83 |
84 def _IMEISlice(device): | 84 def _IMEISlice(device): |
85 imei_slice = '' | 85 imei_slice = '' |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 # TODO(jbudorick): Remove these once no clients depend on them. | 166 # TODO(jbudorick): Remove these once no clients depend on them. |
167 'type': build_product, | 167 'type': build_product, |
168 'build': build_id, | 168 'build': build_id, |
169 'build_detail': build_fingerprint, | 169 'build_detail': build_fingerprint, |
170 }) | 170 }) |
171 | 171 |
172 except device_errors.CommandFailedError: | 172 except device_errors.CommandFailedError: |
173 logging.exception('Failure while getting device status for %s.', | 173 logging.exception('Failure while getting device status for %s.', |
174 str(device)) | 174 str(device)) |
175 if blacklist: | 175 if blacklist: |
176 blacklist.Extend([serial]) | 176 blacklist.Extend([serial], reason='status_check_failure') |
177 | 177 |
178 except device_errors.CommandTimeoutError: | 178 except device_errors.CommandTimeoutError: |
179 logging.exception('Timeout while getting device status for %s.', | 179 logging.exception('Timeout while getting device status for %s.', |
180 str(device)) | 180 str(device)) |
181 if blacklist: | 181 if blacklist: |
182 blacklist.Extend([serial]) | 182 blacklist.Extend([serial], reason='status_check_timeout') |
183 | 183 |
184 elif blacklist: | 184 elif blacklist: |
185 blacklist.Extend([serial]) | 185 blacklist.Extend([serial], reason='offline') |
186 | 186 |
187 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist) | 187 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist) |
188 | 188 |
189 return device_status | 189 return device_status |
190 | 190 |
191 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 191 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
192 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) | 192 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) |
193 return statuses | 193 return statuses |
194 | 194 |
195 | 195 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 blacklist.Reset() | 231 blacklist.Reset() |
232 | 232 |
233 if should_restart_adb: | 233 if should_restart_adb: |
234 KillAllAdb() | 234 KillAllAdb() |
235 for serial in should_restart_usb: | 235 for serial in should_restart_usb: |
236 try: | 236 try: |
237 reset_usb.reset_android_usb(serial) | 237 reset_usb.reset_android_usb(serial) |
238 except (IOError, device_errors.DeviceUnreachableError): | 238 except (IOError, device_errors.DeviceUnreachableError): |
239 logging.exception('Unable to reset USB for %s.', serial) | 239 logging.exception('Unable to reset USB for %s.', serial) |
240 if blacklist: | 240 if blacklist: |
241 blacklist.Extend([serial]) | 241 blacklist.Extend([serial], reason='usb_failure') |
242 | 242 |
243 def blacklisting_recovery(device): | 243 def blacklisting_recovery(device): |
244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): | 244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): |
245 logging.debug('%s is blacklisted, skipping recovery.', str(device)) | 245 logging.debug('%s is blacklisted, skipping recovery.', str(device)) |
246 return | 246 return |
247 | 247 |
248 if str(device) in should_reboot_device: | 248 if str(device) in should_reboot_device: |
249 try: | 249 try: |
250 device.WaitUntilFullyBooted(retries=0) | 250 device.WaitUntilFullyBooted(retries=0) |
251 return | 251 return |
252 except (device_errors.CommandTimeoutError, | 252 except (device_errors.CommandTimeoutError, |
253 device_errors.CommandFailedError): | 253 device_errors.CommandFailedError): |
254 logging.exception('Failure while waiting for %s. ' | 254 logging.exception('Failure while waiting for %s. ' |
255 'Attempting to recover.', str(device)) | 255 'Attempting to recover.', str(device)) |
256 | 256 |
257 try: | 257 try: |
258 try: | 258 try: |
259 device.Reboot(block=False, timeout=5, retries=0) | 259 device.Reboot(block=False, timeout=5, retries=0) |
260 except device_errors.CommandTimeoutError: | 260 except device_errors.CommandTimeoutError: |
261 logging.warning('Timed out while attempting to reboot %s normally.' | 261 logging.warning('Timed out while attempting to reboot %s normally.' |
262 'Attempting alternative reboot.', str(device)) | 262 'Attempting alternative reboot.', str(device)) |
263 # The device drops offline before we can grab the exit code, so | 263 # The device drops offline before we can grab the exit code, so |
264 # we don't check for status. | 264 # we don't check for status. |
265 device.adb.Root() | 265 device.adb.Root() |
266 device.adb.Shell('echo b > /proc/sysrq-trigger', expect_status=None, | 266 device.adb.Shell('echo b > /proc/sysrq-trigger', expect_status=None, |
267 timeout=5, retries=0) | 267 timeout=5, retries=0) |
268 except device_errors.CommandFailedError: | 268 except device_errors.CommandFailedError: |
269 logging.exception('Failed to reboot %s.', str(device)) | 269 logging.exception('Failed to reboot %s.', str(device)) |
270 if blacklist: | 270 if blacklist: |
271 blacklist.Extend([device.adb.GetDeviceSerial()]) | 271 blacklist.Extend([device.adb.GetDeviceSerial()], |
| 272 reason='reboot_failure') |
272 except device_errors.CommandTimeoutError: | 273 except device_errors.CommandTimeoutError: |
273 logging.exception('Timed out while rebooting %s.', str(device)) | 274 logging.exception('Timed out while rebooting %s.', str(device)) |
274 if blacklist: | 275 if blacklist: |
275 blacklist.Extend([device.adb.GetDeviceSerial()]) | 276 blacklist.Extend([device.adb.GetDeviceSerial()], |
| 277 reason='reboot_timeout') |
276 | 278 |
277 try: | 279 try: |
278 device.WaitUntilFullyBooted(retries=0) | 280 device.WaitUntilFullyBooted(retries=0) |
279 except device_errors.CommandFailedError: | 281 except device_errors.CommandFailedError: |
280 logging.exception('Failure while waiting for %s.', str(device)) | 282 logging.exception('Failure while waiting for %s.', str(device)) |
281 if blacklist: | 283 if blacklist: |
282 blacklist.Extend([device.adb.GetDeviceSerial()]) | 284 blacklist.Extend([device.adb.GetDeviceSerial()], |
| 285 reason='reboot_failure') |
283 except device_errors.CommandTimeoutError: | 286 except device_errors.CommandTimeoutError: |
284 logging.exception('Timed out while waiting for %s.', str(device)) | 287 logging.exception('Timed out while waiting for %s.', str(device)) |
285 if blacklist: | 288 if blacklist: |
286 blacklist.Extend([device.adb.GetDeviceSerial()]) | 289 blacklist.Extend([device.adb.GetDeviceSerial()], |
| 290 reason='reboot_timeout') |
287 | 291 |
288 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) | 292 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) |
289 | 293 |
290 | 294 |
291 def main(): | 295 def main(): |
292 parser = argparse.ArgumentParser() | 296 parser = argparse.ArgumentParser() |
293 parser.add_argument('--out-dir', | 297 parser.add_argument('--out-dir', |
294 help='Directory where the device path is stored', | 298 help='Directory where the device path is stored', |
295 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) | 299 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) |
296 parser.add_argument('--restart-usb', action='store_true', | 300 parser.add_argument('--restart-usb', action='store_true', |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 live_devices = [status['serial'] for status in statuses | 385 live_devices = [status['serial'] for status in statuses |
382 if (status['adb_status'] == 'device' | 386 if (status['adb_status'] == 'device' |
383 and not _IsBlacklisted(status['serial'], blacklist))] | 387 and not _IsBlacklisted(status['serial'], blacklist))] |
384 | 388 |
385 # If all devices failed, or if there are no devices, it's an infra error. | 389 # If all devices failed, or if there are no devices, it's an infra error. |
386 return 0 if live_devices else constants.INFRA_EXIT_CODE | 390 return 0 if live_devices else constants.INFRA_EXIT_CODE |
387 | 391 |
388 | 392 |
389 if __name__ == '__main__': | 393 if __name__ == '__main__': |
390 sys.exit(main()) | 394 sys.exit(main()) |
OLD | NEW |