blob: 5ae1a8f4fd5486d8b3a2e5e7793b74769342f9ac [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 Boudra2486ee12013-06-28 13:39:07 +03009tests_timeout = {
10 'bluetooth-enablement': 7200,
11 'bootchart': 300,
12 'busybox': 300,
13 'device-tree': 300,
14 'e2eaudiotest': 7200,
15 'ethernet': 600,
16 'gatortests': 1200,
17 'kernel-version': 300,
18 'leb-basic-graphics': 7200,
19 'ltp': 7200,
20 'mysql': 300,
Fathi Boudrac13926a2013-07-03 11:36:37 +030021 'network-tests-basic': 1200,
Fathi Boudra2486ee12013-06-28 13:39:07 +030022 'perf': 300,
23 'phpinfo': 300,
24 'phpmysql': 300,
25 'pwrmgmt': 600,
26 'sdkhelloc': 300,
27 'sdkhellocxx': 300,
28 'smoke-tests-basic': 1200,
29 'toolchain': 300,
30 'wifi-enablement': 7200,
31}
32
Fathi Boudrac14068b2012-12-06 17:42:11 +020033tests_nano = [
34 'device-tree',
35 'gatortests',
Fathi Boudrac13926a2013-07-03 11:36:37 +030036 'network-tests-basic',
Fathi Boudrac14068b2012-12-06 17:42:11 +020037 'perf',
38 'pwrmgmt',
Fathi Boudra2486ee12013-06-28 13:39:07 +030039 'smoke-tests-basic',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030040]
Fathi Boudrac14068b2012-12-06 17:42:11 +020041
42tests_alip = [
43 'bootchart',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030044]
Fathi Boudrac14068b2012-12-06 17:42:11 +020045
46tests_desktop = [
47 'e2eaudiotest',
48 'bluetooth-enablement',
49 'wifi-enablement',
50 'leb-basic-graphics',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030051]
Fathi Boudrac14068b2012-12-06 17:42:11 +020052
Fathi Boudra60d0e972013-04-19 10:49:47 +030053tests_openembedded_minimal = [
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020054 'busybox',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020055 'device-tree',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020056 'ethernet',
57 'kernel-version',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020058 'perf',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020059 'toolchain',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030060]
Andy Doan61b4d772012-04-24 10:03:28 -050061
Fathi Boudra60d0e972013-04-19 10:49:47 +030062tests_openembedded_lamp = [
63 'pwrmgmt',
64 'mysql',
65 'phpinfo',
66 'phpmysql',
67 'sdkhelloc',
68 'sdkhellocxx',
69]
70
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010071tests_openembedded_leg_java = [
72 # placeholder tests for leg_java
73 'sdkhelloc',
74 'sdkhellocxx',
75]
76
Fathi Boudra8e4ce562012-12-08 14:35:17 +020077# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050078DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020079 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020080 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030081 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020082 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050083 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050084 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020085 'rtsm_foundation-armv8': 'vexpress64',
86 'rtsm_ve-a15x1-a7x1': 'vexpress',
87 'rtsm_ve-a15x4-a7x4': 'vexpress',
88 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050089 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020090 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030091 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020092 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050093}
94
Andy Doan61b4d772012-04-24 10:03:28 -050095
96def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030097 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050098
Fathi Boudrac14068b2012-12-06 17:42:11 +020099
Andy Doan61b4d772012-04-24 10:03:28 -0500100def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200101 """Script entry point: return some JSON based on calling args.
102 We should be called from Jenkins and expect the following to be defined:
103 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
104 """
Andy Doan61b4d772012-04-24 10:03:28 -0500105
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200106 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300107 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200108 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300109 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200110
111 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300112 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200113 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300114 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200115 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300116 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
117 if hwpack_file_name == 'Undefined':
118 sys.exit('Hardware pack is not defined.')
119
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200120 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300121 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
122 if device_type == 'Undefined':
123 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200124
125 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300126 ret_split = hwpack_job_name.split('-', 2)
127 (distribution, architecture, hwpack_type) = \
128 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200129 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300130 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200131 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300132 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200133 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300134 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200135
136 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300137 bundle_stream_name = os.environ.get(
138 'BUNDLE_STREAM_NAME',
139 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
140
Fathi Boudrac14068b2012-12-06 17:42:11 +0200141 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300142 lava_user = os.environ.get('LAVA_USER')
143 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200144 f = open('/var/run/lava/lava-user')
145 lava_user = f.read().strip()
146 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300147
Fathi Boudrac14068b2012-12-06 17:42:11 +0200148 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300149 lava_token = os.environ.get('LAVA_TOKEN')
150 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200151 f = open('/var/run/lava/lava-token')
152 lava_token = f.read().strip()
153 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200154
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300155 # LAVA server URL
156 lava_server = os.environ.get('LAVA_SERVER',
157 'validation.linaro.org/lava-server/RPC2/')
158 # LAVA server base URL
159 lava_server_root = lava_server.rstrip('/')
160 if lava_server_root.endswith('/RPC2'):
161 lava_server_root = lava_server_root[:-len('/RPC2')]
162
163 image_url = '%s/%s/pre-built/%s/%s/%s' % \
164 (snapshots_url,
165 distribution,
166 hwpack_type,
167 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200168 hwpack_file_name)
169
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300170 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530171
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200172 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300173 if distribution == 'openembedded':
174 tests = tests_openembedded_minimal
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300175 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300176 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300177
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300178 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200179 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300180 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500181
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300182 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200183 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300184 tests = tests_alip + tests
185
Fathi Boudra60d0e972013-04-19 10:49:47 +0300186 if 'lamp' in rootfs_type:
187 tests += tests_openembedded_lamp
188
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100189 if 'leg-java' in rootfs_type:
190 tests += tests_openembedded_leg_java
191
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300192 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200193 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300194 try:
195 tests.remove('bluetooth-enablement')
196 tests.remove('wifi-enablement')
197 except ValueError:
198 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300199
200 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200201 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300202 try:
203 tests.remove('pwrmgmt')
204 except ValueError:
205 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500206
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200207 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200208 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300209 'command': 'deploy_linaro_image',
210 'parameters': {
211 'image': '%s' % image_url,
212 },
213 'metadata': {
214 'hwpack.type': '%s' % hwpack_type,
215 'hwpack.build': '%s' % hwpack_build_number,
216 'rootfs.type': '%s' % rootfs_type,
217 'distribution': '%s' % distribution,
218 }
219 },
220 {
221 'command': 'boot_linaro_image',
222 'parameters': {
223 'options': ['boot_cmds=boot_cmds_oe']
224 }
225 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300226 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200227 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300228 'command': 'deploy_linaro_image',
229 'parameters': {
230 'image': '%s' % image_url,
231 },
232 'metadata': {
233 'ubuntu.name': '%s' % hwpack_type,
234 'ubuntu.build': '%s' % hwpack_build_number,
235 'rootfs.type': '%s' % rootfs_type,
236 'ubuntu.distribution': '%s' % distribution,
237 }
238 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200239
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200240 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300241 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300242 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530243 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300244 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300245 {'git-repo': git_repo,
246 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300247 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530248
Fathi Boudraebb2f192013-06-17 10:01:09 +0300249 actions.append({
250 'command': 'lava_test_shell',
251 'parameters': {
Fathi Boudra2486ee12013-06-28 13:39:07 +0300252 'timeout': tests_timeout[test],
Fathi Boudraebb2f192013-06-17 10:01:09 +0300253 'testdef_repos': test_list
254 }
255 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200256
257 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300258 'command': 'submit_results',
259 'parameters': {
260 'stream': bundle_stream_name,
261 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200262 }
263 })
264
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300265 config = json.dumps({'timeout': 18000,
266 'actions': actions,
267 'job_name': '%s%s/%s/' % (ci_base_url,
268 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200269 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300270 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200271 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200272
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200273 print config
274
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300275 skip_lava = os.environ.get('SKIP_LAVA')
276 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200277 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200278 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300279 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200280 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300281 xmlrpclib.ServerProxy(server_url.format(
282 lava_user=lava_user,
283 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200284 lava_server=lava_server))
285 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200286 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300287 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200288 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200289
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300290 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200291 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300292 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200293 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300294 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200295
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300296 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
297 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200298 for root, dirs, files in os.walk(top_dir):
299 for file in files:
300 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300301 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200302
Fathi Boudrade020592012-12-10 13:25:14 +0200303 with open(lava_job_info_orig) as f:
304 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200305
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300306 buffer = buffer.replace(
307 'var lavaJobId = 0',
308 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200309
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300310 lava_job_info = lava_job_info_orig.replace(
311 '.html',
312 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200313 with open(lava_job_info, 'w') as f:
314 f.write(buffer)
315 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200316 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300317 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500318
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300319
320if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500321 main()