| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 | 8 import logging |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import smtplib | 11 import smtplib |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from pylib import buildbot_report | 14 from pylib import buildbot_report |
| 15 from pylib.android_commands import GetAttachedDevices | 15 from pylib.android_commands import GetAttachedDevices |
| 16 from pylib.cmd_helper import GetCmdOutput | 16 from pylib.cmd_helper import GetCmdOutput |
| 17 | 17 |
| 18 | 18 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 def CheckForMissingDevices(options, adb_online_devs): | 53 def CheckForMissingDevices(options, adb_online_devs): |
| 54 """Uses file of previous online devices to detect broken phones. | 54 """Uses file of previous online devices to detect broken phones. |
| 55 | 55 |
| 56 Args: | 56 Args: |
| 57 options: out_dir parameter of options argument is used as the base | 57 options: out_dir parameter of options argument is used as the base |
| 58 directory to load and update the cache file. | 58 directory to load and update the cache file. |
| 59 adb_online_devs: A list of serial numbers of the currently visible | 59 adb_online_devs: A list of serial numbers of the currently visible |
| 60 and online attached devices. | 60 and online attached devices. |
| 61 """ | 61 """ |
| 62 # TODO(navabi): remove this once the bug that causes different number |
| 63 # of devices to be detected between calls is fixed. |
| 64 logger = logging.getLogger() |
| 65 logger.setLevel(logging.INFO) |
| 66 |
| 62 out_dir = os.path.abspath(options.out_dir) | 67 out_dir = os.path.abspath(options.out_dir) |
| 63 | 68 |
| 64 def ReadDeviceList(file_name): | 69 def ReadDeviceList(file_name): |
| 65 devices_path = os.path.join(out_dir, file_name) | 70 devices_path = os.path.join(out_dir, file_name) |
| 66 devices = [] | 71 devices = [] |
| 67 try: | 72 try: |
| 68 with open(devices_path) as f: | 73 with open(devices_path) as f: |
| 69 devices = f.read().splitlines() | 74 devices = f.read().splitlines() |
| 70 except IOError: | 75 except IOError: |
| 71 # Ignore error, file might not exist | 76 # Ignore error, file might not exist |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 bot_name = os.environ['BUILDBOT_BUILDERNAME'] | 95 bot_name = os.environ['BUILDBOT_BUILDERNAME'] |
| 91 slave_name = os.environ['BUILDBOT_SLAVENAME'] | 96 slave_name = os.environ['BUILDBOT_SLAVENAME'] |
| 92 num_online_devs = len(adb_online_devs) | 97 num_online_devs = len(adb_online_devs) |
| 93 subject = 'Devices offline on %s, %s (%d remaining).' % (slave_name, | 98 subject = 'Devices offline on %s, %s (%d remaining).' % (slave_name, |
| 94 bot_name, | 99 bot_name, |
| 95 num_online_devs) | 100 num_online_devs) |
| 96 buildbot_report.PrintWarning() | 101 buildbot_report.PrintWarning() |
| 97 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 102 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
| 98 buildbot_report.PrintSummaryText(devices_missing_msg) | 103 buildbot_report.PrintSummaryText(devices_missing_msg) |
| 99 | 104 |
| 105 # TODO(navabi): Debug by printing both output from GetCmdOutput and |
| 106 # GetAttachedDevices to compare results. |
| 100 body = '\n'.join( | 107 body = '\n'.join( |
| 101 ['Current online devices: %s' % adb_online_devs, | 108 ['Current online devices: %s' % adb_online_devs, |
| 102 '%s are no longer visible. Were they removed?\n' % missing_devs, | 109 '%s are no longer visible. Were they removed?\n' % missing_devs, |
| 103 'SHERIFF: See go/chrome_device_monitor', | 110 'SHERIFF: See go/chrome_device_monitor', |
| 104 'Cache file: %s\n\n' % last_devices_path, | 111 'Cache file: %s\n\n' % last_devices_path, |
| 105 'adb devices: %s' % GetCmdOutput(['adb', 'devices'])]) | 112 'adb devices: %s' % GetCmdOutput(['adb', 'devices']), |
| 113 'adb devices(GetAttachedDevices): %s' % GetAttachedDevices()]) |
| 106 | 114 |
| 107 print body | 115 print body |
| 108 | 116 |
| 109 # Only send email if the first time a particular device goes offline | 117 # Only send email if the first time a particular device goes offline |
| 110 last_missing = ReadDeviceList('.last_missing') | 118 last_missing = ReadDeviceList('.last_missing') |
| 111 new_missing_devs = set(missing_devs) - set(last_missing) | 119 new_missing_devs = set(missing_devs) - set(last_missing) |
| 112 | 120 |
| 113 if new_missing_devs: | 121 if new_missing_devs: |
| 114 msg_body = '\r\n'.join( | 122 msg_body = '\r\n'.join( |
| 115 ['From: %s' % from_address, | 123 ['From: %s' % from_address, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 unique_types = list(set(types)) | 161 unique_types = list(set(types)) |
| 154 unique_builds = list(set(builds)) | 162 unique_builds = list(set(builds)) |
| 155 | 163 |
| 156 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' | 164 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' |
| 157 % (len(devices), unique_types, unique_builds)) | 165 % (len(devices), unique_types, unique_builds)) |
| 158 print '\n'.join(reports) | 166 print '\n'.join(reports) |
| 159 CheckForMissingDevices(options, devices) | 167 CheckForMissingDevices(options, devices) |
| 160 | 168 |
| 161 if __name__ == '__main__': | 169 if __name__ == '__main__': |
| 162 sys.exit(main()) | 170 sys.exit(main()) |
| OLD | NEW |