blob: 17d82f2b0f5b3f471cb3768a9087c5404d8d98fc [file] [log] [blame]
Andy Doan61b4d772012-04-24 10:03:28 -05001#!/usr/bin/python
2
Andy Doan61b4d772012-04-24 10:03:28 -05003import os
Andy Doan61b4d772012-04-24 10:03:28 -05004import sys
Fathi Boudrac14068b2012-12-06 17:42:11 +02005import json
Andy Doan61b4d772012-04-24 10:03:28 -05006import xmlrpclib
Fathi Boudrac14068b2012-12-06 17:42:11 +02007import re
Andy Doan61b4d772012-04-24 10:03:28 -05008
Fathi Boudrac14068b2012-12-06 17:42:11 +02009tests_nano = [
10 'device-tree',
11 'gatortests',
12 'perf',
13 'pwrmgmt',
14 ]
15
16tests_alip = [
17 'bootchart',
18 ]
19
20tests_desktop = [
21 'e2eaudiotest',
22 'bluetooth-enablement',
23 'wifi-enablement',
24 'leb-basic-graphics',
25 ]
26
27tests_openembedded = [
28 ]
Andy Doan61b4d772012-04-24 10:03:28 -050029
Fathi Boudra8e4ce562012-12-08 14:35:17 +020030# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050031DEVICE_STREAM = {
Fathi Boudra8e4ce562012-12-08 14:35:17 +020032 'beaglexm': 'beaglexm',
33 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050034 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050035 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020036 'rtsm_foundation-armv8': 'vexpress64',
37 'rtsm_ve-a15x1-a7x1': 'vexpress',
38 'rtsm_ve-a15x4-a7x4': 'vexpress',
39 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050040 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020041 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030042 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020043 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050044}
45
Andy Doan61b4d772012-04-24 10:03:28 -050046
47def obfuscate_credentials(s):
48 return re.sub(r"([^ ]:).+?(@)", r"\1xxx\2", s)
49
Fathi Boudrac14068b2012-12-06 17:42:11 +020050
Andy Doan61b4d772012-04-24 10:03:28 -050051def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +020052 """Script entry point: return some JSON based on calling args.
53 We should be called from Jenkins and expect the following to be defined:
54 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
55 """
Andy Doan61b4d772012-04-24 10:03:28 -050056
Fathi Boudra8e4ce562012-12-08 14:35:17 +020057 # Snapshots base URL
58 snapshots_url = "http://snapshots.linaro.org"
59
60 # Name of the hardware pack project
61 hwpack_job_name = os.environ.get("HWPACK_JOB_NAME")
62 # The hardware pack build number
63 hwpack_build_number = os.environ.get("HWPACK_BUILD_NUMBER")
64 # Hardware pack file name
65 hwpack_file_name = os.environ.get("HWPACK_FILE_NAME", "Undefined")
66 if hwpack_file_name == "Undefined":
67 sys.exit("Hardware pack is not defined.")
68 # Device type
69 device_type = os.environ.get("DEVICE_TYPE", "Undefined")
70 if device_type == "Undefined":
71 sys.exit("Device type is not defined.")
72
73 # Distribution, architecture and hardware pack type
74 ret_split = hwpack_job_name.split("-", 2)
75 (distribution, architecture, hwpack_type) =\
76 ret_split[0], ret_split[1], ret_split[2]
77 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudrad4ed3e22012-12-09 21:21:31 +020078 hwpack_type = hwpack_type[(len("pre-built-images-")):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +020079 # Rootfs type, default is developer
80 rootfs_type = os.getenv("ROOTFS_TYPE", "developer")
Fathi Boudrac14068b2012-12-06 17:42:11 +020081
82 # Bundle stream name
83 bundle_stream_name = os.environ.get("BUNDLE_STREAM_NAME", \
Fathi Boudra8e4ce562012-12-08 14:35:17 +020084 "/private/team/linaro/pre-built-%s/" % DEVICE_STREAM[device_type])
Fathi Boudrac14068b2012-12-06 17:42:11 +020085 # LAVA user
86 lava_user = os.environ.get("LAVA_USER")
87 if lava_user == None:
88 f = open('/var/run/lava/lava-user')
89 lava_user = f.read().strip()
90 f.close()
91 # LAVA token
92 lava_token = os.environ.get("LAVA_TOKEN")
93 if lava_token == None:
94 f = open('/var/run/lava/lava-token')
95 lava_token = f.read().strip()
96 f.close()
97 # LAVA server URL
98 lava_server = os.environ.get("LAVA_SERVER", \
99 "validation.linaro.org/lava-server/RPC2/")
100 # LAVA server base URL
101 lava_server_root = lava_server.rstrip("/")
102 if lava_server_root.endswith("/RPC2"):
103 lava_server_root = lava_server_root[:-len("/RPC2")]
104
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200105 image_url = "%s/%s/pre-built/%s/%s/%s" %\
106 (snapshots_url, \
107 distribution, \
108 hwpack_type, \
109 hwpack_build_number, \
110 hwpack_file_name)
111
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530112 git_repo = "git://git.linaro.org/ubuntu/test-definitions.git"
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530113
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200114 # tests set specific to an image
Fathi Boudrac51e0912012-06-15 18:18:41 +0300115 tests = tests_nano
116
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300117 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200118 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300119 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500120
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300121 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200122 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300123 tests = tests_alip + tests
124
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300125 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200126 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300127 try:
128 tests.remove('bluetooth-enablement')
129 tests.remove('wifi-enablement')
130 except ValueError:
131 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300132
133 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200134 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300135 try:
136 tests.remove('pwrmgmt')
137 except ValueError:
138 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500139
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200140 if distribution == 'openembedded':
Fathi Boudrac14068b2012-12-06 17:42:11 +0200141 tests = tests_openembedded
Fathi Boudra4079a582012-12-06 19:42:58 +0200142 actions = [{
143 "command": "deploy_linaro_image",
144 "parameters": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200145 "image": "%s" % image_url,
Fathi Boudra4079a582012-12-06 19:42:58 +0200146 },
147 "metadata": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200148 "hwpack.type": "%s" % hwpack_type,
149 "hwpack.build": "%s" % hwpack_build_number,
150 "rootfs.type": "%s" % rootfs_type,
Fathi Boudra4079a582012-12-06 19:42:58 +0200151 "distribution": "%s" % distribution,
152 }
153 }]
154 else: # Distribution is Ubuntu
155 actions = [{
156 "command": "deploy_linaro_image",
157 "parameters": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200158 "image": "%s" % image_url,
Fathi Boudra4079a582012-12-06 19:42:58 +0200159 },
160 "metadata": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200161 "ubuntu.name": "%s" % hwpack_type,
162 "ubuntu.build": "%s" % hwpack_build_number,
163 "rootfs.type": "%s" % rootfs_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200164 "ubuntu.distribution": "%s" % distribution,
Fathi Boudra4079a582012-12-06 19:42:58 +0200165 }
166 }]
167
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200168 if len(tests) > 0:
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530169 test_list = []
170 for test in tests:
171 test_list.append({"git-repo": git_repo,
172 "testdef": 'ubuntu/{0}.yaml'.format(test)})
Fathi Boudrac14068b2012-12-06 17:42:11 +0200173 actions.append({
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530174 "command": "lava_test_shell",
Fathi Boudrac14068b2012-12-06 17:42:11 +0200175 "parameters": {
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530176 "testdef_repos": test_list
Fathi Boudrac14068b2012-12-06 17:42:11 +0200177 }
178 })
179
180 actions.append({
181 "command": "submit_results",
182 "parameters": {
183 "stream": bundle_stream_name,
184 "server": "%s%s" % ("http://", lava_server)
185 }
186 })
187
188 config = json.dumps({"timeout": 18000,
189 "actions": actions,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200190 "job_name": hwpack_job_name,
191 "device_type": device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200192 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200193
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200194 print config
195
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200196 skip_lava = os.environ.get("SKIP_LAVA")
197 if skip_lava == None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200198 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200199 server_url = \
200 "https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}"
201 server = \
202 xmlrpclib.ServerProxy(server_url.format(\
203 lava_user=lava_user, \
204 lava_token=lava_token, \
205 lava_server=lava_server))
206 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200207 except xmlrpclib.ProtocolError, e:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200208 print "Error making a LAVA request:", obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200209 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200210
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200211 print "LAVA Job Id: %s, URL: http://%s/scheduler/job/%s" % \
212 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200213 json.dump({'lava_url': "http://" + lava_server_root,
214 'job_id': lava_job_id},
215 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200216
Fathi Boudrade020592012-12-10 13:25:14 +0200217 lava_job_info_orig = hwpack_file_name.replace(".img.gz", ".html")
218 top_dir = os.environ.get("WORKSPACE", ".")
219 for root, dirs, files in os.walk(top_dir):
220 for file in files:
221 if file == lava_job_info_orig:
222 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200223
Fathi Boudrade020592012-12-10 13:25:14 +0200224 with open(lava_job_info_orig) as f:
225 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200226
Fathi Boudrade020592012-12-10 13:25:14 +0200227 buffer = buffer.replace("var lavaJobId = 0", \
228 "var lavaJobId = " + str(lava_job_id), 1)
229
230 lava_job_info = lava_job_info_orig.replace(".html",\
231 "-" + device_type + ".html")
232 with open(lava_job_info, 'w') as f:
233 f.write(buffer)
234 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200235 else:
236 print "LAVA job submission skipped."
Andy Doan61b4d772012-04-24 10:03:28 -0500237
238if __name__ == "__main__":
239 main()