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

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

Issue 128083002: Android: wait for at least one device if usb restart fails. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Variable name Created 6 years, 11 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 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 import logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 server.sendmail(from_address, [to_address], msg_body) 218 server.sendmail(from_address, [to_address], msg_body)
219 server.quit() 219 server.quit()
220 except Exception as e: 220 except Exception as e:
221 print 'Failed to send alert email. Error: %s' % e 221 print 'Failed to send alert email. Error: %s' % e
222 222
223 223
224 def RestartUsb(): 224 def RestartUsb():
225 if not os.path.isfile('/usr/bin/restart_usb'): 225 if not os.path.isfile('/usr/bin/restart_usb'):
226 print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed ' 226 print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed '
227 'on host (see BUG=305769).') 227 'on host (see BUG=305769).')
228 return 1 228 return False
229 229
230 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) 230 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
231 lsusb_output, _ = lsusb_proc.communicate() 231 lsusb_output, _ = lsusb_proc.communicate()
232 if lsusb_proc.returncode: 232 if lsusb_proc.returncode:
233 print ('Error: Could not get list of USB ports (i.e. lsusb).') 233 print ('Error: Could not get list of USB ports (i.e. lsusb).')
234 return lsusb_proc.returncode 234 return lsusb_proc.returncode
235 235
236 usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] 236 usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
237 for lsusb_line in lsusb_output.strip().split('\n')] 237 for lsusb_line in lsusb_output.strip().split('\n')]
238 238
239 failed_restart = False 239 all_restarted = True
240 # Walk USB devices from leaves up (i.e reverse sorted) restarting the 240 # Walk USB devices from leaves up (i.e reverse sorted) restarting the
241 # connection. If a parent node (e.g. usb hub) is restarted before the 241 # connection. If a parent node (e.g. usb hub) is restarted before the
242 # devices connected to it, the (bus, dev) for the hub can change, making the 242 # devices connected to it, the (bus, dev) for the hub can change, making the
243 # output we have wrong. This way we restart the devices before the hub. 243 # output we have wrong. This way we restart the devices before the hub.
244 for (bus, dev) in reversed(sorted(usb_devices)): 244 for (bus, dev) in reversed(sorted(usb_devices)):
245 # Can not restart root usb connections 245 # Can not restart root usb connections
246 if dev != '001': 246 if dev != '001':
247 return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev]) 247 return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev])
248 if return_code: 248 if return_code:
249 print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev) 249 print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev)
250 failed_restart = True 250 all_restarted = False
251 else: 251 else:
252 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) 252 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
253 253
254 if failed_restart: 254 return all_restarted
255 return 1
256
257 return 0
258 255
259 256
260 def KillAllAdb(): 257 def KillAllAdb():
261 def GetAllAdb(): 258 def GetAllAdb():
262 for p in psutil.process_iter(): 259 for p in psutil.process_iter():
263 try: 260 try:
264 if 'adb' in p.name: 261 if 'adb' in p.name:
265 yield p 262 yield p
266 except psutil.error.NoSuchProcess: 263 except psutil.error.NoSuchProcess:
267 pass 264 pass
(...skipping 24 matching lines...) Expand all
292 help='Output device status data for dashboard.') 289 help='Output device status data for dashboard.')
293 parser.add_option('--restart-usb', action='store_true', 290 parser.add_option('--restart-usb', action='store_true',
294 help='Restart USB ports before running device check.') 291 help='Restart USB ports before running device check.')
295 options, args = parser.parse_args() 292 options, args = parser.parse_args()
296 if args: 293 if args:
297 parser.error('Unknown options %s' % args) 294 parser.error('Unknown options %s' % args)
298 295
299 if options.restart_usb: 296 if options.restart_usb:
300 expected_devices = GetLastDevices(os.path.abspath(options.out_dir)) 297 expected_devices = GetLastDevices(os.path.abspath(options.out_dir))
301 devices = android_commands.GetAttachedDevices() 298 devices = android_commands.GetAttachedDevices()
302 # Only restart usb if devices are missing 299 # Only restart usb if devices are missing.
303 if set(expected_devices) != set(devices): 300 if set(expected_devices) != set(devices):
304 KillAllAdb() 301 KillAllAdb()
305 retries = 5 302 retries = 5
306 if RestartUsb(): 303 usb_restarted = True
304 if not RestartUsb():
305 usb_restarted = False
307 bb_annotations.PrintWarning() 306 bb_annotations.PrintWarning()
308 print "USB reset stage failed, continuing anyway." 307 print 'USB reset stage failed, wait for any device to come back.'
309 retries = 0
310 while retries: 308 while retries:
311 time.sleep(1) 309 time.sleep(1)
312 devices = android_commands.GetAttachedDevices() 310 devices = android_commands.GetAttachedDevices()
313 if set(expected_devices) == set(devices): 311 if set(expected_devices) == set(devices):
312 # All devices are online, keep going.
313 break
314 if not usb_restarted and devices:
315 # The USB wasn't restarted, but there's at least one device online.
316 # No point in trying to wait for all devices.
314 break 317 break
315 retries -= 1 318 retries -= 1
316 319
317 devices = android_commands.GetAttachedDevices() 320 devices = android_commands.GetAttachedDevices()
318 # TODO(navabi): Test to make sure this fails and then fix call 321 # TODO(navabi): Test to make sure this fails and then fix call
319 offline_devices = android_commands.GetAttachedDevices(hardware=False, 322 offline_devices = android_commands.GetAttachedDevices(hardware=False,
320 emulator=False, 323 emulator=False,
321 offline=True) 324 offline=True)
322 325
323 types, builds, batteries, reports, errors = [], [], [], [], [] 326 types, builds, batteries, reports, errors = [], [], [], [], []
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 # devices with critically low battery or install speed. Remove those devices 365 # devices with critically low battery or install speed. Remove those devices
363 # from testing, allowing build to continue with good devices. 366 # from testing, allowing build to continue with good devices.
364 return 1 367 return 1
365 368
366 if not devices: 369 if not devices:
367 return 1 370 return 1
368 371
369 372
370 if __name__ == '__main__': 373 if __name__ == '__main__':
371 sys.exit(main()) 374 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