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
/
b2g_panda.py
executable file
·222 lines (201 loc) · 9.21 KB
/
b2g_panda.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python
# ***** 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 *****
import os
import sys
from time import sleep
# load modules from parent dir
sys.path.insert(1, os.path.dirname(sys.path[0]))
from mozharness.mozilla.buildbot import TBPL_SUCCESS, TBPL_FAILURE, TBPL_WARNING, TBPL_RETRY, BuildbotMixin
from mozharness.base.log import ERROR
from mozharness.base.python import VirtualenvMixin
from mozharness.base.script import BaseScript
from mozharness.mozilla.testing.testbase import TestingMixin
from mozharness.mozilla.testing.mozpool import MozpoolMixin, MozpoolConflictException, MozpoolException
#TODO - adjust these values
MAX_RETRIES = 20
RETRY_INTERVAL = 60
REQUEST_DURATION = 60 * 40
class PandaTest(TestingMixin, BaseScript, VirtualenvMixin, MozpoolMixin, BuildbotMixin):
config_options = [
[["--mozpool-api-url"], {
"dest": "mozpool_api_url",
"help": "Override mozpool api url",
}],
[["--mozpool-device"], {
"dest": "mozpool_device",
"help": "Set Panda device to run tests on",
}],
[["--mozpool-assignee"], {
"dest": "mozpool_assignee",
"help": "Set mozpool assignee (requestor name, free-form)",
}],
[["--mozpool-b2gbase"], {
"dest": "mozpool_b2gbase",
"help": "Set b2gbase url",
}],
]
error_list = []
mozbase_dir = os.path.join('tests', 'mozbase')
virtualenv_modules = [
'requests',
{ 'manifestparser': os.path.join(mozbase_dir, 'manifestdestiny') },
{ 'mozhttpd': os.path.join(mozbase_dir, 'mozhttpd') },
{ 'mozinfo': os.path.join(mozbase_dir, 'mozinfo') },
{ 'mozfile': os.path.join(mozbase_dir, 'mozfile') },
{ 'mozinstall': os.path.join(mozbase_dir, 'mozinstall') },
{ 'mozprofile': os.path.join(mozbase_dir, 'mozprofile') },
{ 'mozprocess': os.path.join(mozbase_dir, 'mozprocess') },
{ 'mozrunner': os.path.join(mozbase_dir, 'mozrunner') },
{ 'mozdevice': os.path.join(mozbase_dir, 'mozdevice') },
{ 'marionette': os.path.join('tests', 'marionette/client') },
{ 'gaiatest': os.path.join('tests', 'gaiatest') },
]
def __init__(self, require_config_file=False):
super(PandaTest, self).__init__(
config_options=self.config_options,
all_actions=['clobber',
'read-buildbot-config',
'download-and-extract',
'create-virtualenv',
'request-device',
'run-test',
'close-request'],
default_actions=['clobber',
'create-virtualenv',
'download-and-extract',
'request-device',
'run-test',
'close-request'],
require_config_file=require_config_file,
config={'virtualenv_modules': self.virtualenv_modules,
'require_test_zip': True,})
self.foopyname = self.query_env()["HOSTNAME"].split(".")[0]
self.mozpool_assignee = self.config.get('mozpool_assignee', \
self.foopyname)
self.request_url = None
def postflight_read_buildbot_config(self):
super(PandaTest, self).postflight_read_buildbot_config()
self.mozpool_device = self.config.get('mozpool_device', \
self.buildbot_config.get('properties')["slavename"])
# XXX: remove this function when bug 826372 gets resolved
def postflight_download_and_extract(self):
dirs = self.query_abs_dirs()
unzip = self.query_exe("unzip")
test_install_dir = dirs.get('abs_test_install_dir', os.path.join(dirs['abs_work_dir'], 'tests'))
os.chdir(test_install_dir)
self.download_file("http://ftp-scl3.mozilla.com/pub/mozilla.org/b2g/tinderbox-builds/cedar-ics_armv7a_gecko/1357245427/b2g-20.0a1.en-US.android-arm.tests.zip")
unzip_cmd = [unzip, '-q', '-o', 'b2g-20.0a1.en-US.android-arm.tests.zip']
self.run_command(unzip_cmd, cwd=test_install_dir, halt_on_failure=True)
def request_device(self):
mph = self.query_mozpool_handler()
for retry in self._retry_sleep(sleep_time=RETRY_INTERVAL, max_retries=MAX_RETRIES,
error_message="INFRA-ERROR: Could not request device '%s'" % self.mozpool_device,
tbpl_status=TBPL_RETRY):
try:
duration = REQUEST_DURATION
image = 'b2g'
b2gbase = self.config.get('mozpool_b2g_base', \
self.installer_url)
response = mph.request_device(self.mozpool_device, self.mozpool_assignee, image, duration, \
b2gbase=b2gbase, pxe_config=None)
break
except MozpoolConflictException:
self.warning("Device unavailable. Retry#%i.." % retry)
except MozpoolException, e:
self.buildbot_status(TBPL_RETRY)
self.fatal("We could not request the device: %s" % str(e))
self.request_url = response['request']['url']
self.info("Got request, url=%s" % self.request_url)
self._wait_for_request_ready()
def run_test(self):
"""
Run the Panda tests
"""
mph = self.query_mozpool_handler()
sys.path.append(self.query_python_site_packages_path())
from mozdevice.devicemanagerSUT import DeviceManagerSUT
APP_INI_LOCATION = '/system/b2g/application.ini'
dm = None
try:
self.info("Connecting to: %s" % self.mozpool_device)
dm = DeviceManagerSUT(self.mozpool_device)
except Exception, e:
self.error("%s" % str(e))
mph.close_request(self.request_url)
self.buildbot_status(TBPL_RETRY)
self.fatal("ERROR: Unable to properly connect to SUT Port on device.")
# No need for 300 second SUT socket timeouts here
dm.default_timeout = 30
if not dm.fileExists(APP_INI_LOCATION):
mph.close_request(self.request_url)
self.buildbot_status(TBPL_RETRY)
self.fatal("ERROR: expected file (%s) not found" % APP_INI_LOCATION)
file_contents = dm.catFile(APP_INI_LOCATION)
if file_contents is None:
mph.close_request(self.request_url)
self.buildbot_status(TBPL_RETRY)
self.fatal("ERROR: Unable to read file (%s)" % APP_INI_LOCATION)
self.info("Read of file (%s) follows" % APP_INI_LOCATION)
self.info("===========================")
self.info(file_contents)
self.info("Running tests...")
dirs = self.query_abs_dirs()
cmd = [self.query_python_path('gaiatest'),
'--address', '%s:2828' % self.mozpool_device,
'--type', 'b2g', os.path.join(dirs['abs_gaiatest_dir'], 'tests', 'manifest.ini')]
code = self.run_command(cmd)
if code == 0:
status = "success"
tbpl_status = TBPL_SUCCESS
elif code == 10: # XXX assuming this code is the right one
status = "test failures"
tbpl_status = TBPL_WARNING
else:
status = "harness failures"
level = ERROR
tbpl_status = TBPL_FAILURE
def query_abs_dirs(self):
if self.abs_dirs:
return self.abs_dirs
abs_dirs = super(PandaTest, self).query_abs_dirs()
dirs = {}
dirs['abs_test_install_dir'] = os.path.join(
abs_dirs['abs_work_dir'], 'tests')
dirs['abs_gaiatest_dir'] = os.path.join(
dirs['abs_test_install_dir'], 'gaiatest', 'gaiatest')
for key in dirs.keys():
if key not in abs_dirs:
abs_dirs[key] = dirs[key]
self.abs_dirs = abs_dirs
return self.abs_dirs
def close_request(self):
mph = self.query_mozpool_handler()
mph.close_request(self.request_url)
self.info("Request '%s' deleted on cleanup" % self.request_url)
self.request_url = None
def _retry_sleep(self, sleep_time=1, max_retries=5, error_message=None, tbpl_status=None):
for x in range(1, max_retries + 1):
yield x
sleep(sleep_time)
if error_message:
self.error(error_message)
if tbpl_status:
self.buildbot_status(tbpl_status)
self.fatal('Retries limit exceeded')
def _wait_for_request_ready(self):
mph = self.query_mozpool_handler()
for retry in self._retry_sleep(sleep_time=RETRY_INTERVAL, max_retries=MAX_RETRIES,
error_message="INFRA-ERROR: Request did not become ready in time",
tbpl_status=TBPL_RETRY):
response = mph.query_request_status(self.request_url)
state = response['state']
if state == 'ready':
return
self.info("Waiting for request 'ready' stage. Current state: '%s'" % state)
if __name__ == '__main__':
pandaTest = PandaTest()
pandaTest.run()