blob: 4cef61ce3b9cda3c9775dfa0e4461f78feadeda4 [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
27tests_openembedded = [
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020028 'device-tree',
29 'perf',
30 'pwrmgmt',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030031]
Andy Doan61b4d772012-04-24 10:03:28 -050032
Fathi Boudra8e4ce562012-12-08 14:35:17 +020033# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050034DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020035 'arndale': 'arndale',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020036 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030037 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020038 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050039 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050040 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020041 'rtsm_foundation-armv8': 'vexpress64',
42 'rtsm_ve-a15x1-a7x1': 'vexpress',
43 'rtsm_ve-a15x4-a7x4': 'vexpress',
44 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050045 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020046 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +030047 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020048 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -050049}
50
Andy Doan61b4d772012-04-24 10:03:28 -050051
52def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030053 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -050054
Fathi Boudrac14068b2012-12-06 17:42:11 +020055
Andy Doan61b4d772012-04-24 10:03:28 -050056def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +020057 """Script entry point: return some JSON based on calling args.
58 We should be called from Jenkins and expect the following to be defined:
59 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
60 """
Andy Doan61b4d772012-04-24 10:03:28 -050061
Fathi Boudrad1f9a862012-12-28 14:46:04 +020062 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030063 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020064 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +030065 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +020066
67 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +030068 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020069 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +030070 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020071 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +030072 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
73 if hwpack_file_name == 'Undefined':
74 sys.exit('Hardware pack is not defined.')
75
Fathi Boudra8e4ce562012-12-08 14:35:17 +020076 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +030077 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
78 if device_type == 'Undefined':
79 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +020080
81 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +030082 ret_split = hwpack_job_name.split('-', 2)
83 (distribution, architecture, hwpack_type) = \
84 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +020085 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +030086 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +020087 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +030088 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +020089 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +030090 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +020091
92 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +030093 bundle_stream_name = os.environ.get(
94 'BUNDLE_STREAM_NAME',
95 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
96
Fathi Boudrac14068b2012-12-06 17:42:11 +020097 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +030098 lava_user = os.environ.get('LAVA_USER')
99 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200100 f = open('/var/run/lava/lava-user')
101 lava_user = f.read().strip()
102 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300103
Fathi Boudrac14068b2012-12-06 17:42:11 +0200104 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300105 lava_token = os.environ.get('LAVA_TOKEN')
106 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200107 f = open('/var/run/lava/lava-token')
108 lava_token = f.read().strip()
109 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200110
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300111 # LAVA server URL
112 lava_server = os.environ.get('LAVA_SERVER',
113 'validation.linaro.org/lava-server/RPC2/')
114 # LAVA server base URL
115 lava_server_root = lava_server.rstrip('/')
116 if lava_server_root.endswith('/RPC2'):
117 lava_server_root = lava_server_root[:-len('/RPC2')]
118
119 image_url = '%s/%s/pre-built/%s/%s/%s' % \
120 (snapshots_url,
121 distribution,
122 hwpack_type,
123 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200124 hwpack_file_name)
125
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300126 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530127
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200128 # tests set specific to an image
Fathi Boudrac51e0912012-06-15 18:18:41 +0300129 tests = tests_nano
130
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300131 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200132 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300133 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500134
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300135 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200136 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300137 tests = tests_alip + tests
138
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300139 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200140 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300141 try:
142 tests.remove('bluetooth-enablement')
143 tests.remove('wifi-enablement')
144 except ValueError:
145 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300146
147 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200148 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300149 try:
150 tests.remove('pwrmgmt')
151 except ValueError:
152 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500153
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200154 if distribution == 'openembedded':
Fathi Boudrac14068b2012-12-06 17:42:11 +0200155 tests = tests_openembedded
Fathi Boudra4079a582012-12-06 19:42:58 +0200156 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300157 'command': 'deploy_linaro_image',
158 'parameters': {
159 'image': '%s' % image_url,
160 },
161 'metadata': {
162 'hwpack.type': '%s' % hwpack_type,
163 'hwpack.build': '%s' % hwpack_build_number,
164 'rootfs.type': '%s' % rootfs_type,
165 'distribution': '%s' % distribution,
166 }
167 },
168 {
169 'command': 'boot_linaro_image',
170 'parameters': {
171 'options': ['boot_cmds=boot_cmds_oe']
172 }
173 }]
174 else: # Distribution is Ubuntu
Fathi Boudra4079a582012-12-06 19:42:58 +0200175 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300176 'command': 'deploy_linaro_image',
177 'parameters': {
178 'image': '%s' % image_url,
179 },
180 'metadata': {
181 'ubuntu.name': '%s' % hwpack_type,
182 'ubuntu.build': '%s' % hwpack_build_number,
183 'rootfs.type': '%s' % rootfs_type,
184 'ubuntu.distribution': '%s' % distribution,
185 }
186 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200187
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200188 if len(tests) > 0:
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530189 test_list = []
190 for test in tests:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300191 test_list.append(
192 {'git-repo': git_repo,
193 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
194 distribution=distribution, test=test)})
195 actions.append({
196 'command': 'lava_test_shell',
197 'parameters': {
198 'timeout': 18000,
199 'testdef_repos': test_list
200 }
201 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200202
203 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300204 'command': 'submit_results',
205 'parameters': {
206 'stream': bundle_stream_name,
207 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200208 }
209 })
210
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300211 config = json.dumps({'timeout': 18000,
212 'actions': actions,
213 'job_name': '%s%s/%s/' % (ci_base_url,
214 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200215 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300216 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200217 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200218
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200219 print config
220
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300221 skip_lava = os.environ.get('SKIP_LAVA')
222 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200223 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200224 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300225 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200226 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300227 xmlrpclib.ServerProxy(server_url.format(
228 lava_user=lava_user,
229 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200230 lava_server=lava_server))
231 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200232 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300233 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200234 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200235
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300236 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200237 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300238 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200239 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300240 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200241
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300242 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
243 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200244 for root, dirs, files in os.walk(top_dir):
245 for file in files:
246 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300247 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200248
Fathi Boudrade020592012-12-10 13:25:14 +0200249 with open(lava_job_info_orig) as f:
250 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200251
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300252 buffer = buffer.replace(
253 'var lavaJobId = 0',
254 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200255
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300256 lava_job_info = lava_job_info_orig.replace(
257 '.html',
258 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200259 with open(lava_job_info, 'w') as f:
260 f.write(buffer)
261 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200262 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300263 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500264
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300265
266if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500267 main()