OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 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 """Provisions Android devices with settings required for bots. | 7 """Provisions Android devices with settings required for bots. |
8 | 8 |
9 Usage: | 9 Usage: |
10 ./provision_devices.py [-d <device serial number>] | 10 ./provision_devices.py [-d <device serial number>] |
11 """ | 11 """ |
12 | 12 |
13 import logging | 13 import logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import subprocess | 17 import subprocess |
18 import sys | 18 import sys |
19 import time | 19 import time |
20 | 20 |
21 from pylib import android_commands | 21 from pylib import android_commands |
22 from pylib import constants | 22 from pylib import constants |
23 from pylib import device_settings | 23 from pylib import device_settings |
24 from pylib.cmd_helper import GetCmdOutput | |
25 from pylib.device import device_utils | 24 from pylib.device import device_utils |
26 | 25 |
27 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 26 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
28 'third_party', 'android_testrunner')) | 27 'third_party', 'android_testrunner')) |
29 import errors | 28 import errors |
30 | 29 |
31 def KillHostHeartbeat(): | 30 def KillHostHeartbeat(): |
32 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 31 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
33 stdout, _ = ps.communicate() | 32 stdout, _ = ps.communicate() |
34 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 33 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 120 |
122 | 121 |
123 def ProvisionDevices(options): | 122 def ProvisionDevices(options): |
124 if options.device is not None: | 123 if options.device is not None: |
125 devices = [options.device] | 124 devices = [options.device] |
126 else: | 125 else: |
127 devices = android_commands.GetAttachedDevices() | 126 devices = android_commands.GetAttachedDevices() |
128 for device_serial in devices: | 127 for device_serial in devices: |
129 device = device_utils.DeviceUtils(device_serial) | 128 device = device_utils.DeviceUtils(device_serial) |
130 device.old_interface.EnableAdbRoot() | 129 device.old_interface.EnableAdbRoot() |
131 install_output = GetCmdOutput( | 130 WipeDeviceData(device) |
132 ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT, | 131 try: |
133 '--apk', | 132 (device_utils.DeviceUtils.parallel(devices) |
134 '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT | 133 .old_interface.Reboot(True)) |
135 ]) | 134 except errors.DeviceUnresponsiveError: |
136 failure_string = 'Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]' | 135 pass |
137 if failure_string in install_output: | 136 for device_serial in devices: |
138 WipeDeviceData(device) | 137 device = device_utils.DeviceUtils(device_serial) |
| 138 device.WaitUntilFullyBooted(timeout=90) |
| 139 device.old_interface.EnableAdbRoot() |
139 _ConfigureLocalProperties(device) | 140 _ConfigureLocalProperties(device) |
140 device_settings.ConfigureContentSettingsDict( | 141 device_settings.ConfigureContentSettingsDict( |
141 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | 142 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
142 # TODO(tonyg): We eventually want network on. However, currently radios | 143 # TODO(tonyg): We eventually want network on. However, currently radios |
143 # can cause perfbots to drain faster than they charge. | 144 # can cause perfbots to drain faster than they charge. |
144 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): | 145 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): |
145 device_settings.ConfigureContentSettingsDict( | 146 device_settings.ConfigureContentSettingsDict( |
146 device, device_settings.NETWORK_DISABLED_SETTINGS) | 147 device, device_settings.NETWORK_DISABLED_SETTINGS) |
147 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) | 148 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) |
148 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') | 149 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 (device_utils.DeviceUtils.parallel(devices) | 181 (device_utils.DeviceUtils.parallel(devices) |
181 .old_interface.Reboot(True).pFinish(None)) | 182 .old_interface.Reboot(True).pFinish(None)) |
182 except errors.DeviceUnresponsiveError: | 183 except errors.DeviceUnresponsiveError: |
183 pass | 184 pass |
184 else: | 185 else: |
185 ProvisionDevices(options) | 186 ProvisionDevices(options) |
186 | 187 |
187 | 188 |
188 if __name__ == '__main__': | 189 if __name__ == '__main__': |
189 sys.exit(main(sys.argv)) | 190 sys.exit(main(sys.argv)) |
OLD | NEW |