blob: 3eea655ab1e42d0ab765b1a0b92e458bdda0191a [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',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030014]
Fathi Boudrac14068b2012-12-06 17:42:11 +020015
16tests_alip = [
17 'bootchart',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030018]
Fathi Boudrac14068b2012-12-06 17:42:11 +020019
20tests_desktop = [
21 'e2eaudiotest',
22 'bluetooth-enablement',
23 'wifi-enablement',
24 'leb-basic-graphics',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030025]
Fathi Boudrac14068b2012-12-06 17:42:11 +020026
Fathi Boudra60d0e972013-04-19 10:49:47 +030027tests_openembedded_minimal = [
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020028 'busybox',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020029 'device-tree',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020030 'ethernet',
31 'kernel-version',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020032 'perf',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020033 'toolchain',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030034]
Andy Doan61b4d772012-04-24 10:03:28 -050035
Fathi Boudra60d0e972013-04-19 10:49:47 +030036tests_openembedded_lamp = [
37 'pwrmgmt',
38 'mysql',
39 'phpinfo',
40 'phpmysql',
41 'sdkhelloc',
42 'sdkhellocxx',
43]
44
Fathi Boudra8e4ce562012-12-08 14:35:17 +020045# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050046DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020047 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020048 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030049 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020050 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050051 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050052 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020053 'rtsm_foundation-armv8': 'vexpress64',
54 'rtsm_ve-a15x1-a7x1': 'vexpress',
55 'rtsm_ve-a15x4-a7x4': 'vexpress',
56 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050057 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020058 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030059 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020060 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050061}
62
Andy Doan61b4d772012-04-24 10:03:28 -050063
64def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030065 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050066
Fathi Boudrac14068b2012-12-06 17:42:11 +020067
Andy Doan61b4d772012-04-24 10:03:28 -050068def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +020069 """Script entry point: return some JSON based on calling args.
70 We should be called from Jenkins and expect the following to be defined:
71 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
72 """
Andy Doan61b4d772012-04-24 10:03:28 -050073
Fathi Boudrad1f9a862012-12-28 14:46:04 +020074 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030075 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020076 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030077 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020078
79 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +030080 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020081 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +030082 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020083 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +030084 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
85 if hwpack_file_name == 'Undefined':
86 sys.exit('Hardware pack is not defined.')
87
Fathi Boudra8e4ce562012-12-08 14:35:17 +020088 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +030089 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
90 if device_type == 'Undefined':
91 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020092
93 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +030094 ret_split = hwpack_job_name.split('-', 2)
95 (distribution, architecture, hwpack_type) = \
96 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +020097 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030098 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +020099 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300100 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200101 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300102 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200103
104 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300105 bundle_stream_name = os.environ.get(
106 'BUNDLE_STREAM_NAME',
107 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
108
Fathi Boudrac14068b2012-12-06 17:42:11 +0200109 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300110 lava_user = os.environ.get('LAVA_USER')
111 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200112 f = open('/var/run/lava/lava-user')
113 lava_user = f.read().strip()
114 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300115
Fathi Boudrac14068b2012-12-06 17:42:11 +0200116 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300117 lava_token = os.environ.get('LAVA_TOKEN')
118 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200119 f = open('/var/run/lava/lava-token')
120 lava_token = f.read().strip()
121 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200122
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300123 # LAVA server URL
124 lava_server = os.environ.get('LAVA_SERVER',
125 'validation.linaro.org/lava-server/RPC2/')
126 # LAVA server base URL
127 lava_server_root = lava_server.rstrip('/')
128 if lava_server_root.endswith('/RPC2'):
129 lava_server_root = lava_server_root[:-len('/RPC2')]
130
131 image_url = '%s/%s/pre-built/%s/%s/%s' % \
132 (snapshots_url,
133 distribution,
134 hwpack_type,
135 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200136 hwpack_file_name)
137
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300138 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530139
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200140 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300141 if distribution == 'openembedded':
142 tests = tests_openembedded_minimal
143 elif distribution == 'ubuntu' or distribution == 'quantal':
144 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300145
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300146 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200147 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300148 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500149
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300150 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200151 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300152 tests = tests_alip + tests
153
Fathi Boudra60d0e972013-04-19 10:49:47 +0300154 if 'lamp' in rootfs_type:
155 tests += tests_openembedded_lamp
156
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300157 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200158 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300159 try:
160 tests.remove('bluetooth-enablement')
161 tests.remove('wifi-enablement')
162 except ValueError:
163 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300164
165 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200166 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300167 try:
168 tests.remove('pwrmgmt')
169 except ValueError:
170 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500171
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200172 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200173 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300174 'command': 'deploy_linaro_image',
175 'parameters': {
176 'image': '%s' % image_url,
177 },
178 'metadata': {
179 'hwpack.type': '%s' % hwpack_type,
180 'hwpack.build': '%s' % hwpack_build_number,
181 'rootfs.type': '%s' % rootfs_type,
182 'distribution': '%s' % distribution,
183 }
184 },
185 {
186 'command': 'boot_linaro_image',
187 'parameters': {
188 'options': ['boot_cmds=boot_cmds_oe']
189 }
190 }]
Fathi Boudra60d0e972013-04-19 10:49:47 +0300191 elif distribution == 'ubuntu' or distribution == 'quantal':
Fathi Boudra4079a582012-12-06 19:42:58 +0200192 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300193 'command': 'deploy_linaro_image',
194 'parameters': {
195 'image': '%s' % image_url,
196 },
197 'metadata': {
198 'ubuntu.name': '%s' % hwpack_type,
199 'ubuntu.build': '%s' % hwpack_build_number,
200 'rootfs.type': '%s' % rootfs_type,
201 'ubuntu.distribution': '%s' % distribution,
202 }
203 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200204
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200205 if len(tests) > 0:
Fathi Boudra60d0e972013-04-19 10:49:47 +0300206 if distribution == 'quantal':
207 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530208 test_list = []
209 for test in tests:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300210 test_list.append(
211 {'git-repo': git_repo,
212 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
213 distribution=distribution, test=test)})
Senthil Kumaran007181c2013-04-16 14:43:19 +0530214
215 actions.append({
Fathi Boudra60d0e972013-04-19 10:49:47 +0300216 'command': 'lava_test_shell',
217 'parameters': {
218 'timeout': 18000,
219 'testdef_repos': test_list
220 }
221 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200222
223 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300224 'command': 'submit_results',
225 'parameters': {
226 'stream': bundle_stream_name,
227 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200228 }
229 })
230
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300231 config = json.dumps({'timeout': 18000,
232 'actions': actions,
233 'job_name': '%s%s/%s/' % (ci_base_url,
234 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200235 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300236 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200237 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200238
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200239 print config
240
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300241 skip_lava = os.environ.get('SKIP_LAVA')
242 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200243 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200244 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300245 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200246 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300247 xmlrpclib.ServerProxy(server_url.format(
248 lava_user=lava_user,
249 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200250 lava_server=lava_server))
251 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200252 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300253 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200254 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200255
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300256 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200257 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300258 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200259 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300260 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200261
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300262 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
263 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200264 for root, dirs, files in os.walk(top_dir):
265 for file in files:
266 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300267 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200268
Fathi Boudrade020592012-12-10 13:25:14 +0200269 with open(lava_job_info_orig) as f:
270 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200271
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300272 buffer = buffer.replace(
273 'var lavaJobId = 0',
274 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200275
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300276 lava_job_info = lava_job_info_orig.replace(
277 '.html',
278 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200279 with open(lava_job_info, 'w') as f:
280 f.write(buffer)
281 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200282 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300283 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500284
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300285
286if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500287 main()