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 |
17 import bb_utils | |
tonyg
2013/10/10 01:56:11
nit: alphabetize below bb_annotations
navabi
2013/10/10 02:10:21
Done.
| |
16 import bb_annotations | 18 import bb_annotations |
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 |
(...skipping 170 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 restart_usb(): | |
tonyg
2013/10/10 01:56:11
style nit: RestartUsb()
navabi
2013/10/10 02:10:21
Done.
| |
209 # Expects restart_usb to be installed (BUG=305769) | |
tonyg
2013/10/10 01:56:11
This comment doesn't add value, I'd drop it.
navabi
2013/10/10 02:10:21
Done.
| |
210 if not os.path.isfile('/usr/bin/restart_usb'): | |
211 print ('WARNING: Could not restart usb. /usr/bin/restart_usb not installed ' | |
212 'on host (see BUG=305769).') | |
213 return | |
214 | |
215 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) | |
216 lsusb_output, _ = lsusb_proc.communicate() | |
217 if lsusb_proc.returncode: | |
218 print ('WARNING: Could not restart usb. Error getting list of USB ports.') | |
219 return | |
220 | |
221 usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] | |
222 for lsusb_line in lsusb_output.strip().split('\n')] | |
223 | |
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 proc = bb_utils.SpawnCmd(['/usr/bin/restart_usb', bus, dev]) | |
tonyg
2013/10/10 01:56:11
Do you want RunCmd instead of SpawnCmd+communicate
navabi
2013/10/10 02:10:21
Done.
| |
232 proc.communicate() | |
233 if proc.returncode: | |
234 print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev) | |
235 else: | |
236 print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) | |
237 | |
238 | |
206 def main(): | 239 def main(): |
207 parser = optparse.OptionParser() | 240 parser = optparse.OptionParser() |
208 parser.add_option('', '--out-dir', | 241 parser.add_option('', '--out-dir', |
209 help='Directory where the device path is stored', | 242 help='Directory where the device path is stored', |
210 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) | 243 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) |
211 parser.add_option('--no-provisioning-check', action='store_true', | 244 parser.add_option('--no-provisioning-check', action='store_true', |
212 help='Will not check if devices are provisioned properly.') | 245 help='Will not check if devices are provisioned properly.') |
213 parser.add_option('--device-status-dashboard', action='store_true', | 246 parser.add_option('--device-status-dashboard', action='store_true', |
214 help='Output device status data for dashboard.') | 247 help='Output device status data for dashboard.') |
248 parser.add_option('--restart-usb', action='store_true', | |
249 help='Restart USB ports before running device check.') | |
215 options, args = parser.parse_args() | 250 options, args = parser.parse_args() |
216 if args: | 251 if args: |
217 parser.error('Unknown options %s' % args) | 252 parser.error('Unknown options %s' % args) |
253 | |
254 if options.restart_usb: | |
255 restart_usb() | |
256 | |
218 devices = android_commands.GetAttachedDevices() | 257 devices = android_commands.GetAttachedDevices() |
219 # TODO(navabi): Test to make sure this fails and then fix call | 258 # TODO(navabi): Test to make sure this fails and then fix call |
220 offline_devices = android_commands.GetAttachedDevices(hardware=False, | 259 offline_devices = android_commands.GetAttachedDevices(hardware=False, |
221 emulator=False, | 260 emulator=False, |
222 offline=True) | 261 offline=True) |
223 | 262 |
224 types, builds, batteries, reports, errors = [], [], [], [], [] | 263 types, builds, batteries, reports, errors = [], [], [], [], [] |
225 fail_step_lst = [] | 264 fail_step_lst = [] |
226 if devices: | 265 if devices: |
227 types, builds, batteries, reports, errors, fail_step_lst = ( | 266 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 | 302 # devices with critically low battery or install speed. Remove those devices |
264 # from testing, allowing build to continue with good devices. | 303 # from testing, allowing build to continue with good devices. |
265 return 1 | 304 return 1 |
266 | 305 |
267 if not devices: | 306 if not devices: |
268 return 1 | 307 return 1 |
269 | 308 |
270 | 309 |
271 if __name__ == '__main__': | 310 if __name__ == '__main__': |
272 sys.exit(main()) | 311 sys.exit(main()) |
OLD | NEW |