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

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: Add restart-usb option for bots to pass to device status check. 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..f402ea66dcf4e4575d78a767adcaf387e1e51667 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,36 @@ def SendDeviceStatusAlert(msg):
print 'Failed to send alert email. Error: %s' % e
+def RestartUsb():
Isaac (away) 2013/10/11 18:10:08 I'd rather this return error than warning. This c
navabi 2013/10/11 18:39:02 I disagree. The failure of restart_usb.py should n
Isaac (away) 2013/10/11 19:04:10 If you're not failing here, what's your plan to en
navabi 2013/10/11 22:03:28 The plan is to add error (or email notification) o
navabi 2013/10/11 22:03:28 bb_device_status_check does not run in testing mod
+ if not os.path.isfile('/usr/bin/restart_usb'):
+ print ('WARNING: Could not restart usb. /usr/bin/restart_usb not installed '
+ 'on host (see BUG=305769).')
+ return
+
+ lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
+ lsusb_output, _ = lsusb_proc.communicate()
+ if lsusb_proc.returncode:
Isaac (away) 2013/10/11 18:10:08 Please return error.
navabi 2013/10/11 22:03:28 Done.
+ print ('WARNING: Could not restart usb. Error getting list of USB ports.')
+ return
+
+ usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
+ for lsusb_line in lsusb_output.strip().split('\n')]
+
+ # 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)):
Isaac (away) 2013/10/11 18:10:08 Is this possible to restrict to only android devic
navabi 2013/10/11 18:39:02 It is, but I don't think that's what we want. I th
Isaac (away) 2013/10/11 19:04:10 I'd be surprised if a USB hub needed to be reset.
navabi 2013/10/11 22:03:28 The script has always restarted all usb ports (inc
+ # Can not restart root usb connections
+ if dev != '001':
+ return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev],
+ flunk_on_failure=False)
Isaac (away) 2013/10/11 18:10:08 flunk on failure.
navabi 2013/10/11 18:39:02 See first comment. I don't think this should flunk
Isaac (away) 2013/10/11 19:04:10 Do you expect this binary to occasionally fail?
navabi 2013/10/11 22:03:28 Let's land it and see. We don't know yet as curren
+ if return_code:
+ print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev)
+ else:
+ print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev)
+
+
def main():
parser = optparse.OptionParser()
parser.add_option('', '--out-dir',
@@ -212,9 +244,15 @@ 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:
+ RestartUsb()
+
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