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 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 sys | 12 import sys |
13 import re | 13 import re |
14 | 14 |
15 import bb_annotations | |
frankf
2013/07/15 17:43:02
convention is to order the imports from most to le
gkanwar1
2013/07/15 17:54:09
This is following the pattern of imports that occu
| |
16 | |
17 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
frankf
2013/07/15 17:43:02
Why do you need this?
gkanwar1
2013/07/15 17:54:09
Since the file is being moved into buildbot, we ne
| |
15 from pylib import android_commands | 18 from pylib import android_commands |
16 from pylib import buildbot_report | |
17 from pylib import constants | 19 from pylib import constants |
18 from pylib.cmd_helper import GetCmdOutput | 20 from pylib.cmd_helper import GetCmdOutput |
19 | 21 |
20 | 22 |
21 def DeviceInfo(serial, options): | 23 def DeviceInfo(serial, options): |
22 """Gathers info on a device via various adb calls. | 24 """Gathers info on a device via various adb calls. |
23 | 25 |
24 Args: | 26 Args: |
25 serial: The serial of the attached device to construct info about. | 27 serial: The serial of the attached device to construct info about. |
26 | 28 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 all_known_devices = list(set(adb_online_devs) | set(last_devices)) | 138 all_known_devices = list(set(adb_online_devs) | set(last_devices)) |
137 WriteDeviceList('.last_devices', all_known_devices) | 139 WriteDeviceList('.last_devices', all_known_devices) |
138 WriteDeviceList('.last_missing', missing_devs) | 140 WriteDeviceList('.last_missing', missing_devs) |
139 | 141 |
140 if not all_known_devices: | 142 if not all_known_devices: |
141 # This can happen if for some reason the .last_devices file is not | 143 # This can happen if for some reason the .last_devices file is not |
142 # present or if it was empty. | 144 # present or if it was empty. |
143 return ['No online devices. Have any devices been plugged in?'] | 145 return ['No online devices. Have any devices been plugged in?'] |
144 if missing_devs: | 146 if missing_devs: |
145 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 147 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
146 buildbot_report.PrintSummaryText(devices_missing_msg) | 148 bb_annotations.PrintSummaryText(devices_missing_msg) |
147 | 149 |
148 # TODO(navabi): Debug by printing both output from GetCmdOutput and | 150 # TODO(navabi): Debug by printing both output from GetCmdOutput and |
149 # GetAttachedDevices to compare results. | 151 # GetAttachedDevices to compare results. |
150 return ['Current online devices: %s' % adb_online_devs, | 152 return ['Current online devices: %s' % adb_online_devs, |
151 '%s are no longer visible. Were they removed?\n' % missing_devs, | 153 '%s are no longer visible. Were they removed?\n' % missing_devs, |
152 'SHERIFF: See go/chrome_device_monitor', | 154 'SHERIFF: See go/chrome_device_monitor', |
153 'Cache file: %s\n\n' % last_devices_path, | 155 'Cache file: %s\n\n' % last_devices_path, |
154 'adb devices: %s' % GetCmdOutput(['adb', 'devices']), | 156 'adb devices: %s' % GetCmdOutput(['adb', 'devices']), |
155 'adb devices(GetAttachedDevices): %s' % | 157 'adb devices(GetAttachedDevices): %s' % |
156 android_commands.GetAttachedDevices()] | 158 android_commands.GetAttachedDevices()] |
157 else: | 159 else: |
158 new_devs = set(adb_online_devs) - set(last_devices) | 160 new_devs = set(adb_online_devs) - set(last_devices) |
159 if new_devs and os.path.exists(last_devices_path): | 161 if new_devs and os.path.exists(last_devices_path): |
160 buildbot_report.PrintWarning() | 162 bb_annotations.PrintWarning() |
161 buildbot_report.PrintSummaryText( | 163 bb_annotations.PrintSummaryText( |
162 '%d new devices detected' % len(new_devs)) | 164 '%d new devices detected' % len(new_devs)) |
163 print ('New devices detected %s. And now back to your ' | 165 print ('New devices detected %s. And now back to your ' |
164 'regularly scheduled program.' % list(new_devs)) | 166 'regularly scheduled program.' % list(new_devs)) |
165 | 167 |
166 | 168 |
167 def SendDeviceStatusAlert(msg): | 169 def SendDeviceStatusAlert(msg): |
168 from_address = 'buildbot@chromium.org' | 170 from_address = 'buildbot@chromium.org' |
169 to_address = 'chromium-android-device-alerts@google.com' | 171 to_address = 'chromium-android-device-alerts@google.com' |
170 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') | 172 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') |
171 slave_name = os.environ.get('BUILDBOT_SLAVENAME') | 173 slave_name = os.environ.get('BUILDBOT_SLAVENAME') |
(...skipping 25 matching lines...) Expand all Loading... | |
197 fail_step_lst = [] | 199 fail_step_lst = [] |
198 if devices: | 200 if devices: |
199 types, builds, reports, errors, fail_step_lst = ( | 201 types, builds, reports, errors, fail_step_lst = ( |
200 zip(*[DeviceInfo(dev, options) for dev in devices])) | 202 zip(*[DeviceInfo(dev, options) for dev in devices])) |
201 | 203 |
202 err_msg = CheckForMissingDevices(options, devices) or [] | 204 err_msg = CheckForMissingDevices(options, devices) or [] |
203 | 205 |
204 unique_types = list(set(types)) | 206 unique_types = list(set(types)) |
205 unique_builds = list(set(builds)) | 207 unique_builds = list(set(builds)) |
206 | 208 |
207 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' | 209 bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' |
208 % (len(devices), unique_types, unique_builds)) | 210 % (len(devices), unique_types, unique_builds)) |
209 print '\n'.join(reports) | 211 print '\n'.join(reports) |
210 | 212 |
211 for serial, dev_errors in zip(devices, errors): | 213 for serial, dev_errors in zip(devices, errors): |
212 if dev_errors: | 214 if dev_errors: |
213 err_msg += ['%s errors:' % serial] | 215 err_msg += ['%s errors:' % serial] |
214 err_msg += [' %s' % error for error in dev_errors] | 216 err_msg += [' %s' % error for error in dev_errors] |
215 | 217 |
216 if err_msg: | 218 if err_msg: |
217 buildbot_report.PrintWarning() | 219 bb_annotations.PrintWarning() |
218 msg = '\n'.join(err_msg) | 220 msg = '\n'.join(err_msg) |
219 print msg | 221 print msg |
220 SendDeviceStatusAlert(msg) | 222 SendDeviceStatusAlert(msg) |
221 | 223 |
222 if False in fail_step_lst: | 224 if False in fail_step_lst: |
223 # TODO(navabi): Build fails on device status check step if there exists any | 225 # TODO(navabi): Build fails on device status check step if there exists any |
224 # devices with critically low battery or install speed. Remove those devices | 226 # devices with critically low battery or install speed. Remove those devices |
225 # from testing, allowing build to continue with good devices. | 227 # from testing, allowing build to continue with good devices. |
226 return 1 | 228 return 1 |
227 | 229 |
228 if not devices: | 230 if not devices: |
229 return 1 | 231 return 1 |
230 | 232 |
231 | 233 |
232 if __name__ == '__main__': | 234 if __name__ == '__main__': |
233 sys.exit(main()) | 235 sys.exit(main()) |
OLD | NEW |