Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2564)

Unified Diff: build/android/device_status_check.py

Issue 12382006: Check if mantarays are charging, and alert on all Android device errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/device_status_check.py
diff --git a/build/android/device_status_check.py b/build/android/device_status_check.py
index 5f78ddce3d87a2d3778c5748c355b84ffd52e745..e8211fe93fdbc7a3e1a6832581a2067e2c9e2bea 100755
--- a/build/android/device_status_check.py
+++ b/build/android/device_status_check.py
@@ -33,14 +33,17 @@ def DeviceInfo(serial):
device_type = AdbShellCmd('getprop ro.build.product')
device_build = AdbShellCmd('getprop ro.build.id')
+ device_product_name = AdbShellCmd('getprop ro.product.name')
setup_wizard_disabled = AdbShellCmd(
'getprop ro.setupwizard.mode') == 'DISABLED'
battery = AdbShellCmd('dumpsys battery')
if 'Error' in battery:
+ ac_power = 'Unknown'
battery_level = 'Unknown'
battery_temp = 'Unknown'
else:
+ ac_power = re.findall('AC powered: (\w+)', battery)[0]
Isaac (away) 2013/03/05 07:12:22 This will throw an exception if the regex does not
Siva Chandra 2013/03/13 02:18:33 As per xsdg@, yes.
battery_level = int(re.findall('level: (\d+)', battery)[0])
battery_temp = float(re.findall('temperature: (\d+)', battery)[0]) / 10
report = ['Device %s (%s)' % (serial, device_type),
@@ -55,12 +58,19 @@ def DeviceInfo(serial):
'']
warnings = []
+ errors = []
if battery_level < 5:
- warnings += ['critically low battery']
+ warnings += ['\tDevice critically low in battery.\n']
if not setup_wizard_disabled:
- warnings += ['Setup wizard not disabled. Was it provisioned correctly?']
+ warnings += ['\tSetup wizard not disabled. Was it provisioned correctly?\n']
+ if device_product_name == 'mantaray' and ac_power == 'false':
Isaac (away) 2013/03/05 07:12:22 I would prefer a positive check, i.e. ac_power !=
Siva Chandra 2013/03/13 02:18:33 Done.
+ errors += ['\tMantaray device not connected to AC power.\n']
+ if warnings:
+ warnings = [''.join(warnings)]
Isaac (away) 2013/03/05 07:12:22 What is this code for?
Siva Chandra 2013/03/13 02:18:33 Now removed.
+ if errors:
+ errors = [''.join(errors)]
- return device_type, device_build, '\n'.join(report), warnings
+ return device_type, device_build, '\n'.join(report), warnings, errors
def CheckForMissingDevices(options, adb_online_devs):
@@ -102,22 +112,15 @@ def CheckForMissingDevices(options, adb_online_devs):
last_devices = ReadDeviceList('.last_devices')
missing_devs = list(set(last_devices) - set(adb_online_devs))
+ err_msg = ''
if missing_devs:
- from_address = 'buildbot@chromium.org'
- to_address = 'chromium-android-device-alerts@google.com'
- bot_name = os.environ.get('BUILDBOT_BUILDERNAME')
- slave_name = os.environ.get('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()
devices_missing_msg = '%d devices not detected.' % len(missing_devs)
buildbot_report.PrintSummaryText(devices_missing_msg)
# TODO(navabi): Debug by printing both output from GetCmdOutput and
# GetAttachedDevices to compare results.
- body = '\n'.join(
+ err = '\n'.join(
['Current online devices: %s' % adb_online_devs,
'%s are no longer visible. Were they removed?\n' % missing_devs,
'SHERIFF: See go/chrome_device_monitor',
@@ -126,24 +129,14 @@ def CheckForMissingDevices(options, adb_online_devs):
'adb devices(GetAttachedDevices): %s' %
android_commands.GetAttachedDevices()])
- print body
+ print err
# 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 and bot_name:
- msg_body = '\r\n'.join(
- ['From: %s' % from_address,
- 'To: %s' % to_address,
- 'Subject: %s' % subject,
- '', body])
- try:
- server = smtplib.SMTP('localhost')
- server.sendmail(from_address, [to_address], msg_body)
- server.quit()
- except Exception as e:
- print 'Failed to send alert email. Error: %s' % e
+ if new_missing_devs:
+ err_msg = err
Isaac (away) 2013/03/05 07:12:22 Just create the message here and return directly
Siva Chandra 2013/03/13 02:18:33 Done.
else:
new_devs = set(adb_online_devs) - set(last_devices)
if new_devs and os.path.exists(last_devices_path):
@@ -155,6 +148,26 @@ def CheckForMissingDevices(options, adb_online_devs):
WriteDeviceList('.last_devices', (adb_online_devs + last_devices))
WriteDeviceList('.last_missing', missing_devs)
+ return err_msg
+
+
+def SendDeviceStatusAlert(msg):
+ if not msg:
+ return
Isaac (away) 2013/03/05 07:12:22 remove 155-156. Don't call this function if you d
Siva Chandra 2013/03/13 02:18:33 Done.
+ from_address = 'buildbot@chromium.org'
+ to_address = 'chromium-android-device-alerts@google.com'
+ bot_name = os.environ.get('BUILDBOT_BUILDERNAME')
+ slave_name = os.environ.get('BUILDBOT_SLAVENAME')
+ subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name)
+ msg_body = '\r\n'.join(['From: %s' % from_address, 'To: %s' % to_address,
+ 'Subject: %s' % subject, '', msg])
+ try:
+ server = smtplib.SMTP('localhost')
+ server.sendmail(from_address, [to_address], msg_body)
+ server.quit()
+ except Exception as e:
+ print 'Failed to send alert email. Error: %s' % e
+
def main():
parser = optparse.OptionParser()
@@ -167,9 +180,12 @@ def main():
if args:
parser.error('Unknown options %s' % args)
devices = android_commands.GetAttachedDevices()
- types, builds, reports, errors = [], [], [], []
+ types, builds, reports, warnings, errors = [], [], [], [], []
Isaac (away) 2013/03/05 07:12:22 It's not clear to me that we need a new class of a
Siva Chandra 2013/03/13 02:18:33 Converted everything into an error.
if devices:
- types, builds, reports, errors = zip(*[DeviceInfo(dev) for dev in devices])
+ types, builds, reports, warnings, errors = zip(
+ *[DeviceInfo(dev) for dev in devices])
+
+ missing_devices_msg = CheckForMissingDevices(options, devices)
unique_types = list(set(types))
unique_builds = list(set(builds))
@@ -178,14 +194,25 @@ def main():
% (len(devices), unique_types, unique_builds))
print '\n'.join(reports)
+ full_warnings = []
full_errors = []
- for serial, device_errors in zip(devices, errors):
- full_errors.extend('%s: %s' % (serial, error) for error in device_errors)
- if full_errors:
+ device_info_err_msg = ''
+ for serial, dev_warnings in zip(devices, warnings):
+ full_warnings.extend('%s:\n%s' % (serial, error) for error in dev_warnings)
+ for serial, dev_errors in zip(devices, errors):
+ full_errors.extend('%s:\n%s' % (serial, error) for error in dev_errors)
+
+ if full_warnings or full_errors or missing_devices_msg:
buildbot_report.PrintWarning()
- print '\n'.join(full_errors)
- CheckForMissingDevices(options, devices)
+ if full_warnings:
+ print '\n'.join(full_warnings)
+ if full_errors:
+ device_info_err_msg = '\n'.join(full_errors)
+ print device_info_err_msg
+
+ SendDeviceStatusAlert(missing_devices_msg + device_info_err_msg)
+
if __name__ == '__main__':
sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698