jjb: clean-up: remove deactivated fuzzing job
[lttng-ci.git] / scripts / system-tests / lava2-submit.py
CommitLineData
21fec189 1#!/usr/bin/python3
878b4840
JR
2# Copyright (C) 2016 - Francis Deslauriers <francis.deslauriers@efficios.com>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import argparse
878b4840
JR
18import json
19import os
20import random
21import sys
22import time
23import xmlrpc.client
6d3950a9
JR
24from urllib.parse import urljoin
25from urllib.request import urlretrieve
21fec189
JR
26import yaml
27from jinja2 import Environment, FileSystemLoader
878b4840 28
ef84c6ec
JR
29USERNAME = 'lava-jenkins'
30HOSTNAME = 'lava-master-02.internal.efficios.com'
0425e1dd 31OBJSTORE_URL = "https://obj.internal.efficios.com/lava/results/"
878b4840 32
f5f36c68
FD
33
34class TestType:
21fec189 35 """ Enum like for test type """
f5f36c68 36
21fec189
JR
37 baremetal_benchmarks = 1
38 baremetal_tests = 2
39 kvm_tests = 3
878b4840 40 values = {
f5f36c68
FD
41 'baremetal-benchmarks': baremetal_benchmarks,
42 'baremetal-tests': baremetal_tests,
43 'kvm-tests': kvm_tests,
878b4840
JR
44 }
45
f5f36c68
FD
46
47class DeviceType:
21fec189 48 """ Enum like for device type """
f5f36c68 49
4cb5cc4f 50 x86 = 'x86'
f9a184a9 51 kvm = 'qemu'
f5f36c68
FD
52 values = {'kvm': kvm, 'x86': x86}
53
4cb5cc4f 54
878b4840
JR
55def get_job_bundle_content(server, job):
56 try:
57 bundle_sha = server.scheduler.job_status(str(job))['bundle_sha1']
58 bundle = server.dashboard.get(bundle_sha)
21fec189
JR
59 except xmlrpc.client.Fault as error:
60 print('Error while fetching results bundle', error.faultString)
61 raise error
878b4840
JR
62
63 return json.loads(bundle['content'])
64
f5f36c68 65
878b4840 66def check_job_all_test_cases_state_count(server, job):
21fec189
JR
67 """
68 Parse the results bundle to see the run-tests testcase
69 of the lttng-kernel-tests passed successfully
70 """
0425e1dd
JR
71 print("Testcase result:")
72 content = server.results.get_testjob_results_yaml(str(job))
c2f8bcb9 73 testcases = yaml.unsafe_load(content)
878b4840 74
21fec189
JR
75 passed_tests = 0
76 failed_tests = 0
0425e1dd
JR
77 for testcase in testcases:
78 if testcase['result'] != 'pass':
f5f36c68
FD
79 print(
80 "\tFAILED {}\n\t\t See http://{}{}".format(
81 testcase['name'], HOSTNAME, testcase['url']
82 )
83 )
21fec189 84 failed_tests += 1
0425e1dd 85 else:
21fec189 86 passed_tests += 1
878b4840
JR
87 return (passed_tests, failed_tests)
88
f5f36c68 89
0425e1dd 90def fetch_benchmark_results(build_id):
21fec189
JR
91 """
92 Get the benchmark results from the objstore
93 save them as CSV files localy
94 """
f5f36c68
FD
95 testcases = [
96 'processed_results_close.csv',
97 'processed_results_ioctl.csv',
98 'processed_results_open_efault.csv',
99 'processed_results_open_enoent.csv',
100 'processed_results_dup_close.csv',
101 'processed_results_raw_syscall_getpid.csv',
102 'processed_results_lttng_test_filter.csv',
103 ]
0425e1dd
JR
104 for testcase in testcases:
105 url = urljoin(OBJSTORE_URL, "{:s}/{:s}".format(build_id, testcase))
935bfecd 106 print('Fetching {}'.format(url))
0425e1dd 107 urlretrieve(url, testcase)
878b4840 108
f5f36c68 109
878b4840 110def print_test_output(server, job):
21fec189
JR
111 """
112 Parse the attachment of the testcase to fetch the stdout of the test suite
113 """
0425e1dd 114 job_finished, log = server.scheduler.jobs.logs(str(job))
be7f51b6 115 logs = yaml.unsafe_load(log.data.decode('ascii'))
0425e1dd
JR
116 print_line = False
117 for line in logs:
118 if line['lvl'] != 'target':
119 continue
120 if line['msg'] == '<LAVA_SIGNAL_STARTTC run-tests>':
121 print('---- TEST SUITE OUTPUT BEGIN ----')
122 print_line = True
123 continue
124 if line['msg'] == '<LAVA_SIGNAL_ENDTC run-tests>':
125 print('----- TEST SUITE OUTPUT END -----')
d132001f
FD
126 print_line = False
127 continue
0425e1dd
JR
128 if print_line:
129 print("{} {}".format(line['dt'], line['msg']))
878b4840 130
f5f36c68
FD
131
132def get_vlttng_cmd(
133 lttng_tools_url, lttng_tools_commit, lttng_ust_url=None, lttng_ust_commit=None
134):
21fec189
JR
135 """
136 Return vlttng cmd to be used in the job template for setup.
137 """
878b4840 138
f5f36c68
FD
139 vlttng_cmd = (
140 'vlttng --jobs=$(nproc) --profile urcu-master'
141 ' --override projects.babeltrace.build-env.PYTHON=python3'
142 ' --override projects.babeltrace.build-env.PYTHON_CONFIG=python3-config'
143 ' --profile babeltrace-stable-1.4'
144 ' --profile babeltrace-python'
145 ' --profile lttng-tools-master'
146 ' --override projects.lttng-tools.source='
147 + lttng_tools_url
148 + ' --override projects.lttng-tools.checkout='
149 + lttng_tools_commit
150 + ' --profile lttng-tools-no-man-pages'
151 )
878b4840
JR
152
153 if lttng_ust_commit is not None:
f5f36c68
FD
154 vlttng_cmd += (
155 ' --profile lttng-ust-master '
156 ' --override projects.lttng-ust.source='
157 + lttng_ust_url
158 + ' --override projects.lttng-ust.checkout='
159 + lttng_ust_commit
160 + ' --profile lttng-ust-no-man-pages'
161 )
878b4840 162
888b31de 163 vlttng_path = '/tmp/virtenv'
c11ec858 164
4cb5cc4f 165 vlttng_cmd += ' ' + vlttng_path
878b4840 166
4cb5cc4f 167 return vlttng_cmd
878b4840 168
f5f36c68 169
878b4840 170def main():
9a49d69d 171 nfsrootfs = "https://obj.internal.efficios.com/lava/rootfs/rootfs_amd64_xenial_2018-12-05.tar.gz"
878b4840
JR
172 test_type = None
173 parser = argparse.ArgumentParser(description='Launch baremetal test using Lava')
174 parser.add_argument('-t', '--type', required=True)
175 parser.add_argument('-j', '--jobname', required=True)
176 parser.add_argument('-k', '--kernel', required=True)
878b4840 177 parser.add_argument('-lm', '--lmodule', required=True)
eb5bdbeb 178 parser.add_argument('-tu', '--tools-url', required=True)
878b4840 179 parser.add_argument('-tc', '--tools-commit', required=True)
6b35e57c 180 parser.add_argument('-id', '--build-id', required=True)
eb5bdbeb 181 parser.add_argument('-uu', '--ust-url', required=False)
878b4840 182 parser.add_argument('-uc', '--ust-commit', required=False)
f23dc688 183 parser.add_argument('-d', '--debug', required=False, action='store_true')
878b4840
JR
184 args = parser.parse_args()
185
186 if args.type not in TestType.values:
187 print('argument -t/--type {} unrecognized.'.format(args.type))
188 print('Possible values are:')
189 for k in TestType.values:
190 print('\t {}'.format(k))
191 return -1
878b4840
JR
192
193 lava_api_key = None
f23dc688
JR
194 if not args.debug:
195 try:
ef84c6ec 196 lava_api_key = os.environ['LAVA2_JENKINS_TOKEN']
21fec189 197 except Exception as error:
f5f36c68
FD
198 print(
199 'LAVA2_JENKINS_TOKEN not found in the environment variable. Exiting...',
200 error,
201 )
f23dc688 202 return -1
878b4840 203
4cb5cc4f 204 jinja_loader = FileSystemLoader(os.path.dirname(os.path.realpath(__file__)))
f5f36c68 205 jinja_env = Environment(loader=jinja_loader, trim_blocks=True, lstrip_blocks=True)
4cb5cc4f 206 jinja_template = jinja_env.get_template('template_lava_job.jinja2')
4cb5cc4f
JR
207
208 test_type = TestType.values[args.type]
209
210 if test_type in [TestType.baremetal_benchmarks, TestType.baremetal_tests]:
211 device_type = DeviceType.x86
878b4840 212 else:
4cb5cc4f 213 device_type = DeviceType.kvm
e640b6d8
JR
214
215 vlttng_path = '/tmp/virtenv'
4cb5cc4f 216
f5f36c68
FD
217 vlttng_cmd = get_vlttng_cmd(
218 args.tools_url, args.tools_commit, args.ust_url, args.ust_commit
219 )
4cb5cc4f
JR
220
221 context = dict()
222 context['DeviceType'] = DeviceType
223 context['TestType'] = TestType
224
225 context['job_name'] = args.jobname
226 context['test_type'] = test_type
4cb5cc4f
JR
227 context['random_seed'] = random.randint(0, 1000000)
228 context['device_type'] = device_type
229
230 context['vlttng_cmd'] = vlttng_cmd
231 context['vlttng_path'] = vlttng_path
232
233 context['kernel_url'] = args.kernel
234 context['nfsrootfs_url'] = nfsrootfs
235 context['lttng_modules_url'] = args.lmodule
6b35e57c 236 context['jenkins_build_id'] = args.build_id
4cb5cc4f
JR
237
238 context['kprobe_round_nb'] = 10
239
ef84c6ec
JR
240 render = jinja_template.render(context)
241
ef84c6ec
JR
242 print('Job to be submitted:')
243
244 print(render)
878b4840 245
f23dc688 246 if args.debug:
f23dc688
JR
247 return 0
248
f5f36c68
FD
249 server = xmlrpc.client.ServerProxy(
250 'http://%s:%s@%s/RPC2' % (USERNAME, lava_api_key, HOSTNAME)
251 )
878b4840 252
21fec189
JR
253 for attempt in range(10):
254 try:
255 jobid = server.scheduler.submit_job(render)
256 except xmlrpc.client.ProtocolError as error:
f5f36c68
FD
257 print(
258 'Protocol error on submit, sleeping and retrying. Attempt #{}'.format(
259 attempt
260 )
261 )
21fec189
JR
262 time.sleep(5)
263 continue
264 else:
265 break
878b4840
JR
266
267 print('Lava jobid:{}'.format(jobid))
f5f36c68
FD
268 print(
269 'Lava job URL: http://lava-master-02.internal.efficios.com/scheduler/job/{}'.format(
270 jobid
271 )
272 )
878b4840 273
f5f36c68 274 # Check the status of the job every 30 seconds
0425e1dd
JR
275 jobstatus = server.scheduler.job_state(jobid)['job_state']
276 running = False
21fec189 277 while jobstatus in ['Submitted', 'Scheduling', 'Scheduled', 'Running']:
0425e1dd 278 if not running and jobstatus == 'Running':
878b4840 279 print('Job started running')
0425e1dd 280 running = True
878b4840 281 time.sleep(30)
26cbe60b
JR
282 try:
283 jobstatus = server.scheduler.job_state(jobid)['job_state']
21fec189
JR
284 except xmlrpc.client.ProtocolError as error:
285 print('Protocol error, retrying')
286 continue
878b4840 287 print('Job ended with {} status.'.format(jobstatus))
0425e1dd
JR
288
289 if jobstatus != 'Finished':
878b4840 290 return -1
878b4840 291
0425e1dd
JR
292 if test_type is TestType.kvm_tests or test_type is TestType.baremetal_tests:
293 print_test_output(server, jobid)
294 elif test_type is TestType.baremetal_benchmarks:
295 fetch_benchmark_results(args.build_id)
296
21fec189 297 passed, failed = check_job_all_test_cases_state_count(server, jobid)
0425e1dd
JR
298 print('With {} passed and {} failed Lava test cases.'.format(passed, failed))
299
21fec189 300 if failed != 0:
0425e1dd 301 return -1
878b4840 302
21fec189
JR
303 return 0
304
f5f36c68 305
878b4840
JR
306if __name__ == "__main__":
307 sys.exit(main())
This page took 0.038538 seconds and 4 git commands to generate.