blob: d17b9f281b2be48d209e6efcfb739218240bab11 [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 Boudrad1f9a862012-12-28 14:46:04 +020057 # CI base URL
58 ci_base_url = "https://ci.linaro.org/jenkins/job/"
Fathi Boudra8e4ce562012-12-08 14:35:17 +020059 # Snapshots base URL
60 snapshots_url = "http://snapshots.linaro.org"
61
62 # Name of the hardware pack project
63 hwpack_job_name = os.environ.get("HWPACK_JOB_NAME")
64 # The hardware pack build number
65 hwpack_build_number = os.environ.get("HWPACK_BUILD_NUMBER")
66 # Hardware pack file name
67 hwpack_file_name = os.environ.get("HWPACK_FILE_NAME", "Undefined")
68 if hwpack_file_name == "Undefined":
69 sys.exit("Hardware pack is not defined.")
70 # Device type
71 device_type = os.environ.get("DEVICE_TYPE", "Undefined")
72 if device_type == "Undefined":
73 sys.exit("Device type is not defined.")
74
75 # Distribution, architecture and hardware pack type
76 ret_split = hwpack_job_name.split("-", 2)
77 (distribution, architecture, hwpack_type) =\
78 ret_split[0], ret_split[1], ret_split[2]
79 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudrad4ed3e22012-12-09 21:21:31 +020080 hwpack_type = hwpack_type[(len("pre-built-images-")):]
Fathi Boudrad1f9a862012-12-28 14:46:04 +020081 if hwpack_type.find('='):
82 hwpack_type = hwpack_type[(len("pre-built-images/hwpack=")):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +020083 # Rootfs type, default is developer
84 rootfs_type = os.getenv("ROOTFS_TYPE", "developer")
Fathi Boudrac14068b2012-12-06 17:42:11 +020085
86 # Bundle stream name
87 bundle_stream_name = os.environ.get("BUNDLE_STREAM_NAME", \
Fathi Boudra8e4ce562012-12-08 14:35:17 +020088 "/private/team/linaro/pre-built-%s/" % DEVICE_STREAM[device_type])
Fathi Boudrac14068b2012-12-06 17:42:11 +020089 # LAVA user
90 lava_user = os.environ.get("LAVA_USER")
91 if lava_user == None:
92 f = open('/var/run/lava/lava-user')
93 lava_user = f.read().strip()
94 f.close()
95 # LAVA token
96 lava_token = os.environ.get("LAVA_TOKEN")
97 if lava_token == None:
98 f = open('/var/run/lava/lava-token')
99 lava_token = f.read().strip()
100 f.close()
101 # LAVA server URL
102 lava_server = os.environ.get("LAVA_SERVER", \
103 "validation.linaro.org/lava-server/RPC2/")
104 # LAVA server base URL
105 lava_server_root = lava_server.rstrip("/")
106 if lava_server_root.endswith("/RPC2"):
107 lava_server_root = lava_server_root[:-len("/RPC2")]
108
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200109 image_url = "%s/%s/pre-built/%s/%s/%s" %\
110 (snapshots_url, \
111 distribution, \
112 hwpack_type, \
113 hwpack_build_number, \
114 hwpack_file_name)
115
Fathi Boudra022b7b82012-12-20 10:50:36 +0200116 git_repo = "git://git.linaro.org/qa/test-definitions.git"
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530117
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200118 # tests set specific to an image
Fathi Boudrac51e0912012-06-15 18:18:41 +0300119 tests = tests_nano
120
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300121 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200122 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300123 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500124
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300125 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200126 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300127 tests = tests_alip + tests
128
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300129 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200130 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300131 try:
132 tests.remove('bluetooth-enablement')
133 tests.remove('wifi-enablement')
134 except ValueError:
135 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300136
137 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200138 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300139 try:
140 tests.remove('pwrmgmt')
141 except ValueError:
142 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500143
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200144 if distribution == 'openembedded':
Fathi Boudrac14068b2012-12-06 17:42:11 +0200145 tests = tests_openembedded
Fathi Boudra4079a582012-12-06 19:42:58 +0200146 actions = [{
147 "command": "deploy_linaro_image",
148 "parameters": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200149 "image": "%s" % image_url,
Fathi Boudra4079a582012-12-06 19:42:58 +0200150 },
151 "metadata": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200152 "hwpack.type": "%s" % hwpack_type,
153 "hwpack.build": "%s" % hwpack_build_number,
154 "rootfs.type": "%s" % rootfs_type,
Fathi Boudra4079a582012-12-06 19:42:58 +0200155 "distribution": "%s" % distribution,
156 }
157 }]
158 else: # Distribution is Ubuntu
159 actions = [{
160 "command": "deploy_linaro_image",
161 "parameters": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200162 "image": "%s" % image_url,
Fathi Boudra4079a582012-12-06 19:42:58 +0200163 },
164 "metadata": {
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200165 "ubuntu.name": "%s" % hwpack_type,
166 "ubuntu.build": "%s" % hwpack_build_number,
167 "rootfs.type": "%s" % rootfs_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200168 "ubuntu.distribution": "%s" % distribution,
Fathi Boudra4079a582012-12-06 19:42:58 +0200169 }
170 }]
171
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200172 if len(tests) > 0:
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530173 test_list = []
174 for test in tests:
175 test_list.append({"git-repo": git_repo,
Senthil Kumarancfa63fa2012-12-21 14:26:05 +0530176 "testdef": 'ubuntu/{0}.yaml'.format(test)})
Fathi Boudrac14068b2012-12-06 17:42:11 +0200177 actions.append({
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530178 "command": "lava_test_shell",
Fathi Boudrac14068b2012-12-06 17:42:11 +0200179 "parameters": {
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530180 "testdef_repos": test_list
Fathi Boudrac14068b2012-12-06 17:42:11 +0200181 }
182 })
183
184 actions.append({
185 "command": "submit_results",
186 "parameters": {
187 "stream": bundle_stream_name,
188 "server": "%s%s" % ("http://", lava_server)
189 }
190 })
191
192 config = json.dumps({"timeout": 18000,
193 "actions": actions,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200194 "job_name": "%s%s/%s/" % (ci_base_url,\
195 hwpack_job_name,\
196 hwpack_build_number),
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200197 "device_type": device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200198 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200199
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200200 print config
201
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200202 skip_lava = os.environ.get("SKIP_LAVA")
203 if skip_lava == None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200204 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200205 server_url = \
206 "https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}"
207 server = \
208 xmlrpclib.ServerProxy(server_url.format(\
209 lava_user=lava_user, \
210 lava_token=lava_token, \
211 lava_server=lava_server))
212 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200213 except xmlrpclib.ProtocolError, e:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200214 print "Error making a LAVA request:", obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200215 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200216
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200217 print "LAVA Job Id: %s, URL: http://%s/scheduler/job/%s" % \
218 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200219 json.dump({'lava_url': "http://" + lava_server_root,
220 'job_id': lava_job_id},
221 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200222
Fathi Boudrade020592012-12-10 13:25:14 +0200223 lava_job_info_orig = hwpack_file_name.replace(".img.gz", ".html")
224 top_dir = os.environ.get("WORKSPACE", ".")
225 for root, dirs, files in os.walk(top_dir):
226 for file in files:
227 if file == lava_job_info_orig:
228 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200229
Fathi Boudrade020592012-12-10 13:25:14 +0200230 with open(lava_job_info_orig) as f:
231 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200232
Fathi Boudrade020592012-12-10 13:25:14 +0200233 buffer = buffer.replace("var lavaJobId = 0", \
234 "var lavaJobId = " + str(lava_job_id), 1)
235
236 lava_job_info = lava_job_info_orig.replace(".html",\
237 "-" + device_type + ".html")
238 with open(lava_job_info, 'w') as f:
239 f.write(buffer)
240 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200241 else:
242 print "LAVA job submission skipped."
Andy Doan61b4d772012-04-24 10:03:28 -0500243
244if __name__ == "__main__":
245 main()