summaryrefslogtreecommitdiff
path: root/lava-submit.py
blob: ff9315e0ffb76d44418f04e94ed564df543e7b6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/python

import os
import sys
import json
import xmlrpclib
import re

tests_timeout = {
    'bluetooth-enablement': 7200,
    'bootchart': 800,
    'busybox': 800,
    'cyclictest': 90000,
    'device-tree': 800,
    'e2eaudiotest': 7200,
    'ethernet': 800,
    'gatortests': 1200,
    'jtreg-hotspot-compiler': 64800,
    'jtreg-hotspot-gc': 14400,
    'jtreg-hotspot-runtime': 36000,
    'jtreg-hotspot-sanity': 7200,
    'jtreg-hotspot-serviceability': 7200,
    'jtreg-hotspot-testlibrary': 7200,
    'kernel-version': 800,
    'leb-basic-graphics': 7200,
    'ltp': 7200,
    'mysql': 800,
    'network-tests-basic': 1200,
    'perf': 800,
    'phpinfo': 800,
    'phpmysql': 800,
    'pwrmgmt': 1200,
    'sdkhelloc': 800,
    'sdkhellocxx': 800,
    'smoke-tests-basic': 1200,
    'toolchain': 800,
    'wifi-enablement': 7200,
}

tests_nano = [
    'device-tree',
    'gatortests',
    'network-tests-basic',
    'perf',
    'pwrmgmt',
    'smoke-tests-basic',
]

tests_alip = [
    'bootchart',
]

tests_desktop = [
    'e2eaudiotest',
    'bluetooth-enablement',
    'wifi-enablement',
    'leb-basic-graphics',
]

tests_openembedded_minimal = [
    'busybox',
    'device-tree',
    'ethernet',
    'kernel-version',
    'perf',
    'toolchain',
]

tests_openembedded_lamp = [
    'mysql',
    'phpinfo',
    'phpmysql',
    'sdkhelloc',
    'sdkhellocxx',
]

tests_openembedded_leg_java = [
    'openjdk8-sanity',
    'mauve-setup',
    'mauve-BinaryCompatibility',
    'mauve-BinaryCompatibility-altered',
    'mauve-gnu-java',
    'mauve-gnu-javax',
    'mauve-java-awt',
    'mauve-java-beans',
    'mauve-java-io',
    'mauve-java-lang',
    'mauve-java-math',
    'mauve-java-net',
    'mauve-java-nio',
    'mauve-java-rmi',
    'mauve-java-security',
    'mauve-java-sql',
    'mauve-java-text',
    'mauve-java-util',
    'mauve-javax-accessibility',
    'mauve-javax-crypto',
    'mauve-javax-imageio',
    'mauve-javax-management',
    'mauve-javax-naming',
    'mauve-javax-net',
    'mauve-javax-print',
    'mauve-javax-rmi',
    'mauve-javax-security',
    'mauve-javax-sound',
    'mauve-javax-swing',
    'mauve-javax-xml',
    'mauve-locales',
    'mauve-org-omg',
    'mauve-org-w3c',
    'jtreg-hotspot-compiler',
    'jtreg-hotspot-gc',
    'jtreg-hotspot-runtime',
    'jtreg-hotspot-sanity',
    'jtreg-hotspot-serviceability',
    'jtreg-hotspot-testlibrary',
]

# Mapping device type - bundle stream
DEVICE_STREAM = {
    'arndale': 'arndale',
    'arndale-octa': 'arndale-octa',
    'beaglebone-black': 'beaglebone',
    'beaglexm': 'beaglexm',
    'highbank': 'highbank',
    'midway': 'midway',
    'origen': 'leb-origen',
    'panda': 'leb-panda-4430',
    'panda-es': 'leb-panda-es',
    'rtsm_foundation-armv8': 'vexpress64',
    'rtsm_fvp_base-aemv8a': 'vexpress64',
    'rtsm_fvp_base_cortex-a57x1-a53x1': 'vexpress64',
    'rtsm_fvp_base_cortex-a57x4-a53x4': 'vexpress64',
    'rtsm_ve-a15x1-a7x1': 'vexpress',
    'rtsm_ve-a15x4-a7x4': 'vexpress',
    'rtsm_ve-armv8': 'vexpress64',
    'snowball_sd': 'leb-snowball',
    'vexpress-a5': 'vexpress',
    'vexpress-a9': 'vexpress',
    'vexpress-tc2': 'vexpress',
}


