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

Side by Side Diff: build/android/provision_devices.py

Issue 204353011: If install of test apk fails because of storage, wipe device data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use constants.ADB_KEYS_FILE. Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « build/android/buildbot/bb_device_status_check.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
24 25
25 26
26 def KillHostHeartbeat(): 27 def KillHostHeartbeat():
27 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) 28 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
28 stdout, _ = ps.communicate() 29 stdout, _ = ps.communicate()
29 matches = re.findall('\\n.*host_heartbeat.*', stdout) 30 matches = re.findall('\\n.*host_heartbeat.*', stdout)
30 for match in matches: 31 for match in matches:
31 print 'An instance of host heart beart running... will kill' 32 print 'An instance of host heart beart running... will kill'
32 pid = re.findall('(\d+)', match)[1] 33 pid = re.findall('(\d+)', match)[1]
33 subprocess.call(['kill', str(pid)]) 34 subprocess.call(['kill', str(pid)])
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 'ro.audio.silent=1', 77 'ro.audio.silent=1',
77 'ro.setupwizard.mode=DISABLED', 78 'ro.setupwizard.mode=DISABLED',
78 ] 79 ]
79 adb.SetProtectedFileContents(android_commands.LOCAL_PROPERTIES_PATH, 80 adb.SetProtectedFileContents(android_commands.LOCAL_PROPERTIES_PATH,
80 '\n'.join(local_props)) 81 '\n'.join(local_props))
81 # Android will not respect the local props file if it is world writable. 82 # Android will not respect the local props file if it is world writable.
82 adb.RunShellCommandWithSU('chmod 644 %s' % 83 adb.RunShellCommandWithSU('chmod 644 %s' %
83 android_commands.LOCAL_PROPERTIES_PATH) 84 android_commands.LOCAL_PROPERTIES_PATH)
84 85
85 86
87 def WipeDeviceData(device):
88 """Wipes data from device, keeping only the adb_keys for authorization.
89
90 After wiping data on a device that has been authorized, adb can still
91 communicate with the device, but after reboot the device will need to be
92 re-authorized because the adb keys file is stored in /data/misc/adb/.
93 Thus, before reboot the adb_keys file is rewritten so the device does not need
94 to be re-authorized.
95
96 Arguments:
97 device: the device to wipe
98 """
99 android_cmd = android_commands.AndroidCommands(device)
100 device_authorized = android_cmd.FileExistsOnDevice(constants.ADB_KEYS_FILE)
101 if device_authorized:
102 adb_keys = android_cmd.RunShellCommandWithSU(
103 'cat %s' % constants.ADB_KEYS_FILE)[0]
104 android_cmd.RunShellCommandWithSU('wipe data')
105 if device_authorized:
106 path_list = constants.ADB_KEYS_FILE.split('/')
107 dir_path = '/'.join(path_list[:len(path_list)-1])
108 android_cmd.RunShellCommandWithSU('mkdir -p %s' % dir_path)
109 adb_keys = android_cmd.RunShellCommand(
110 'echo %s > %s' % (adb_keys, constants.ADB_KEYS_FILE))
111 android_cmd.Reboot()
112
113
86 def ProvisionDevices(options): 114 def ProvisionDevices(options):
87 if options.device is not None: 115 if options.device is not None:
88 devices = [options.device] 116 devices = [options.device]
89 else: 117 else:
90 devices = android_commands.GetAttachedDevices() 118 devices = android_commands.GetAttachedDevices()
91 for device in devices: 119 for device in devices:
92 android_cmd = android_commands.AndroidCommands(device) 120 android_cmd = android_commands.AndroidCommands(device)
121 install_output = GetCmdOutput(
122 ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT,
123 '--apk',
124 '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT
125 ])
126 failure_string = 'Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]'
127 if failure_string in install_output:
128 WipeDeviceData(device)
93 _ConfigureLocalProperties(android_cmd) 129 _ConfigureLocalProperties(android_cmd)
94 device_settings.ConfigureContentSettingsDict( 130 device_settings.ConfigureContentSettingsDict(
95 android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS) 131 android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
96 # TODO(tonyg): We eventually want network on. However, currently radios 132 # TODO(tonyg): We eventually want network on. However, currently radios
97 # can cause perfbots to drain faster than they charge. 133 # can cause perfbots to drain faster than they charge.
98 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): 134 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower():
99 device_settings.ConfigureContentSettingsDict( 135 device_settings.ConfigureContentSettingsDict(
100 android_cmd, device_settings.NETWORK_DISABLED_SETTINGS) 136 android_cmd, device_settings.NETWORK_DISABLED_SETTINGS)
101 android_cmd.RunShellCommandWithSU('date -u %f' % time.time()) 137 android_cmd.RunShellCommandWithSU('date -u %f' % time.time())
102 if options.auto_reconnect: 138 if options.auto_reconnect:
(...skipping 15 matching lines...) Expand all
118 154
119 if args: 155 if args:
120 print >> sys.stderr, 'Unused args %s' % args 156 print >> sys.stderr, 'Unused args %s' % args
121 return 1 157 return 1
122 158
123 ProvisionDevices(options) 159 ProvisionDevices(options)
124 160
125 161
126 if __name__ == '__main__': 162 if __name__ == '__main__':
127 sys.exit(main(sys.argv)) 163 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/buildbot/bb_device_status_check.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698