Chromium Code Reviews| 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 json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 138 |
| 139 try: | 139 try: |
| 140 last_missing_devices = device_list.GetPersistentDeviceList( | 140 last_missing_devices = device_list.GetPersistentDeviceList( |
| 141 last_missing_devices_path) | 141 last_missing_devices_path) |
| 142 except IOError: | 142 except IOError: |
| 143 last_missing_devices = [] | 143 last_missing_devices = [] |
| 144 | 144 |
| 145 missing_devs = list(set(last_devices) - device_serials) | 145 missing_devs = list(set(last_devices) - device_serials) |
| 146 new_missing_devs = list(set(missing_devs) - set(last_missing_devices)) | 146 new_missing_devs = list(set(missing_devs) - set(last_missing_devices)) |
| 147 | 147 |
| 148 if new_missing_devs and os.environ.get('BUILDBOT_SLAVENAME'): | 148 buildbot_slavename = os.environ.get('BUILDBOT_SLAVENAME') |
| 149 buildbot_buildername = os.environ.get('BUILDBOT_BUILDERNAME') | |
| 150 buildbot_buildnumber = os.environ.get('BUILDBOT_BUILDNUMBER') | |
| 151 | |
| 152 if new_missing_devs and buildbot_slavename: | |
| 149 logging.info('new_missing_devs %s' % new_missing_devs) | 153 logging.info('new_missing_devs %s' % new_missing_devs) |
| 150 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 154 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
| 151 bb_annotations.PrintSummaryText(devices_missing_msg) | 155 bb_annotations.PrintSummaryText(devices_missing_msg) |
| 152 | 156 |
| 153 from_address = 'chrome-bot@chromium.org' | 157 from_address = 'chrome-bot@chromium.org' |
| 154 to_addresses = ['chrome-labs-tech-ticket@google.com', | 158 to_addresses = ['chrome-labs-tech-ticket@google.com', |
| 155 'chrome-android-device-alert@google.com'] | 159 'chrome-android-device-alert@google.com'] |
| 156 cc_addresses = ['chrome-android-device-alert@google.com'] | 160 cc_addresses = ['chrome-android-device-alert@google.com'] |
| 157 subject = 'Devices offline on %s, %s, %s' % ( | 161 subject = 'Devices offline on %s, %s, %s' % ( |
| 158 os.environ.get('BUILDBOT_SLAVENAME'), | 162 buildbot_slavename, buildbot_buildername, buildbot_buildnumber) |
| 159 os.environ.get('BUILDBOT_BUILDERNAME'), | |
| 160 os.environ.get('BUILDBOT_BUILDNUMBER')) | |
| 161 msg = ('Please reboot the following devices:\n%s' % | 163 msg = ('Please reboot the following devices:\n%s' % |
| 162 '\n'.join(map(str, new_missing_devs))) | 164 '\n'.join(map(str, new_missing_devs))) |
| 163 SendEmail(from_address, to_addresses, cc_addresses, subject, msg) | 165 SendEmail(from_address, to_addresses, cc_addresses, subject, msg) |
| 164 | 166 |
| 167 unauthorized_devices = adb_wrapper.AdbWrapper.Devices( | |
| 168 desired_state='unauthorized') | |
| 169 if unauthorized_devices: | |
| 170 logging.info('unauthorized devices:') | |
| 171 for ud in unauthorized_devices: | |
| 172 logging.info(' %s', ud) | |
| 173 | |
| 174 if buildbot_slavename: | |
| 175 from_address = 'chrome-bot@chromium.org' | |
| 176 to_addresses = [ | |
| 177 'jbudorick@chromium.org', | |
|
rnephew (Wrong account)
2015/08/21 02:25:12
I'm not sure I like your email hardcoded in here,
jbudorick
2015/08/21 02:27:38
bundled in the inbox, mercifully.
jbudorick
2015/08/21 02:28:31
Also, I intend this (along with the other email al
mikecase (-- gone --)
2015/08/21 02:40:53
Shouldn't this be sent to the infra-lab people and
jbudorick
2015/08/21 02:45:23
yes
| |
| 178 'chrome-android-device-alert@google.com'] | |
| 179 subject = 'Unauthorized devices on %s' % buildbot_slavename | |
| 180 msg = ['The following devices are offline on %s' % buildbot_slavename] | |
| 181 msg += [' %s' % ud for ud in unauthorized_devices] | |
| 182 msg += ['', 'Detected on %s #%s' % (buildbot_buildername, | |
| 183 buildbot_buildnumber)] | |
| 184 msg = '\n'.join(msg) | |
| 185 SendEmail(from_address, to_addresses, [], subject, msg) | |
| 186 | |
| 165 all_known_devices = list(device_serials | set(last_devices)) | 187 all_known_devices = list(device_serials | set(last_devices)) |
| 166 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) | 188 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) |
| 167 device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs) | 189 device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs) |
| 168 | 190 |
| 169 if not all_known_devices: | 191 if not all_known_devices: |
| 170 # This can happen if for some reason the .last_devices file is not | 192 # This can happen if for some reason the .last_devices file is not |
| 171 # present or if it was empty. | 193 # present or if it was empty. |
| 172 return ['No online devices. Have any devices been plugged in?'] | 194 return ['No online devices. Have any devices been plugged in?'] |
| 173 if missing_devs: | 195 if missing_devs: |
| 174 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 196 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
| 175 bb_annotations.PrintSummaryText(devices_missing_msg) | 197 bb_annotations.PrintSummaryText(devices_missing_msg) |
| 176 return ['Current online devices: %s' % ', '.join(d for d in device_serials), | 198 return ['Current online devices: %s' % ', '.join(d for d in device_serials), |
| 177 '%s are no longer visible. Were they removed?' % missing_devs] | 199 '%s are no longer visible. Were they removed?' % missing_devs] |
| 178 else: | 200 else: |
| 179 new_devs = device_serials - set(last_devices) | 201 new_devs = device_serials - set(last_devices) |
| 180 if new_devs and os.path.exists(last_devices_path): | 202 if new_devs and os.path.exists(last_devices_path): |
| 181 bb_annotations.PrintWarning() | 203 bb_annotations.PrintWarning() |
| 182 bb_annotations.PrintSummaryText( | 204 bb_annotations.PrintSummaryText( |
| 183 '%d new devices detected' % len(new_devs)) | 205 '%d new devices detected' % len(new_devs)) |
| 184 logging.info('New devices detected:') | 206 logging.info('New devices detected:') |
| 185 for d in new_devs: | 207 for d in new_devs: |
| 186 logging.info(' %s', d) | 208 logging.info(' %s', d) |
| 187 | 209 |
| 188 | 210 |
| 189 def SendEmail(from_address, to_addresses, cc_addresses, subject, msg): | 211 def SendEmail(from_address, to_addresses, cc_addresses, subject, msg): |
| 212 # TODO(jbudorick): Transition from email alerts for every failure to a more | |
| 213 # sustainable solution. | |
| 190 msg_body = '\r\n'.join(['From: %s' % from_address, | 214 msg_body = '\r\n'.join(['From: %s' % from_address, |
| 191 'To: %s' % ', '.join(to_addresses), | 215 'To: %s' % ', '.join(to_addresses), |
| 192 'CC: %s' % ', '.join(cc_addresses), | 216 'CC: %s' % ', '.join(cc_addresses), |
| 193 'Subject: %s' % subject, '', msg]) | 217 'Subject: %s' % subject, '', msg]) |
| 194 try: | 218 try: |
| 195 server = smtplib.SMTP('localhost') | 219 server = smtplib.SMTP('localhost') |
| 196 server.sendmail(from_address, to_addresses, msg_body) | 220 server.sendmail(from_address, to_addresses, msg_body) |
| 197 server.quit() | 221 server.quit() |
| 198 except Exception: | 222 except Exception: |
| 199 logging.exception('Failed to send alert email.') | 223 logging.exception('Failed to send alert email.') |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 from_address = 'buildbot@chromium.org' | 370 from_address = 'buildbot@chromium.org' |
| 347 to_addresses = ['chromium-android-device-alerts@google.com'] | 371 to_addresses = ['chromium-android-device-alerts@google.com'] |
| 348 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') | 372 bot_name = os.environ.get('BUILDBOT_BUILDERNAME') |
| 349 slave_name = os.environ.get('BUILDBOT_SLAVENAME') | 373 slave_name = os.environ.get('BUILDBOT_SLAVENAME') |
| 350 subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) | 374 subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) |
| 351 SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) | 375 SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) |
| 352 | 376 |
| 353 if options.device_status_dashboard: | 377 if options.device_status_dashboard: |
| 354 offline_devices = [ | 378 offline_devices = [ |
| 355 device_utils.DeviceUtils(a) | 379 device_utils.DeviceUtils(a) |
| 356 for a in adb_wrapper.AdbWrapper.Devices(is_ready=False) | 380 for a in adb_wrapper.AdbWrapper.Devices(desired_state=None) |
| 357 if a.GetState() == 'offline'] | 381 if a.GetState() == 'offline'] |
| 358 | 382 |
| 359 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', | 383 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', |
| 360 [len(devices)], 'devices') | 384 [len(devices)], 'devices') |
| 361 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', | 385 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', |
| 362 [len(offline_devices)], 'devices', | 386 [len(offline_devices)], 'devices', |
| 363 'unimportant') | 387 'unimportant') |
| 364 for dev, battery in zip(devices, batteries): | 388 for dev, battery in zip(devices, batteries): |
| 365 perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), | 389 perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), |
| 366 [battery], '%', | 390 [battery], '%', |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 379 | 403 |
| 380 if num_failed_devs == len(devices): | 404 if num_failed_devs == len(devices): |
| 381 return 2 | 405 return 2 |
| 382 | 406 |
| 383 if not devices: | 407 if not devices: |
| 384 return 1 | 408 return 1 |
| 385 | 409 |
| 386 | 410 |
| 387 if __name__ == '__main__': | 411 if __name__ == '__main__': |
| 388 sys.exit(main()) | 412 sys.exit(main()) |
| OLD | NEW |