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

Unified Diff: build/android/buildbot/bb_device_status_check.py

Issue 26747004: Add option to restart usb on device status check before performing check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make failed restart_usb.py fail on error. Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/buildbot/bb_device_status_check.py
diff --git a/build/android/buildbot/bb_device_status_check.py b/build/android/buildbot/bb_device_status_check.py
index a5ef54b34ce8c9a435c6fbb7d31569e38c64a2d7..9647ea6bdba3d5d1e74404fd4e8f2463f92b5137 100755
--- a/build/android/buildbot/bb_device_status_check.py
+++ b/build/android/buildbot/bb_device_status_check.py
@@ -9,11 +9,13 @@ import logging
import optparse
import os
import smtplib
+import subprocess
import sys
import re
import urllib
import bb_annotations
+import bb_utils
sys.path.append(os.path.join(os.path.dirname(__file__),
os.pardir, os.pardir, 'util', 'lib',
@@ -203,6 +205,43 @@ def SendDeviceStatusAlert(msg):
print 'Failed to send alert email. Error: %s' % e
+def RestartUsb():
+ if not os.path.isfile('/usr/bin/restart_usb'):
+ print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed '
+ 'on host (see BUG=305769).')
+ return 1
+
+ lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
+ lsusb_output, _ = lsusb_proc.communicate()
+ if lsusb_proc.returncode:
+ print ('Error: Could not get list of USB ports (i.e. lsusb).')
+ return lsusb_proc.returncode
+
+ usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
+ for lsusb_line in lsusb_output.strip().split('\n')]
+
+ failed_restart = False
+ # Walk USB devices from leaves up (i.e reverse sorted) restarting the
+ # connection. If a parent node (e.g. usb hub) is restarted before the
+ # devices connected to it, the (bus, dev) for the hub can change, making the
+ # output we have wrong. This way we restart the devices before the hub.
+ for (bus, dev) in reversed(sorted(usb_devices)):
+ # Can not restart root usb connections
+ if dev != '001':
+ return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev],
+ flunk_on_failure=True)
Isaac (away) 2013/10/17 07:27:55 this is the default, line not needed.
+ if return_code:
+ print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev)
+ failed_restart = True
+ else:
+ print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
+
+ if failed_restart:
+ return 1
+
+ return 0
+
+
def main():
parser = optparse.OptionParser()
parser.add_option('', '--out-dir',
@@ -212,9 +251,17 @@ def main():
help='Will not check if devices are provisioned properly.')
parser.add_option('--device-status-dashboard', action='store_true',
help='Output device status data for dashboard.')
+ parser.add_option('--restart-usb', action='store_true',
+ help='Restart USB ports before running device check.')
options, args = parser.parse_args()
if args:
parser.error('Unknown options %s' % args)
+
+ if options.restart_usb:
+ rc = RestartUsb()
+ if rc:
+ return 1
+
devices = android_commands.GetAttachedDevices()
# TODO(navabi): Test to make sure this fails and then fix call
offline_devices = android_commands.GetAttachedDevices(hardware=False,
« no previous file with comments | « no previous file | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698