blob: d3d56f631da034cf243091b3a978ae95c6fd79d9 [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
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010045tests_openembedded_leg_java = [
46 # placeholder tests for leg_java
47 'sdkhelloc',
48 'sdkhellocxx',
49]
50
Fathi Boudra8e4ce562012-12-08 14:35:17 +020051# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050052DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020053 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020054 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030055 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020056 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050057 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050058 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020059 'rtsm_foundation-armv8': 'vexpress64',
60 'rtsm_ve-a15x1-a7x1': 'vexpress',
61 'rtsm_ve-a15x4-a7x4': 'vexpress',
62 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050063 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020064 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030065 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020066 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050067}
68
Andy Doan61b4d772012-04-24 10:03:28 -050069
70def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030071 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050072
Fathi Boudrac14068b2012-12-06 17:42:11 +020073
Andy Doan61b4d772012-04-24 10:03:28 -050074def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +020075 """Script entry point: return some JSON based on calling args.
76 We should be called from Jenkins and expect the following to be defined:
77 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
78 """
Andy Doan61b4d772012-04-24 10:03:28 -050079
Fathi Boudrad1f9a862012-12-28 14:46:04 +020080 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030081 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020082 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030083 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020084
85 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +030086 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020087 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +030088 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020089 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +030090 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
91 if hwpack_file_name == 'Undefined':
92 sys.exit('Hardware pack is not defined.')
93
Fathi Boudra8e4ce562012-12-08 14:35:17 +020094 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +030095 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
96 if device_type == 'Undefined':
97 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020098
99 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300100 ret_split = hwpack_job_name.split('-', 2)
101 (distribution, architecture, hwpack_type) = \
102 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200103 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300104 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200105 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300106 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200107 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300108 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200109
110 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300111 bundle_stream_name = os.environ.get(
112 'BUNDLE_STREAM_NAME',
113 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
114
Fathi Boudrac14068b2012-12-06 17:42:11 +0200115 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300116 lava_user = os.environ.get('LAVA_USER')
117 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200118 f = open('/var/run/lava/lava-user')
119 lava_user = f.read().strip()
120 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300121
Fathi Boudrac14068b2012-12-06 17:42:11 +0200122 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300123 lava_token = os.environ.get('LAVA_TOKEN')
124 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200125 f = open('/var/run/lava/lava-token')
126 lava_token = f.read().strip()
127 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200128
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300129 # LAVA server URL
130 lava_server = os.environ.get('LAVA_SERVER',
131 'validation.linaro.org/lava-server/RPC2/')
132 # LAVA server base URL
133 lava_server_root = lava_server.rstrip('/')
134 if lava_server_root.endswith('/RPC2'):
135 lava_server_root = lava_server_root[:-len('/RPC2')]
136
137 image_url = '%s/%s/pre-built/%s/%s/%s' % \
138 (snapshots_url,
139 distribution,
140 hwpack_type,
141 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200142 hwpack_file_name)
143
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300144 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530145
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200146 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300147 if distribution == 'openembedded':
148 tests = tests_openembedded_minimal
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300149 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300150 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300151
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300152 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200153 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300154 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500155
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300156 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200157 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300158 tests = tests_alip + tests
159
Fathi Boudra60d0e972013-04-19 10:49:47 +0300160 if 'lamp' in rootfs_type:
161 tests += tests_openembedded_lamp
162
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100163 if 'leg-java' in rootfs_type:
164 tests += tests_openembedded_leg_java
165
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300166 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200167 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300168 try:
169 tests.remove('bluetooth-enablement')
170 tests.remove('wifi-enablement')
171 except ValueError:
172 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300173
174 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200175 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300176 try:
177 tests.remove('pwrmgmt')
178 except ValueError:
179 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500180
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200181 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200182 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300183 'command': 'deploy_linaro_image',
184 'parameters': {
185 'image': '%s' % image_url,
186 },
187 'metadata': {
188 'hwpack.type': '%s' % hwpack_type,
189 'hwpack.build': '%s' % hwpack_build_number,
190 'rootfs.type': '%s' % rootfs_type,
191 'distribution': '%s' % distribution,
192 }
193 },
194 {
195 'command': 'boot_linaro_image',
196 'parameters': {
197 'options': ['boot_cmds=boot_cmds_oe']
198 }
199 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300200 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200201 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300202 'command': 'deploy_linaro_image',
203 'parameters': {
204 'image': '%s' % image_url,
205 },
206 'metadata': {
207 'ubuntu.name': '%s' % hwpack_type,
208 'ubuntu.build': '%s' % hwpack_build_number,
209 'rootfs.type': '%s' % rootfs_type,
210 'ubuntu.distribution': '%s' % distribution,
211 }
212 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200213
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200214 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300215 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300216 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530217 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300218 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300219 {'git-repo': git_repo,
220 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300221 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530222
Fathi Boudraebb2f192013-06-17 10:01:09 +0300223 actions.append({
224 'command': 'lava_test_shell',
225 'parameters': {
226 'timeout': 18000,
227 'testdef_repos': test_list
228 }
229 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200230
231 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300232 'command': 'submit_results',
233 'parameters': {
234 'stream': bundle_stream_name,
235 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200236 }
237 })
238
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300239 config = json.dumps({'timeout': 18000,
240 'actions': actions,
241 'job_name': '%s%s/%s/' % (ci_base_url,
242 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200243 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300244 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200245 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200246
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200247 print config
248
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300249 skip_lava = os.environ.get('SKIP_LAVA')
250 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200251 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200252 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300253 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200254 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300255 xmlrpclib.ServerProxy(server_url.format(
256 lava_user=lava_user,
257 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200258 lava_server=lava_server))
259 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200260 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300261 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200262 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200263
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300264 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200265 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300266 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200267 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300268 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200269
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300270 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
271 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200272 for root, dirs, files in os.walk(top_dir):
273 for file in files:
274 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300275 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200276
Fathi Boudrade020592012-12-10 13:25:14 +0200277 with open(lava_job_info_orig) as f:
278 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200279
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300280 buffer = buffer.replace(
281 'var lavaJobId = 0',
282 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200283
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300284 lava_job_info = lava_job_info_orig.replace(
285 '.html',
286 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200287 with open(lava_job_info, 'w') as f:
288 f.write(buffer)
289 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200290 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300291 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500292
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300293
294if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500295 main()