def obfuscate_credentials(s):
    return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)


def main():
    """Script entry point: return some JSON based on calling args.
    We should be called from Jenkins and expect the following to be defined:
    $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
    """

    # CI base URL
    ci_base_url = 'https://ci.linaro.org/jenkins/job/'
    # Snapshots base URL
    snapshots_url = 'http://snapshots.linaro.org'

    # Name of the hardware pack project
    hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
    # The hardware pack build number
    hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
    # Hardware pack file name
    hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
    if hwpack_file_name == 'Undefined':
        sys.exit('Hardware pack is not defined.')

    # Device type
    device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
    if device_type == 'Undefined':
        sys.exit('Device type is not defined.')

    # Distribution, architecture and hardware pack type
    ret_split = hwpack_job_name.split('-', 2)
    (distribution, architecture, hwpack_type) = \
        ret_split[0], ret_split[1], ret_split[2]
    if hwpack_type.startswith('pre-built-images-'):
        hwpack_type = hwpack_type[(len('pre-built-images-')):]
    if '=' in hwpack_type:
        hwpack_type = hwpack_type[(len('pre-built-images/')):]
        ret_split = dict(
            token.split('=') for token in hwpack_type.split(','))
        hwpack_type = ret_split['hwpack']

    # Rootfs type, default is developer
    rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')

    # Bundle stream name
    bundle_stream_name = os.environ.get(
        'BUNDLE_STREAM_NAME',
        '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])

    # LAVA user
    lava_user = os.environ.get('LAVA_USER')
    if lava_user is None:
        f = open('/var/run/lava/lava-user')
        lava_user = f.read().strip()
        f.close()

    # LAVA token
    lava_token = os.environ.get('LAVA_TOKEN')
    if lava_token is None:
        f = open('/var/run/lava/lava-token')
        lava_token = f.read().strip()
        f.close()

    # LAVA server URL
    lava_server = os.environ.get('LAVA_SERVER',
                                 'validation.linaro.org/RPC2/')
    # LAVA server base URL
    lava_server_root = lava_server.rstrip('/')
    if lava_server_root.endswith('/RPC2'):
        lava_server_root = lava_server_root[:-len('/RPC2')]

    image_url = '%s/%s/pre-built/%s/%s/%s' % \
                (snapshots_url,
                 distribution,
                 hwpack_type,
                 hwpack_build_number,
                 hwpack_file_name)

    git_repo = 'git://git.linaro.org/qa/test-definitions.git'

    lava_test_plan = os.environ.get('LAVA_TEST_PLAN')
    if lava_test_plan is None:
        # tests set specific to an image
        if distribution == 'openembedded':
            tests = tests_openembedded_minimal
            if 'lamp' in rootfs_type:
                tests += tests_openembedded_lamp
            if 'leg-java' in rootfs_type:
                tests += tests_openembedded_leg_java
        elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
            tests = tests_nano
            # if ubuntu-desktop, cover more test cases (LEB)
            if rootfs_type == 'ubuntu-desktop':
                tests += tests_desktop
            # if alip, specific tests like bootchart (which should be first)
            if rootfs_type == 'alip':
                tests = tests_alip + tests
    else:
        lava_test_plan = lava_test_plan.strip("'")
        tests = lava_test_plan.split()

    # removing bluetooth and wifi for devices that don't support it
    if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
        try:
            tests.remove('bluetooth-enablement')
            tests.remove('wifi-enablement')
        except ValueError:
            pass

    # vexpress doesn't support PM, so disable pwrmgmt
    if device_type in ['vexpress-a9']:
        try:
            tests.remove('pwrmgmt')
        except ValueError:
            pass

    if distribution == 'openembedded':
        actions = [{
                       'command': 'deploy_linaro_image',
                       'parameters': {
                           'image': '%s' % image_url,
                       },
                       'metadata': {
                           'hwpack.type': '%s' % hwpack_type,
                           'hwpack.build': '%s' % hwpack_build_number,
                           'rootfs.type': '%s' % rootfs_type,
                           'distribution': '%s' % distribution,
                       }
                   },
                   {
                       'command': 'boot_linaro_image'
                   }]

        bootloader = os.environ.get('BOOTLOADER')
        if bootloader is not None:
            actions[0]['parameters'].update(json.loads('{"bootloadertype": "%s"}' % bootloader))

    elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
        actions = [{
                       'command': 'deploy_linaro_image',
                       'parameters': {
                           'image': '%s' % image_url,
                       },
                       'metadata': {
                           'ubuntu.name': '%s' % hwpack_type,
                           'ubuntu.build': '%s' % hwpack_build_number,
                           'rootfs.type': '%s' % rootfs_type,
                           'ubuntu.distribution': '%s' % distribution,
                       }
                   }]

    if len(tests) > 0:
        if distribution == 'quantal' or distribution == 'raring':
            distribution = 'ubuntu'
        for test in tests:
            test_list = [(
                {'git-repo': git_repo,
                 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
                     distribution=distribution, test=test)})]

            actions.append({
                'command': 'lava_test_shell',
                'parameters': {
                    'timeout': tests_timeout.get(test, 18000),
                    'testdef_repos': test_list
                }
            })

    actions.append({
        'command': 'submit_results',
        'parameters': {
            'stream': bundle_stream_name,
            'server': '%s%s' % ('http://', lava_server)
        }
    })

    # XXX Global timeout in LAVA is hardcoded to 24h (24 * 60 60)
    # https://bugs.launchpad.net/bugs/1226017
    # Set to 172800s (48h) to workaround the limitation
    # A sane default is 900s (15m)
    config = json.dumps({'timeout': 172800,
                         'actions': actions,
                         'job_name': '%s%s/%s/' % (ci_base_url,
                                                   hwpack_job_name,
                                                   hwpack_build_number),
                         'device_type': device_type,
                        }, indent=2)

    print config

    skip_lava = os.environ.get('SKIP_LAVA')
    if skip_lava is None:
        try:
            server_url = \
                'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
            server = \
                xmlrpclib.ServerProxy(server_url.format(
                    lava_user=lava_user,
                    lava_token=lava_token,
                    lava_server=lava_server))
            lava_job_id = server.scheduler.submit_job(config)
        except xmlrpclib.ProtocolError, e:
            print 'Error making a LAVA request:', obfuscate_credentials(str(e))
            sys.exit(1)

        print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
              (lava_job_id, lava_server_root, lava_job_id)
        json.dump({'lava_url': 'http://' + lava_server_root,
                   'job_id': lava_job_id},
                  open('lava-job-info', 'w'))

        lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
        top_dir = os.environ.get('WORKSPACE', '.')
        for root, dirs, files in os.walk(top_dir):
            for file in files:
                if file == lava_job_info_orig:
                    lava_job_info_orig = os.path.join(root, file)

                    with open(lava_job_info_orig) as f:
                        buffer = f.read()

                    buffer = buffer.replace(
                        'var lavaJobId = 0',
                        'var lavaJobId = ' + str(lava_job_id), 1)

                    lava_job_info = lava_job_info_orig.replace(
                        '.html',
                        '-' + device_type + '.html')
                    with open(lava_job_info, 'w') as f:
                        f.write(buffer)
                    os.remove(lava_job_info_orig)
    else:
        print 'LAVA job submission skipped.'


if __name__ == '__main__':
    main()