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