This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
device_talosrunner.py
195 lines (169 loc) · 7.46 KB
/
device_talosrunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python -u
# ***** BEGIN LICENSE BLOCK *****
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# ***** END LICENSE BLOCK *****
"""device_talosrunner.py
Set up and run talos against a device running SUT Agent or ADBD.
WIP.
"""
import os
import sys
import time
sys.path.insert(1, os.path.dirname(sys.path[0]))
from mozharness.base.errors import PythonErrorList
from mozharness.mozilla.testing.device import device_config_options, DeviceMixin
from mozharness.mozilla.testing.talos import Talos
# Stop buffering!
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
# DeviceTalosRunner {{{1
class DeviceTalosRunner(DeviceMixin, Talos):
config_options = Talos.config_options + device_config_options
def __init__(self, require_config_file=False):
super(DeviceTalosRunner, self).__init__(
config_options=self.config_options,
all_actions=['preclean',
'create-virtualenv',
'check-device',
'read-buildbot-config',
'download',
'unpack',
'pre-cleanup-device',
'install-app',
'generate-config',
'run-tests',
'post-cleanup-device',
# 'upload',
# 'notify',
# 'postclean',
# 'reboot-host',
],
default_actions=['preclean',
'create-virtualenv',
'check-device',
'pre-cleanup-device',
'download',
'unpack',
'install-app',
'generate-config',
'run-tests',
'post-cleanup-device',
],
config={'virtualenv_modules': ['talos']},
require_config_file=require_config_file,
)
if not self.installer_path:
self.installer_path = os.path.join(self.workdir, 'installer.apk')
def _pre_config_lock(self, rw_config):
super(DeviceTalosRunner, self)._pre_config_lock(rw_config)
if 'device_protocol' not in self.config:
self.fatal("Must specify --device-protocol!")
# Helper methods {{{2
def query_abs_dirs(self):
if self.abs_dirs:
return self.abs_dirs
abs_dirs = super(DeviceTalosRunner, self).query_abs_dirs()
abs_dirs['abs_application_dir'] = os.path.join(abs_dirs['abs_work_dir'],
'application')
self.abs_dirs = abs_dirs
return self.abs_dirs
# Actions {{{2
def preclean(self):
self.clobber()
# create_virtualenv defined in VirtualenvMixin
# check_device defined in DeviceMixin
def pre_cleanup_device(self):
self.cleanup_device()
# read_buildbot_config defined in BuildbotMixin
def download(self):
if not self.installer_url:
self.installer_url = self.config['installer_url']
self._download_installer()
def unpack(self):
# We need a generic extract() again.
dirs = self.query_abs_dirs()
unzip = self.query_exe("unzip")
self.mkdir_p(dirs['abs_application_dir'])
self.run_command([unzip, self.installer_path],
cwd=dirs['abs_application_dir'])
inifile = os.path.join(dirs['abs_application_dir'], 'application.ini')
remoteappini = os.path.join(dirs['abs_work_dir'], 'remoteapp.ini')
self.copyfile(inifile, remoteappini)
# TODO install_app defined in DeviceMixin
def preflight_generate_config(self):
if 'install-app' in self.actions:
c = self.config
time_to_sleep = c.get("post_install_sleep", 60)
self.info("Sleeping %d to avoid post-install errors" %
time_to_sleep)
time.sleep(time_to_sleep)
super(DeviceTalosRunner, self).preflight_generate_config()
def generate_config(self, conf='talos.yml', options=None):
c = self.config
dirs = self.query_abs_dirs()
python = self.query_python_path()
script_dir = os.path.dirname(python)
additional_options = []
if c.get('disable_chrome'):
additional_options.append("--noChrome")
if c['device_protocol'] == 'sut':
additional_options.extend(['--remoteDevice', c['device_ip']])
additional_options.extend(['--remotePort', c.get('device_port', '20701')])
elif c['device_protocol'] == 'adb':
additional_options.extend(['--remoteDevice', ''])
additional_options.extend(['--remotePort', '-1'])
if c.get('start_python_webserver'):
additional_options.append('--develop')
# if c.get('repository'):
# additional_options.append('repository', c['repository'])
script = os.path.join(script_dir, 'remotePerfConfigurator')
# TODO set no_chrome based on active tests
command = [script,
'-v',
'-e', c['device_package_name'],
'-t', c.get('talos_device_name', c['device_name']),
'--branchName', c['talos_branch'],
'--resultsServer', c['graph_server'],
'--resultsLink', c['results_link'],
'--activeTests', ':'.join(c['talos_suites']),
'--sampleConfig', c['talos_config_file'],
'--output', conf,
'--browserWait', '60',
'--webServer', c['talos_webserver'],
] + additional_options
self.run_command(command, cwd=dirs['abs_work_dir'],
error_list=PythonErrorList,
halt_on_failure=True)
# def preflight_run_talos(self):
# #TODO get this un-adb-hardcoded
# if 'install-app' not in self.actions:
# c = self.config
# device_id = self.query_device_id()
# adb = self.query_exe('adb')
# kill = self.query_device_exe('kill')
# procs = self.get_output_from_command([adb, "-s", device_id,
# 'shell', 'ps'],
# log_level=DEBUG)
# if c['device_package_name'] in procs:
# self.info("Found %s running... attempting to kill." %
# c['device_package_name'])
# # TODO this needs to kill the pid
# # TODO verify it's gone
# for line in procs.splitlines():
# line_contents = re.split('\s+', line)
# if line_contents[-1].startswith(c['device_package_name']):
# self.run_command([adb, "-s", device_id, 'shell',
# kill, line_contents[1]],
# error_list=ADBErrorList)
def post_cleanup_device(self):
c = self.config
if c.get('enable_automation'):
self.cleanup_device(reboot=True)
else:
self.info("Nothing to do without enable_automation set.")
# run_tests() is in Talos
# __main__ {{{1
if __name__ == '__main__':
device_talos_runner = DeviceTalosRunner()
device_talos_runner.run()