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

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

Issue 12733012: Provision Android devices after the 'device_status_check' step. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding host heartbeat Created 7 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """Provisions Android devices with settings required for bots.
8
9 Usage:
10 ./provision_devices.py [-d <device serial number>]
11 """
12
13 import optparse
14 import os
15 import re
16 import subprocess
17 import sys
18 import time
19
20 from pylib import android_commands
21 from pylib import constants
22
23
24 def PushAndLaunchAdbReboot(device, adb_reboot):
25 print 'Will push and launch adb_reboot on %s' % device
26 android_cmd = android_commands.AndroidCommands(device)
27 # Check if adb_reboot is running. If yes, stop it.
28 dev_procs = android_cmd.RunShellCommand('ps')
29 for dev_proc in dev_procs:
30 if 'adb_reboot' in dev_proc:
Isaac (away) 2013/03/25 23:50:03 I'd prefer a more structured parsing of ps.
Siva Chandra 2013/03/26 02:27:51 Like?
31 print ' adb_reboot running. Killing ...'
32 pid = re.findall('(\d+)', dev_proc)[0]
33 android_cmd.RunShellCommand('kill %s' % pid)
34 # Check if the exe is on the device. If yes, delete it.
35 if android_cmd.FileExistsOnDevice('/data/local/adb_reboot'):
Isaac (away) 2013/03/25 23:50:03 why delete? Just run pushifneeded.
Siva Chandra 2013/03/26 02:27:51 Done.
36 print ' adb_reboot exists on device. Deleting ...'
37 android_cmd.RunShellCommand('rm /data/local/adb_reboot')
38 # Push adb_reboot
39 print ' Pushing adb_reboot ...'
40 android_cmd.PushIfNeeded('%s' % adb_reboot, '/data/local/')
41 # Launch adb_reboot
42 print ' Launching adb_reboot ...'
43 p1 = subprocess.Popen(['echo', 'cd /data/local; ./adb_reboot; exit'],
Isaac (away) 2013/03/25 23:50:03 don't need to echo and pipe. You can use subproce
Siva Chandra 2013/03/26 02:27:51 This does not work: p = subprocess.Popen(['adb',
44 stdout=subprocess.PIPE)
45 subprocess.call(['adb', '-s', device, 'shell'], stdin=p1.stdout)
46
47
48 def LaunchHostHeartbeat():
49 ps = subprocess.Popen(['ps', 'a'], stdout = subprocess.PIPE)
50 stdout, _ = ps.communicate()
51 for line in stdout.splitlines():
52 if 'host_heartbeat' in line:
53 # Kill the previous host_heartbeat
54 print 'Host heart beart already running ... will kill'
55 pid = re.findall('(\d+)', line)[0]
Isaac (away) 2013/03/25 23:50:03 You should use a regex in line 52 and get the grou
Siva Chandra 2013/03/26 02:27:51 Done.
56 subprocess.call(['kill', '%s' % pid])
Isaac (away) 2013/03/25 23:50:03 prefer str(pid)
Siva Chandra 2013/03/26 02:27:51 Done.
57 break
58 # Launch a new host_heartbeat
59 cmd = '%s/build/android/host_heartbeat.py' % constants.CHROME_DIR
60 print 'Launching %s ...' % cmd
61 subprocess.Popen([cmd])
Isaac (away) 2013/03/25 23:50:03 Are you expecting this to not die when the parent
Siva Chandra 2013/03/26 02:27:51 On my system, the process stays alive, dont know w
Siva Chandra 2013/03/27 01:27:13 I do not think we need to have a detached process.
62
63
64 def ProvisionDevices(options):
65 if options.device is not None:
66 devices = [options.device]
67 else:
68 devices = android_commands.GetAttachedDevices()
69 for device in devices:
70 android_cmd = android_commands.AndroidCommands(device)
71 android_cmd.EnableAdbRoot()
72 android_cmd.RunShellCommand('date -u %f' % time.time())
73 PushAndLaunchAdbReboot(device, options.adb_reboot)
74 LaunchHostHeartbeat()
75
76
77 def main(argv):
78 parser = optparse.OptionParser()
79 parser.add_option('-d', '--device', dest='device', default=None,
80 help='The serial number of the device to be provisioned')
81 parser.add_option('-a', '--adb_reboot', dest='adb_reboot', default=None,
82 help='Path to the adb_reboot binary')
83 options, _ = parser.parse_args(argv)
84
85 if not options.adb_reboot:
86 print >> sys.stderr, 'Path to adb_reboot not specified'
87 return -1
88
89 ProvisionDevices(options)
90
91
92 if __name__ == '__main__':
93 sys.exit(main(sys.argv))
OLDNEW
« build/android/buildbot/bb_device_steps.py ('K') | « build/android/host_heartbeat.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698