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 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import smtplib | 11 import smtplib |
12 import subprocess | |
12 import sys | 13 import sys |
13 import re | 14 import re |
14 import urllib | 15 import urllib |
15 | 16 |
16 import bb_annotations | 17 import bb_annotations |
18 import bb_utils | |
17 | 19 |
18 sys.path.append(os.path.join(os.path.dirname(__file__), | 20 sys.path.append(os.path.join(os.path.dirname(__file__), |
19 os.pardir, os.pardir, 'util', 'lib', | 21 os.pardir, os.pardir, 'util', 'lib', |
20 'common')) | 22 'common')) |
21 import perf_tests_results_helper # pylint: disable=F0401 | 23 import perf_tests_results_helper # pylint: disable=F0401 |
22 | 24 |
23 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 25 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
24 from pylib import android_commands | 26 from pylib import android_commands |
25 from pylib import constants | 27 from pylib import constants |
26 from pylib.cmd_helper import GetCmdOutput | 28 from pylib.cmd_helper import GetCmdOutput |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 msg_body = '\r\n'.join(['From: %s' % from_address, 'To: %s' % to_address, | 198 msg_body = '\r\n'.join(['From: %s' % from_address, 'To: %s' % to_address, |
197 'Subject: %s' % subject, '', msg]) | 199 'Subject: %s' % subject, '', msg]) |
198 try: | 200 try: |
199 server = smtplib.SMTP('localhost') | 201 server = smtplib.SMTP('localhost') |
200 server.sendmail(from_address, [to_address], msg_body) | 202 server.sendmail(from_address, [to_address], msg_body) |
201 server.quit() | 203 server.quit() |
202 except Exception as e: | 204 except Exception as e: |
203 print 'Failed to send alert email. Error: %s' % e | 205 print 'Failed to send alert email. Error: %s' % e |
204 | 206 |
205 | 207 |
208 def RestartUsb(): | |
209 if not os.path.isfile('/usr/bin/restart_usb'): | |
210 print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed ' | |
211 'on host (see BUG=305769).') | |
212 return 1 | |
213 | |
214 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) | |
215 lsusb_output, _ = lsusb_proc.communicate() | |
216 if lsusb_proc.returncode: | |
217 print ('Error: Could not get list of USB ports (i.e. lsusb).') | |
218 return lsusb_proc.returncode | |
219 | |
220 usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] | |
221 for lsusb_line in lsusb_output.strip().split('\n')] | |
222 | |
223 failed_restart = False | |
224 # Walk USB devices from leaves up (i.e reverse sorted) restarting the | |
225 # connection. If a parent node (e.g. usb hub) is restarted before the | |
226 # devices connected to it, the (bus, dev) for the hub can change, making the | |
227 # output we have wrong. This way we restart the devices before the hub. | |
228 for (bus, dev) in reversed(sorted(usb_devices)): | |
229 # Can not restart root usb connections | |
230 if dev != '001': | |
231 return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev], | |
232 flunk_on_failure=True) | |
Isaac (away)
2013/10/17 07:27:55
this is the default, line not needed.
| |
233 if return_code: | |
234 print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev) | |
235 failed_restart = True | |
236 else: | |
237 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) | |
238 | |
239 if failed_restart: | |
240 return 1 | |
241 | |
242 return 0 | |
243 | |
244 | |
206 def main(): | 245 def main(): |
207 parser = optparse.OptionParser() | 246 parser = optparse.OptionParser() |
208 parser.add_option('', '--out-dir', | 247 parser.add_option('', '--out-dir', |
209 help='Directory where the device path is stored', | 248 help='Directory where the device path is stored', |
210 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) | 249 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) |
211 parser.add_option('--no-provisioning-check', action='store_true', | 250 parser.add_option('--no-provisioning-check', action='store_true', |
212 help='Will not check if devices are provisioned properly.') | 251 help='Will not check if devices are provisioned properly.') |
213 parser.add_option('--device-status-dashboard', action='store_true', | 252 parser.add_option('--device-status-dashboard', action='store_true', |
214 help='Output device status data for dashboard.') | 253 help='Output device status data for dashboard.') |
254 parser.add_option('--restart-usb', action='store_true', | |
255 help='Restart USB ports before running device check.') | |
215 options, args = parser.parse_args() | 256 options, args = parser.parse_args() |
216 if args: | 257 if args: |
217 parser.error('Unknown options %s' % args) | 258 parser.error('Unknown options %s' % args) |
259 | |
260 if options.restart_usb: | |
261 rc = RestartUsb() | |
262 if rc: | |
263 return 1 | |
264 | |
218 devices = android_commands.GetAttachedDevices() | 265 devices = android_commands.GetAttachedDevices() |
219 # TODO(navabi): Test to make sure this fails and then fix call | 266 # TODO(navabi): Test to make sure this fails and then fix call |
220 offline_devices = android_commands.GetAttachedDevices(hardware=False, | 267 offline_devices = android_commands.GetAttachedDevices(hardware=False, |
221 emulator=False, | 268 emulator=False, |
222 offline=True) | 269 offline=True) |
223 | 270 |
224 types, builds, batteries, reports, errors = [], [], [], [], [] | 271 types, builds, batteries, reports, errors = [], [], [], [], [] |
225 fail_step_lst = [] | 272 fail_step_lst = [] |
226 if devices: | 273 if devices: |
227 types, builds, batteries, reports, errors, fail_step_lst = ( | 274 types, builds, batteries, reports, errors, fail_step_lst = ( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 # devices with critically low battery or install speed. Remove those devices | 310 # devices with critically low battery or install speed. Remove those devices |
264 # from testing, allowing build to continue with good devices. | 311 # from testing, allowing build to continue with good devices. |
265 return 1 | 312 return 1 |
266 | 313 |
267 if not devices: | 314 if not devices: |
268 return 1 | 315 return 1 |
269 | 316 |
270 | 317 |
271 if __name__ == '__main__': | 318 if __name__ == '__main__': |
272 sys.exit(main()) | 319 sys.exit(main()) |
OLD | NEW |