diff options
author | navabi@chromium.org <navabi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-03 00:49:53 +0000 |
---|---|---|
committer | navabi@chromium.org <navabi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-03 00:49:53 +0000 |
commit | ec2269074716dd93a815b11d73952807cbe75f27 (patch) | |
tree | 9e640ace23d2388d01cfb6ee69098c4429f59253 /build | |
parent | d2fe22ff46833f668503dc8eb9f286fb8382e437 (diff) | |
download | chromium_src-ec2269074716dd93a815b11d73952807cbe75f27.zip chromium_src-ec2269074716dd93a815b11d73952807cbe75f27.tar.gz chromium_src-ec2269074716dd93a815b11d73952807cbe75f27.tar.bz2 |
Make device_status_check.py email clank-infra if devices go offline.
BUG=152583
Review URL: https://chromiumcodereview.appspot.com/11021004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-x | build/android/device_status_check.py | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/build/android/device_status_check.py b/build/android/device_status_check.py index b3447ca..8b34a90 100755 --- a/build/android/device_status_check.py +++ b/build/android/device_status_check.py @@ -8,6 +8,7 @@ import optparse import os +import smtplib import sys from pylib import buildbot_report @@ -59,26 +60,65 @@ def CheckForMissingDevices(options, adb_online_devs): and online attached devices. """ out_dir = os.path.abspath(options.out_dir) + + def ReadDeviceList(file_name): + devices_path = os.path.join(out_dir, file_name) + devices = [] + try: + with open(devices_path) as f: + devices = f.read().splitlines() + except IOError: + # Ignore error, file might not exist + pass + return devices + + def WriteDeviceList(file_name, device_list): + path = os.path.join(out_dir, file_name) + if not os.path.exists(out_dir): + os.makedirs(out_dir) + with open(path, 'w') as f: + # Write devices currently visible plus devices previously seen. + f.write('\n'.join(set(device_list))) + last_devices_path = os.path.join(out_dir, '.last_devices') - last_devices = [] - try: - with open(last_devices_path) as f: - last_devices = f.read().splitlines() - except IOError: - # Ignore error, file might not exist - pass + last_devices = ReadDeviceList('.last_devices') missing_devs = list(set(last_devices) - set(adb_online_devs)) if missing_devs: + from_address = 'buildbot@chromium.org' + to_address = 'chromium-android-device-alerts@google.com' + bot_name = os.environ['BUILDBOT_BUILDERNAME'] + slave_name = os.environ['BUILDBOT_SLAVENAME'] + num_online_devs = len(adb_online_devs) + subject = 'Devices offline on %s, %s (%d remaining).' % (slave_name, + bot_name, + num_online_devs) buildbot_report.PrintWarning() - buildbot_report.PrintSummaryText( - '%d devices not detected.' % len(missing_devs)) - print 'Current online devices: %s' % adb_online_devs - print '%s are no longer visible. Were they removed?\n' % missing_devs - print 'SHERIFF: See go/chrome_device_monitor' - print 'Cache file: %s\n\n' % last_devices_path - print 'adb devices' - print GetCmdOutput(['adb', 'devices']) + devices_missing_msg = '%d devices not detected.' % len(missing_devs) + buildbot_report.PrintSummaryText(devices_missing_msg) + + body = '\n'.join( + ['Current online devices: %s' % adb_online_devs, + '%s are no longer visible. Were they removed?\n' % missing_devs, + 'SHERIFF: See go/clank/engineering/buildbots/troubleshooting', + 'Cache file: %s\n\n' % last_devices_path, + 'adb devices: %s' % GetCmdOutput(['adb', 'devices'])]) + + print body + + # Only send email if the first time a particular device goes offline + last_missing = ReadDeviceList('.last_missing') + new_missing_devs = set(missing_devs) - set(last_missing) + + if new_missing_devs: + msg_body = '\r\n'.join( + ['From: %s' % from_address, + 'To: %s' % to_address, + 'Subject: %s' % subject, + '', body]) + server = smtplib.SMTP('localhost') + server.sendmail(from_address, [to_address], msg_body) + server.quit() else: new_devs = set(adb_online_devs) - set(last_devices) if new_devs and os.path.exists(last_devices_path): @@ -87,12 +127,8 @@ def CheckForMissingDevices(options, adb_online_devs): '%d new devices detected' % len(new_devs)) print ('New devices detected %s. And now back to your ' 'regularly scheduled program.' % list(new_devs)) - - if not os.path.exists(out_dir): - os.makedirs(out_dir) - with open(last_devices_path, 'w') as f: - # Write devices currently visible plus devices previously seen. - f.write('\n'.join(set(adb_online_devs + last_devices))) + WriteDeviceList('.last_devices', (adb_online_devs + last_devices)) + WriteDeviceList('.last_missing', missing_devs) def main(): |