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 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 adb_online_devs: A list of serial numbers of the currently visible | 118 adb_online_devs: A list of serial numbers of the currently visible |
119 and online attached devices. | 119 and online attached devices. |
120 """ | 120 """ |
121 # TODO(navabi): remove this once the bug that causes different number | 121 # TODO(navabi): remove this once the bug that causes different number |
122 # of devices to be detected between calls is fixed. | 122 # of devices to be detected between calls is fixed. |
123 logger = logging.getLogger() | 123 logger = logging.getLogger() |
124 logger.setLevel(logging.INFO) | 124 logger.setLevel(logging.INFO) |
125 | 125 |
126 out_dir = os.path.abspath(options.out_dir) | 126 out_dir = os.path.abspath(options.out_dir) |
127 | 127 |
128 # last_devices denotes all known devices prior to this run | |
128 last_devices_path = os.path.join(out_dir, device_list.LAST_DEVICES_FILENAME) | 129 last_devices_path = os.path.join(out_dir, device_list.LAST_DEVICES_FILENAME) |
130 last_missing_devices_path = os.path.join(out_dir, | |
131 device_list.LAST_MISSING_DEVICES_FILENAME) | |
129 try: | 132 try: |
130 last_devices = device_list.GetPersistentDeviceList(last_devices_path) | 133 last_devices = device_list.GetPersistentDeviceList(last_devices_path) |
131 except IOError: | 134 except IOError: |
132 # Ignore error, file might not exist | 135 # Ignore error, file might not exist |
133 last_devices = [] | 136 last_devices = [] |
137 | |
138 try: | |
139 last_missing_devices = device_list.GetPersistentDeviceList( | |
140 last_missing_devices_path) | |
141 except IOError: | |
142 last_missing_devices = [] | |
143 | |
134 missing_devs = list(set(last_devices) - set(adb_online_devs)) | 144 missing_devs = list(set(last_devices) - set(adb_online_devs)) |
friedman1
2014/06/13 00:31:55
If you keep these as a set you can use better oper
| |
145 new_missing_devs = list(set(missing_devs) - set(last_missing_devices)) | |
146 | |
147 if new_missing_devs: | |
148 logging.info('new_missing_devs %s' % new_missing_devs) | |
149 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | |
150 bb_annotations.PrintSummaryText(devices_missing_msg) | |
151 | |
152 from_address = 'chrome-bot@google.com' | |
153 to_address = 'chrome-labs-tech-ticket@google.com' | |
154 subject = 'Devices offline on %s' % os.environ.get('BUILDBOT_SLAVENAME') | |
155 msg = ('Please reboot the following devices:\n%s' % | |
156 '\n'.join(map(str,new_missing_devs))) | |
157 SendEmail(from_address, to_address, subject, msg) | |
135 | 158 |
136 all_known_devices = list(set(adb_online_devs) | set(last_devices)) | 159 all_known_devices = list(set(adb_online_devs) | set(last_devices)) |
137 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) | 160 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) |
138 device_list.WritePersistentDeviceList( | 161 device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs) |
139 os.path.join(out_dir, device_list.LAST_MISSING_DEVICES_FILENAME), | |
140 missing_devs) | |
141 | 162 |
142 if not all_known_devices: | 163 if not all_known_devices: |
143 # This can happen if for some reason the .last_devices file is not | 164 # This can happen if for some reason the .last_devices file is not |
144 # present or if it was empty. | 165 # present or if it was empty. |
145 return ['No online devices. Have any devices been plugged in?'] | 166 return ['No online devices. Have any devices been plugged in?'] |
146 if missing_devs: | 167 if missing_devs: |
147 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 168 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
148 bb_annotations.PrintSummaryText(devices_missing_msg) | 169 bb_annotations.PrintSummaryText(devices_missing_msg) |
149 | 170 |
150 # TODO(navabi): Debug by printing both output from GetCmdOutput and | 171 # TODO(navabi): Debug by printing both output from GetCmdOutput and |
(...skipping 18 matching lines...) Expand all Loading... | |
169 else: | 190 else: |
170 new_devs = set(adb_online_devs) - set(last_devices) | 191 new_devs = set(adb_online_devs) - set(last_devices) |
171 if new_devs and os.path.exists(last_devices_path): | 192 if new_devs and os.path.exists(last_devices_path): |
172 bb_annotations.PrintWarning() | 193 bb_annotations.PrintWarning() |
173 bb_annotations.PrintSummaryText( | 194 bb_annotations.PrintSummaryText( |
174 '%d new devices detected' % len(new_devs)) | 195 '%d new devices detected' % len(new_devs)) |
175 print ('New devices detected %s. And now back to your ' | 196 print ('New devices detected %s. And now back to your ' |
176 'regularly scheduled program.' % list(new_devs)) | 197 'regularly scheduled program.' % list(new_devs)) |
177 | 198 |
178 | 199 |
179 def SendDeviceStatusAlert(msg): | 200 def SendEmail(from_address, to_address, subject, msg): |
180 from_address = 'buildbot@chromium.org' | |
181 to_address = 'chromium-android-device-alerts@google.com' | |
182 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') | |
183 slave_name = os.environ.get('BUILDBOT_SLAVENAME') | |
184 subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) | |
185 msg_body = '\r\n'.join(['From: %s' % from_address, 'To: %s' % to_address, | 201 msg_body = '\r\n'.join(['From: %s' % from_address, 'To: %s' % to_address, |
186 'Subject: %s' % subject, '', msg]) | 202 'Subject: %s' % subject, '', msg]) |
187 try: | 203 try: |
188 server = smtplib.SMTP('localhost') | 204 server = smtplib.SMTP('localhost') |
189 server.sendmail(from_address, [to_address], msg_body) | 205 server.sendmail(from_address, [to_address], msg_body) |
190 server.quit() | 206 server.quit() |
191 except Exception as e: | 207 except Exception as e: |
192 print 'Failed to send alert email. Error: %s' % e | 208 print 'Failed to send alert email. Error: %s' % e |
193 | 209 |
194 | 210 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 333 |
318 for serial, dev_errors in zip(devices, errors): | 334 for serial, dev_errors in zip(devices, errors): |
319 if dev_errors: | 335 if dev_errors: |
320 err_msg += ['%s errors:' % serial] | 336 err_msg += ['%s errors:' % serial] |
321 err_msg += [' %s' % error for error in dev_errors] | 337 err_msg += [' %s' % error for error in dev_errors] |
322 | 338 |
323 if err_msg: | 339 if err_msg: |
324 bb_annotations.PrintWarning() | 340 bb_annotations.PrintWarning() |
325 msg = '\n'.join(err_msg) | 341 msg = '\n'.join(err_msg) |
326 print msg | 342 print msg |
327 SendDeviceStatusAlert(msg) | 343 from_address = 'buildbot@chromium.org' |
344 to_address = 'chromium-android-device-alerts@google.com' | |
345 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') | |
346 slave_name = os.environ.get('BUILDBOT_SLAVENAME') | |
347 subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) | |
348 SendEmail(from_address, to_address, subject, msg) | |
328 | 349 |
329 if options.device_status_dashboard: | 350 if options.device_status_dashboard: |
330 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', | 351 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', |
331 [len(devices)], 'devices') | 352 [len(devices)], 'devices') |
332 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', | 353 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', |
333 [len(offline_devices)], 'devices', | 354 [len(offline_devices)], 'devices', |
334 'unimportant') | 355 'unimportant') |
335 for serial, battery in zip(devices, batteries): | 356 for serial, battery in zip(devices, batteries): |
336 perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, | 357 perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, |
337 [battery], '%', | 358 [battery], '%', |
338 'unimportant') | 359 'unimportant') |
339 | 360 |
340 if False in fail_step_lst: | 361 if False in fail_step_lst: |
341 # TODO(navabi): Build fails on device status check step if there exists any | 362 # TODO(navabi): Build fails on device status check step if there exists any |
342 # devices with critically low battery. Remove those devices from testing, | 363 # devices with critically low battery. Remove those devices from testing, |
343 # allowing build to continue with good devices. | 364 # allowing build to continue with good devices. |
344 return 2 | 365 return 2 |
345 | 366 |
346 if not devices: | 367 if not devices: |
347 return 1 | 368 return 1 |
348 | 369 |
349 | 370 |
350 if __name__ == '__main__': | 371 if __name__ == '__main__': |
351 sys.exit(main()) | 372 sys.exit(main()) |
OLD | NEW |