blob: 09d1641b1ac846187539b521602687fbfb6fccee [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,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030017 'kernel-version': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030018 'leb-basic-graphics': 7200,
19 'ltp': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030020 'mysql': 800,
Fathi Boudrac13926a2013-07-03 11:36:37 +030021 'network-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030022 'perf': 800,
23 'phpinfo': 800,
24 'phpmysql': 800,
25 'pwrmgmt': 800,
26 'sdkhelloc': 800,
27 'sdkhellocxx': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030028 'smoke-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030029 'toolchain': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030030 '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 = [
Fathi Boudra60d0e972013-04-19 10:49:47 +030063 'mysql',
64 'phpinfo',
65 'phpmysql',
66 'sdkhelloc',
67 'sdkhellocxx',
68]
69
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010070tests_openembedded_leg_java = [
Andrew McDermott114e7662013-07-03 16:12:37 +010071 'mauve',
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010072]
73
Fathi Boudra8e4ce562012-12-08 14:35:17 +020074# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050075DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020076 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020077 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030078 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020079 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050080 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050081 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020082 'rtsm_foundation-armv8': 'vexpress64',
83 'rtsm_ve-a15x1-a7x1': 'vexpress',
84 'rtsm_ve-a15x4-a7x4': 'vexpress',
85 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050086 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020087 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030088 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020089 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050090}
91
Andy Doan61b4d772012-04-24 10:03:28 -050092
93def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030094 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050095
Fathi Boudrac14068b2012-12-06 17:42:11 +020096
Andy Doan61b4d772012-04-24 10:03:28 -050097def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +020098 """Script entry point: return some JSON based on calling args.
99 We should be called from Jenkins and expect the following to be defined:
100 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
101 """
Andy Doan61b4d772012-04-24 10:03:28 -0500102
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200103 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300104 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200105 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300106 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200107
108 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300109 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200110 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300111 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200112 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300113 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
114 if hwpack_file_name == 'Undefined':
115 sys.exit('Hardware pack is not defined.')
116
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200117 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300118 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
119 if device_type == 'Undefined':
120 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200121
122 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300123 ret_split = hwpack_job_name.split('-', 2)
124 (distribution, architecture, hwpack_type) = \
125 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200126 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300127 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200128 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300129 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200130 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300131 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200132
133 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300134 bundle_stream_name = os.environ.get(
135 'BUNDLE_STREAM_NAME',
136 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
137
Fathi Boudrac14068b2012-12-06 17:42:11 +0200138 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300139 lava_user = os.environ.get('LAVA_USER')
140 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200141 f = open('/var/run/lava/lava-user')
142 lava_user = f.read().strip()
143 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300144
Fathi Boudrac14068b2012-12-06 17:42:11 +0200145 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300146 lava_token = os.environ.get('LAVA_TOKEN')
147 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200148 f = open('/var/run/lava/lava-token')
149 lava_token = f.read().strip()
150 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200151
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300152 # LAVA server URL
153 lava_server = os.environ.get('LAVA_SERVER',
Fathi Boudra62997d92013-07-27 09:58:28 +0300154 'validation.linaro.org/RPC2/')
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300155 # LAVA server base URL
156 lava_server_root = lava_server.rstrip('/')
157 if lava_server_root.endswith('/RPC2'):
158 lava_server_root = lava_server_root[:-len('/RPC2')]
159
160 image_url = '%s/%s/pre-built/%s/%s/%s' % \
161 (snapshots_url,
162 distribution,
163 hwpack_type,
164 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200165 hwpack_file_name)
166
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300167 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530168
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200169 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300170 if distribution == 'openembedded':
171 tests = tests_openembedded_minimal
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300172 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300173 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300174
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300175 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200176 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300177 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500178
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300179 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200180 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300181 tests = tests_alip + tests
182
Fathi Boudra60d0e972013-04-19 10:49:47 +0300183 if 'lamp' in rootfs_type:
184 tests += tests_openembedded_lamp
185
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100186 if 'leg-java' in rootfs_type:
187 tests += tests_openembedded_leg_java
188
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300189 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200190 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300191 try:
192 tests.remove('bluetooth-enablement')
193 tests.remove('wifi-enablement')
194 except ValueError:
195 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300196
197 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200198 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300199 try:
200 tests.remove('pwrmgmt')
201 except ValueError:
202 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500203
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200204 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200205 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300206 'command': 'deploy_linaro_image',
207 'parameters': {
208 'image': '%s' % image_url,
209 },
210 'metadata': {
211 'hwpack.type': '%s' % hwpack_type,
212 'hwpack.build': '%s' % hwpack_build_number,
213 'rootfs.type': '%s' % rootfs_type,
214 'distribution': '%s' % distribution,
215 }
216 },
217 {
218 'command': 'boot_linaro_image',
219 'parameters': {
220 'options': ['boot_cmds=boot_cmds_oe']
221 }
222 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300223 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200224 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300225 'command': 'deploy_linaro_image',
226 'parameters': {
227 'image': '%s' % image_url,
228 },
229 'metadata': {
230 'ubuntu.name': '%s' % hwpack_type,
231 'ubuntu.build': '%s' % hwpack_build_number,
232 'rootfs.type': '%s' % rootfs_type,
233 'ubuntu.distribution': '%s' % distribution,
234 }
235 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200236
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200237 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300238 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300239 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530240 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300241 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300242 {'git-repo': git_repo,
243 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300244 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530245
Fathi Boudraebb2f192013-06-17 10:01:09 +0300246 actions.append({
247 'command': 'lava_test_shell',
248 'parameters': {
Fathi Boudrab088b142013-07-19 09:54:04 +0300249 'timeout': tests_timeout.get(test, 18000),
Fathi Boudraebb2f192013-06-17 10:01:09 +0300250 'testdef_repos': test_list
251 }
252 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200253
254 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300255 'command': 'submit_results',
256 'parameters': {
257 'stream': bundle_stream_name,
258 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200259 }
260 })
261
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300262 config = json.dumps({'timeout': 18000,
263 'actions': actions,
264 'job_name': '%s%s/%s/' % (ci_base_url,
265 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200266 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300267 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200268 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200269
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200270 print config
271
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300272 skip_lava = os.environ.get('SKIP_LAVA')
273 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200274 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200275 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300276 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200277 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300278 xmlrpclib.ServerProxy(server_url.format(
279 lava_user=lava_user,
280 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200281 lava_server=lava_server))
282 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200283 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300284 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200285 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200286
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300287 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200288 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300289 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200290 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300291 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200292
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300293 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
294 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200295 for root, dirs, files in os.walk(top_dir):
296 for file in files:
297 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300298 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200299
Fathi Boudrade020592012-12-10 13:25:14 +0200300 with open(lava_job_info_orig) as f:
301 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200302
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300303 buffer = buffer.replace(
304 'var lavaJobId = 0',
305 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200306
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300307 lava_job_info = lava_job_info_orig.replace(
308 '.html',
309 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200310 with open(lava_job_info, 'w') as f:
311 f.write(buffer)
312 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200313 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300314 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500315
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300316
317if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500318 main()