blob: 59d141b45e44e02ed30e4d12288f8b3ec5fce5d5 [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,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030011 'bootchart': 800,
12 'busybox': 800,
13 'device-tree': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030014 'e2eaudiotest': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030015 'ethernet': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030016 'gatortests': 1200,
Andrew McDermott5c370112013-08-23 11:10:28 +010017 'jtreg': 86400,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030018 'kernel-version': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030019 'leb-basic-graphics': 7200,
20 'ltp': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030021 'mysql': 800,
Fathi Boudrac13926a2013-07-03 11:36:37 +030022 'network-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030023 'perf': 800,
24 'phpinfo': 800,
25 'phpmysql': 800,
26 'pwrmgmt': 800,
27 'sdkhelloc': 800,
28 'sdkhellocxx': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030029 'smoke-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030030 'toolchain': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030031 'wifi-enablement': 7200,
32}
33
Fathi Boudrac14068b2012-12-06 17:42:11 +020034tests_nano = [
35 'device-tree',
36 'gatortests',
Fathi Boudrac13926a2013-07-03 11:36:37 +030037 'network-tests-basic',
Fathi Boudrac14068b2012-12-06 17:42:11 +020038 'perf',
39 'pwrmgmt',
Fathi Boudra2486ee12013-06-28 13:39:07 +030040 'smoke-tests-basic',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030041]
Fathi Boudrac14068b2012-12-06 17:42:11 +020042
43tests_alip = [
44 'bootchart',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030045]
Fathi Boudrac14068b2012-12-06 17:42:11 +020046
47tests_desktop = [
48 'e2eaudiotest',
49 'bluetooth-enablement',
50 'wifi-enablement',
51 'leb-basic-graphics',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030052]
Fathi Boudrac14068b2012-12-06 17:42:11 +020053
Fathi Boudra60d0e972013-04-19 10:49:47 +030054tests_openembedded_minimal = [
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020055 'busybox',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020056 'device-tree',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020057 'ethernet',
58 'kernel-version',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020059 'perf',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020060 'toolchain',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030061]
Andy Doan61b4d772012-04-24 10:03:28 -050062
Fathi Boudra60d0e972013-04-19 10:49:47 +030063tests_openembedded_lamp = [
Fathi Boudra60d0e972013-04-19 10:49:47 +030064 'mysql',
65 'phpinfo',
66 'phpmysql',
67 'sdkhelloc',
68 'sdkhellocxx',
69]
70
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010071tests_openembedded_leg_java = [
Andrew McDermottedd9b8d2013-08-24 00:07:53 +010072 'openjdk7-sanity',
73 'openjdk8-sanity',
Andrew McDermott114e7662013-07-03 16:12:37 +010074 'mauve',
Andrew McDermott5c370112013-08-23 11:10:28 +010075 'jtreg',
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010076]
77
Fathi Boudra8e4ce562012-12-08 14:35:17 +020078# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050079DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020080 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020081 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030082 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020083 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050084 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050085 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020086 'rtsm_foundation-armv8': 'vexpress64',
87 'rtsm_ve-a15x1-a7x1': 'vexpress',
88 'rtsm_ve-a15x4-a7x4': 'vexpress',
89 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050090 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020091 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030092 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020093 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050094}
95
Andy Doan61b4d772012-04-24 10:03:28 -050096
97def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030098 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050099
Fathi Boudrac14068b2012-12-06 17:42:11 +0200100
Andy Doan61b4d772012-04-24 10:03:28 -0500101def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200102 """Script entry point: return some JSON based on calling args.
103 We should be called from Jenkins and expect the following to be defined:
104 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
105 """
Andy Doan61b4d772012-04-24 10:03:28 -0500106
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200107 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300108 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200109 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300110 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200111
112 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300113 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200114 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300115 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200116 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300117 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
118 if hwpack_file_name == 'Undefined':
119 sys.exit('Hardware pack is not defined.')
120
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200121 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300122 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
123 if device_type == 'Undefined':
124 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200125
126 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300127 ret_split = hwpack_job_name.split('-', 2)
128 (distribution, architecture, hwpack_type) = \
129 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200130 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300131 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200132 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300133 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200134 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300135 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200136
137 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300138 bundle_stream_name = os.environ.get(
139 'BUNDLE_STREAM_NAME',
140 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
141
Fathi Boudrac14068b2012-12-06 17:42:11 +0200142 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300143 lava_user = os.environ.get('LAVA_USER')
144 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200145 f = open('/var/run/lava/lava-user')
146 lava_user = f.read().strip()
147 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300148
Fathi Boudrac14068b2012-12-06 17:42:11 +0200149 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300150 lava_token = os.environ.get('LAVA_TOKEN')
151 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200152 f = open('/var/run/lava/lava-token')
153 lava_token = f.read().strip()
154 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200155
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300156 # LAVA server URL
157 lava_server = os.environ.get('LAVA_SERVER',
Fathi Boudra62997d92013-07-27 09:58:28 +0300158 'validation.linaro.org/RPC2/')
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300159 # LAVA server base URL
160 lava_server_root = lava_server.rstrip('/')
161 if lava_server_root.endswith('/RPC2'):
162 lava_server_root = lava_server_root[:-len('/RPC2')]
163
164 image_url = '%s/%s/pre-built/%s/%s/%s' % \
165 (snapshots_url,
166 distribution,
167 hwpack_type,
168 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200169 hwpack_file_name)
170
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300171 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530172
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200173 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300174 if distribution == 'openembedded':
175 tests = tests_openembedded_minimal
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300176 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300177 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300178
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300179 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200180 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300181 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500182
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300183 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200184 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300185 tests = tests_alip + tests
186
Fathi Boudra60d0e972013-04-19 10:49:47 +0300187 if 'lamp' in rootfs_type:
188 tests += tests_openembedded_lamp
189
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100190 if 'leg-java' in rootfs_type:
191 tests += tests_openembedded_leg_java
192
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300193 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200194 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300195 try:
196 tests.remove('bluetooth-enablement')
197 tests.remove('wifi-enablement')
198 except ValueError:
199 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300200
201 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200202 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300203 try:
204 tests.remove('pwrmgmt')
205 except ValueError:
206 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500207
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200208 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200209 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300210 'command': 'deploy_linaro_image',
211 'parameters': {
212 'image': '%s' % image_url,
213 },
214 'metadata': {
215 'hwpack.type': '%s' % hwpack_type,
216 'hwpack.build': '%s' % hwpack_build_number,
217 'rootfs.type': '%s' % rootfs_type,
218 'distribution': '%s' % distribution,
219 }
220 },
221 {
222 'command': 'boot_linaro_image',
223 'parameters': {
224 'options': ['boot_cmds=boot_cmds_oe']
225 }
226 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300227 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200228 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300229 'command': 'deploy_linaro_image',
230 'parameters': {
231 'image': '%s' % image_url,
232 },
233 'metadata': {
234 'ubuntu.name': '%s' % hwpack_type,
235 'ubuntu.build': '%s' % hwpack_build_number,
236 'rootfs.type': '%s' % rootfs_type,
237 'ubuntu.distribution': '%s' % distribution,
238 }
239 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200240
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200241 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300242 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300243 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530244 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300245 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300246 {'git-repo': git_repo,
247 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300248 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530249
Fathi Boudraebb2f192013-06-17 10:01:09 +0300250 actions.append({
251 'command': 'lava_test_shell',
252 'parameters': {
Fathi Boudrab088b142013-07-19 09:54:04 +0300253 'timeout': tests_timeout.get(test, 18000),
Fathi Boudraebb2f192013-06-17 10:01:09 +0300254 'testdef_repos': test_list
255 }
256 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200257
258 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300259 'command': 'submit_results',
260 'parameters': {
261 'stream': bundle_stream_name,
262 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200263 }
264 })
265
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300266 config = json.dumps({'timeout': 18000,
267 'actions': actions,
268 'job_name': '%s%s/%s/' % (ci_base_url,
269 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200270 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300271 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200272 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200273
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200274 print config
275
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300276 skip_lava = os.environ.get('SKIP_LAVA')
277 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200278 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200279 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300280 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200281 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300282 xmlrpclib.ServerProxy(server_url.format(
283 lava_user=lava_user,
284 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200285 lava_server=lava_server))
286 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200287 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300288 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200289 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200290
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300291 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200292 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300293 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200294 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300295 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200296
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300297 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
298 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200299 for root, dirs, files in os.walk(top_dir):
300 for file in files:
301 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300302 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200303
Fathi Boudrade020592012-12-10 13:25:14 +0200304 with open(lava_job_info_orig) as f:
305 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200306
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300307 buffer = buffer.replace(
308 'var lavaJobId = 0',
309 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200310
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300311 lava_job_info = lava_job_info_orig.replace(
312 '.html',
313 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200314 with open(lava_job_info, 'w') as f:
315 f.write(buffer)
316 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200317 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300318 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500319
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300320
321if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500322 main()