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

Side by Side Diff: build/android/buildbot/bb_device_status_check.py

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 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 unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 sys.path.append(os.path.join(os.path.dirname(__file__), 23 sys.path.append(os.path.join(os.path.dirname(__file__),
24 os.pardir, os.pardir, 'util', 'lib', 24 os.pardir, os.pardir, 'util', 'lib',
25 'common')) 25 'common'))
26 import perf_tests_results_helper # pylint: disable=F0401 26 import perf_tests_results_helper # pylint: disable=F0401
27 27
28 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 28 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
29 from pylib import android_commands 29 from pylib import android_commands
30 from pylib import constants 30 from pylib import constants
31 from pylib.cmd_helper import GetCmdOutput 31 from pylib.cmd_helper import GetCmdOutput
32 from pylib.device import device_blacklist 32 from pylib.device import device_blacklist
33 from pylib.device import device_utils
33 34
34 def DeviceInfo(serial, options): 35 def DeviceInfo(serial, options):
35 """Gathers info on a device via various adb calls. 36 """Gathers info on a device via various adb calls.
36 37
37 Args: 38 Args:
38 serial: The serial of the attached device to construct info about. 39 serial: The serial of the attached device to construct info about.
39 40
40 Returns: 41 Returns:
41 Tuple of device type, build id, report as a string, error messages, and 42 Tuple of device type, build id, report as a string, error messages, and
42 boolean indicating whether or not device can be used for testing. 43 boolean indicating whether or not device can be used for testing.
43 """ 44 """
44 45
45 device_adb = android_commands.AndroidCommands(serial) 46 device_adb = device_utils.DeviceUtils(serial)
46 47 device_type = device_adb.old_interface.GetBuildProduct()
47 # TODO(navabi): Replace AdbShellCmd with device_adb. 48 device_build = device_adb.old_interface.GetBuildId()
48 device_type = device_adb.GetBuildProduct() 49 device_build_type = device_adb.old_interface.GetBuildType()
49 device_build = device_adb.GetBuildId() 50 device_product_name = device_adb.old_interface.GetProductName()
50 device_build_type = device_adb.GetBuildType()
51 device_product_name = device_adb.GetProductName()
52 51
53 try: 52 try:
54 battery = device_adb.GetBatteryInfo() 53 battery = device_adb.old_interface.GetBatteryInfo()
55 except Exception as e: 54 except Exception as e:
56 battery = None 55 battery = None
57 logging.error('Unable to obtain battery info for %s, %s', serial, e) 56 logging.error('Unable to obtain battery info for %s, %s', serial, e)
58 57
59 def _GetData(re_expression, line, lambda_function=lambda x:x): 58 def _GetData(re_expression, line, lambda_function=lambda x:x):
60 if not line: 59 if not line:
61 return 'Unknown' 60 return 'Unknown'
62 found = re.findall(re_expression, line) 61 found = re.findall(re_expression, line)
63 if found and len(found): 62 if found and len(found):
64 return lambda_function(found[0]) 63 return lambda_function(found[0])
65 return 'Unknown' 64 return 'Unknown'
66 65
67 ac_power = _GetData('AC powered: (\w+)', battery) 66 ac_power = _GetData('AC powered: (\w+)', battery)
68 battery_level = _GetData('level: (\d+)', battery) 67 battery_level = _GetData('level: (\d+)', battery)
69 battery_temp = _GetData('temperature: (\d+)', battery, 68 battery_temp = _GetData('temperature: (\d+)', battery,
70 lambda x: float(x) / 10.0) 69 lambda x: float(x) / 10.0)
71 imei_slice = _GetData('Device ID = (\d+)', 70 imei_slice = _GetData('Device ID = (\d+)',
72 device_adb.GetSubscriberInfo(), 71 device_adb.old_interface.GetSubscriberInfo(),
73 lambda x: x[-6:]) 72 lambda x: x[-6:])
74 report = ['Device %s (%s)' % (serial, device_type), 73 report = ['Device %s (%s)' % (serial, device_type),
75 ' Build: %s (%s)' % 74 ' Build: %s (%s)' %
76 (device_build, device_adb.GetBuildFingerprint()), 75 (device_build, device_adb.old_interface.GetBuildFingerprint()),
77 ' Battery: %s%%' % battery_level, 76 ' Battery: %s%%' % battery_level,
78 ' Battery temp: %s' % battery_temp, 77 ' Battery temp: %s' % battery_temp,
79 ' IMEI slice: %s' % imei_slice, 78 ' IMEI slice: %s' % imei_slice,
80 ' Wifi IP: %s' % device_adb.GetWifiIP(), 79 ' Wifi IP: %s' % device_adb.old_interface.GetWifiIP(),
81 ''] 80 '']
82 81
83 errors = [] 82 errors = []
84 if battery_level < 15: 83 if battery_level < 15:
85 errors += ['Device critically low in battery. Turning off device.'] 84 errors += ['Device critically low in battery. Turning off device.']
86 if not options.no_provisioning_check: 85 if not options.no_provisioning_check:
87 setup_wizard_disabled = device_adb.GetSetupWizardStatus() == 'DISABLED' 86 setup_wizard_disabled = (
87 device_adb.old_interface.GetSetupWizardStatus() == 'DISABLED')
88 if not setup_wizard_disabled and device_build_type != 'user': 88 if not setup_wizard_disabled and device_build_type != 'user':
89 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] 89 errors += ['Setup wizard not disabled. Was it provisioned correctly?']
90 if device_product_name == 'mantaray' and ac_power != 'true': 90 if device_product_name == 'mantaray' and ac_power != 'true':
91 errors += ['Mantaray device not connected to AC power.'] 91 errors += ['Mantaray device not connected to AC power.']
92 92
93 # Turn off devices with low battery. 93 # Turn off devices with low battery.
94 if battery_level < 15: 94 if battery_level < 15:
95 device_adb.EnableAdbRoot() 95 device_adb.old_interface.EnableAdbRoot()
96 device_adb.Shutdown() 96 device_adb.old_interface.Shutdown()
97 full_report = '\n'.join(report) 97 full_report = '\n'.join(report)
98 return device_type, device_build, battery_level, full_report, errors, True 98 return device_type, device_build, battery_level, full_report, errors, True
99 99
100 100
101 def GetLastDevices(out_dir): 101 def GetLastDevices(out_dir):
102 """Returns a list of devices that have been seen on the bot. 102 """Returns a list of devices that have been seen on the bot.
103 103
104 Args: 104 Args:
105 options: out_dir parameter of options argument is used as the base 105 options: out_dir parameter of options argument is used as the base
106 directory to load and update the cache file. 106 directory to load and update the cache file.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 (os.environ.get('BUILDBOT_BUILDERNAME'), 169 (os.environ.get('BUILDBOT_BUILDERNAME'),
170 os.environ.get('BUILDBOT_SLAVENAME'), 170 os.environ.get('BUILDBOT_SLAVENAME'),
171 os.environ.get('BUILDBOT_BUILDNUMBER'))))) 171 os.environ.get('BUILDBOT_BUILDNUMBER')))))
172 return ['Current online devices: %s' % adb_online_devs, 172 return ['Current online devices: %s' % adb_online_devs,
173 '%s are no longer visible. Were they removed?\n' % missing_devs, 173 '%s are no longer visible. Were they removed?\n' % missing_devs,
174 'SHERIFF:\n', 174 'SHERIFF:\n',
175 '@@@STEP_LINK@Click here to file a bug@%s@@@\n' % crbug_link, 175 '@@@STEP_LINK@Click here to file a bug@%s@@@\n' % crbug_link,
176 'Cache file: %s\n\n' % last_devices_path, 176 'Cache file: %s\n\n' % last_devices_path,
177 'adb devices: %s' % GetCmdOutput(['adb', 'devices']), 177 'adb devices: %s' % GetCmdOutput(['adb', 'devices']),
178 'adb devices(GetAttachedDevices): %s' % 178 'adb devices(GetAttachedDevices): %s' %
179 android_commands.GetAttachedDevices()] 179 android_commands.GetAttachedDevices()]
180 else: 180 else:
181 new_devs = set(adb_online_devs) - set(last_devices) 181 new_devs = set(adb_online_devs) - set(last_devices)
182 if new_devs and os.path.exists(last_devices_path): 182 if new_devs and os.path.exists(last_devices_path):
183 bb_annotations.PrintWarning() 183 bb_annotations.PrintWarning()
184 bb_annotations.PrintSummaryText( 184 bb_annotations.PrintSummaryText(
185 '%d new devices detected' % len(new_devs)) 185 '%d new devices detected' % len(new_devs))
186 print ('New devices detected %s. And now back to your ' 186 print ('New devices detected %s. And now back to your '
187 'regularly scheduled program.' % list(new_devs)) 187 'regularly scheduled program.' % list(new_devs))
188 188
189 189
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 # All devices are online, keep going. 297 # All devices are online, keep going.
298 break 298 break
299 if not usb_restarted and devices: 299 if not usb_restarted and devices:
300 # The USB wasn't restarted, but there's at least one device online. 300 # The USB wasn't restarted, but there's at least one device online.
301 # No point in trying to wait for all devices. 301 # No point in trying to wait for all devices.
302 break 302 break
303 retries -= 1 303 retries -= 1
304 304
305 devices = android_commands.GetAttachedDevices() 305 devices = android_commands.GetAttachedDevices()
306 # TODO(navabi): Test to make sure this fails and then fix call 306 # TODO(navabi): Test to make sure this fails and then fix call
307 offline_devices = android_commands.GetAttachedDevices(hardware=False, 307 offline_devices = android_commands.GetAttachedDevices(
308 emulator=False, 308 hardware=False, emulator=False, offline=True)
309 offline=True)
310 309
311 types, builds, batteries, reports, errors = [], [], [], [], [] 310 types, builds, batteries, reports, errors = [], [], [], [], []
312 fail_step_lst = [] 311 fail_step_lst = []
313 if devices: 312 if devices:
314 types, builds, batteries, reports, errors, fail_step_lst = ( 313 types, builds, batteries, reports, errors, fail_step_lst = (
315 zip(*[DeviceInfo(dev, options) for dev in devices])) 314 zip(*[DeviceInfo(dev, options) for dev in devices]))
316 315
317 err_msg = CheckForMissingDevices(options, devices) or [] 316 err_msg = CheckForMissingDevices(options, devices) or []
318 317
319 unique_types = list(set(types)) 318 unique_types = list(set(types))
(...skipping 30 matching lines...) Expand all
350 # devices with critically low battery. Remove those devices from testing, 349 # devices with critically low battery. Remove those devices from testing,
351 # allowing build to continue with good devices. 350 # allowing build to continue with good devices.
352 return 1 351 return 1
353 352
354 if not devices: 353 if not devices:
355 return 1 354 return 1
356 355
357 356
358 if __name__ == '__main__': 357 if __name__ == '__main__':
359 sys.exit(main()) 358 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698