blob: 775b90103ec3b92b1ae895a735cb90d7f524f941 [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001package com.mirantis.system_qa
2
Dennis Dmitriev27a96792018-07-30 07:52:03 +03003import groovy.xml.XmlUtil
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03004
Dennis Dmitriev8df35442018-07-31 08:40:20 +03005def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03006 def common = new com.mirantis.mk.Common()
7 common.printMsg("Run shell command:\n" + cmd, "blue")
8 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +03009 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030010 script = """\
11 set +x;
12 echo 'activate python virtualenv ${VENV_PATH}';
13 . ${VENV_PATH}/bin/activate;
Dennis Dmitriev8df35442018-07-31 08:40:20 +030014 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030015 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030016 def result
17 try {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030018 return sh(script: script, returnStdout: returnStdout)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030019 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030020 def stderr = readFile("${stderr_path}")
21 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
22 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030023 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030024 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030025 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030026}
27
28def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030029 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030030}
31
Dennis Dmitriev27a96792018-07-30 07:52:03 +030032def build_pipeline_job(job_name, parameters) {
33 //Build a job, grab the results if failed and use the results in exception
34 def common = new com.mirantis.mk.Common()
35 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
36 common.prettyPrint(parameters)
37
38 def job_info = build job: "${job_name}",
39 parameters: parameters,
40 propagate: false
41
42 if (job_info.getResult() != "SUCCESS") {
43 currentBuild.result = job_info.getResult()
44 def build_number = job_info.getNumber()
45 common.printMsg("Job '${job_name}' failed, getting details", "red")
46 def workflow_details=run_cmd_stdout("""\
47 export JOB_NAME=${job_name}
48 export BUILD_NUMBER=${build_number}
49 python ./tcp_tests/utils/get_jenkins_job_stages.py
50 """)
51 throw new Exception(workflow_details)
52 }
53}
54
55def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
56 //Build a job, grab the results if failed and use the results in exception
57 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
58 def common = new com.mirantis.mk.Common()
59 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
60 common.prettyPrint(parameters)
61
62 def job_info = build job: "${job_name}",
63 parameters: parameters,
64 propagate: false
65
66 if (job_info.getResult() != "SUCCESS") {
67 def build_status = job_info.getResult()
68 def build_number = job_info.getNumber()
69 def build_url = job_info.getAbsoluteUrl()
70 def job_url = "${build_url}"
71 currentBuild.result = build_status
72 if (junit_report_filename) {
73 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "red")
74 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
75 projectName: job_name,
76 selector: specific("${build_number}"),
77 filter: "${junit_report_source_dir}/${junit_report_filename}",
78 target: '.',
79 flatten: true,
80 fingerprintArtifacts: true)
81
82 def String junit_report_xml = readFile("${junit_report_filename}")
83 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
Dennis Dmitriev3f9329c2018-08-30 18:17:49 +030084 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
85 def String junit_report_xml_filtered = junit_report_xml_pretty.replaceAll("<","&lt;").replaceAll(">", "&gt;")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030086 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitriev39666082018-08-29 15:30:45 +030087 throw new Exception(msg + junit_report_xml_filtered)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030088 } else {
89 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
90 }
91 }
92}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030093
94def prepare_working_dir() {
95 println "Clean the working directory ${env.WORKSPACE}"
96 deleteDir()
97
Dennis Dmitriev27a96792018-07-30 07:52:03 +030098 // do not fail if environment doesn't exists
99 println "Remove environment ${ENV_NAME}"
100 run_cmd("""\
101 dos.py erase ${ENV_NAME} || true
102 """)
103 println "Remove config drive ISO"
104 run_cmd("""\
105 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
106 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300107
108 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300109 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
110 if [ -n "$TCP_QA_REFS" ]; then
111 set -e
112 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
113 fi
114 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300115 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300116}
117
118def swarm_bootstrap_salt_cluster_devops() {
119 def common = new com.mirantis.mk.Common()
120 def parameters = [
121 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
122 string(name: 'PARENT_WORKSPACE', value: pwd()),
123 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
124 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
125 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
126 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
127 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
128 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
129 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
130 string(name: 'PIPELINE_LIBRARY_REF', value: "${PIPELINE_LIBRARY_REF}"),
131 string(name: 'MK_PIPELINES_REF', value: "${MK_PIPELINES_REF}"),
132 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${COOKIECUTTER_TEMPLATE_COMMIT}"),
133 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${SALT_MODELS_SYSTEM_COMMIT}"),
134 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
135 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300136
137 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300138}
139
140def swarm_deploy_cicd(String stack_to_install='core,cicd') {
141 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
142 def common = new com.mirantis.mk.Common()
143 def parameters = [
144 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
145 string(name: 'PARENT_WORKSPACE', value: pwd()),
146 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
147 string(name: 'STACK_INSTALL', value: stack_to_install),
148 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
149 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
150 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300151 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300152}
153
154def swarm_deploy_platform(String stack_to_install) {
155 // Run openstack_deploy job on CICD Jenkins for specified stacks
156 def common = new com.mirantis.mk.Common()
157 def parameters = [
158 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
159 string(name: 'PARENT_WORKSPACE', value: pwd()),
160 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
161 string(name: 'STACK_INSTALL', value: stack_to_install),
162 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
163 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
164 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300165 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300166}
167
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300168def swarm_run_pytest(String passed_steps) {
169 // Run pytest tests
170 def common = new com.mirantis.mk.Common()
171 def parameters = [
172 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
173 string(name: 'PASSED_STEPS', value: passed_steps),
174 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
175 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
176 string(name: 'PARENT_WORKSPACE', value: pwd()),
177 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
178 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
179 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
180 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
181 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
182 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
183 ]
184 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
185 common.prettyPrint(parameters)
186 build job: 'swarm-run-pytest',
187 parameters: parameters
188}
189
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300190def swarm_testrail_report(String passed_steps) {
191 // Run pytest tests
192 def common = new com.mirantis.mk.Common()
193 def parameters = [
194 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
195 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
196 string(name: 'PASSED_STEPS', value: passed_steps),
197 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
198 string(name: 'PARENT_WORKSPACE', value: pwd()),
199 string(name: 'TCP_QA_REFS', value: "${TCP_QA_REFS}"),
200 ]
201 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
202 common.prettyPrint(parameters)
203 build job: 'swarm-testrail-report',
204 parameters: parameters
205}
206
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300207def generate_cookied_model() {
208 def common = new com.mirantis.mk.Common()
209 // do not fail if environment doesn't exists
210 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
211 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
212 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
213 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
214 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
215 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
216 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
217 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
218
219 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
220 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
221
222 def parameters = [
223 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
224 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
225 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
226 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
227 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
228 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
229 string(name: 'TCP_QA_REVIEW', value: "${TCP_QA_REFS}"),
230 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
231 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
232 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
233 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
234 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300235
236 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300237}
238
239def generate_configdrive_iso() {
240 def common = new com.mirantis.mk.Common()
241 def SALT_MASTER_IP=run_cmd_stdout("""\
242 export ENV_NAME=${ENV_NAME}
243 . ./tcp_tests/utils/env_salt
244 echo \$SALT_MASTER_IP
245 """).trim().split().last()
246 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
247 def parameters = [
248 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
249 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
250 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
251 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
252 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
253 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
254 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
255 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
256 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
257 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
258 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
259 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
260 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
261 string(name: 'PIPELINE_LIBRARY_REF', value: "${PIPELINE_LIBRARY_REF}"),
262 string(name: 'MK_PIPELINES_REF', value: "${MK_PIPELINES_REF}"),
263 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300264 build_pipeline_job('create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300265}
266
267def run_job_on_day01_node(stack_to_install, timeout=1800) {
268 // stack_to_install="core,cicd"
269 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300270 try {
271 run_cmd("""\
272 export ENV_NAME=${ENV_NAME}
273 . ./tcp_tests/utils/env_salt
274 . ./tcp_tests/utils/env_jenkins_day01
275 export JENKINS_BUILD_TIMEOUT=${timeout}
276 JOB_PARAMETERS=\"{
277 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
278 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
279 }\"
280 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
281 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
282 """)
283 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300284 def common = new com.mirantis.mk.Common()
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300285 common.printMsg("Product job 'deploy_openstack' failed, getting details", "red")
286 def workflow_details=run_cmd_stdout("""\
287 . ./tcp_tests/utils/env_salt
288 . ./tcp_tests/utils/env_jenkins_day01
289 export JOB_NAME=deploy_openstack
290 export BUILD_NUMBER=lastBuild
291 python ./tcp_tests/utils/get_jenkins_job_stages.py
292 """)
293 throw new Exception(workflow_details)
294 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300295}
296
297def run_job_on_cicd_nodes(stack_to_install, timeout=1800) {
298 // stack_to_install="k8s,calico,stacklight"
299 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300300 try {
301 run_cmd("""\
302 export ENV_NAME=${ENV_NAME}
303 . ./tcp_tests/utils/env_salt
304 . ./tcp_tests/utils/env_jenkins_cicd
305 export JENKINS_BUILD_TIMEOUT=${timeout}
306 JOB_PARAMETERS=\"{
307 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
308 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
309 }\"
310 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
311 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
312 sleep 60 # Wait for IO calm down on cluster nodes
313 """)
314 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300315 def common = new com.mirantis.mk.Common()
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300316 common.printMsg("Product job 'deploy_openstack' failed, getting details", "red")
317 def workflow_details=run_cmd_stdout("""\
318 . ./tcp_tests/utils/env_salt
319 . ./tcp_tests/utils/env_jenkins_cicd
320 export JOB_NAME=deploy_openstack
321 export BUILD_NUMBER=lastBuild
322 python ./tcp_tests/utils/get_jenkins_job_stages.py
323 """)
324 throw new Exception(workflow_details)
325 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300326}
327
328def sanity_check_component(stack) {
329 // Run sanity check for the component ${stack}.
330 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300331 try {
332 run_cmd("""\
333 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
334 """)
335 } catch (e) {
336 def String junit_report_xml = readFile("deploy_${stack}.xml")
337 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
338 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
339 throw new Exception(msg + junit_report_xml_pretty)
340 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300341}
342
343def devops_snapshot(stack) {
344 // Make the snapshot with name "${stack}_deployed"
345 // for all VMs in the environment.
346 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
347 // then make a copy for the created snapshot to allow the system
348 // tests to revert this snapshot along with the metadata from the INI file.
349 run_cmd("""\
350 dos.py suspend ${ENV_NAME}
351 dos.py snapshot ${ENV_NAME} ${stack}_deployed
352 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300353 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300354 dos.py time-sync ${ENV_NAME} || dos.py time-sync ${ENV_NAME} # sometimes, timesync may fail. Need to update it in fuel-devops.
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300355 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
356 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
357 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300358 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300359}
360
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300361def get_steps_list(steps) {
362 // Make a list from comma separated string
363 return steps.split(',').collect { it.split(':')[0] }
364}
365
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300366def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
367 // <filename> is name of the XML report file that will be created
368 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
369 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitriev39666082018-08-29 15:30:45 +0300370 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300371<?xml version=\"1.0\" encoding=\"utf-8\"?>
372 <testsuite>
373 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
374 <${status} message=\"${status_message}\">${text}</${status}>
375 <system-out>${stdout}</system-out>
376 <system-err>${stderr}</system-err>
377 </testcase>
378 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300379"""
380 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300381}
382
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300383def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
384 def venvPath = '/home/jenkins/venv_testrail_reporter'
385 def testPlanDesc = env.ENV_NAME
386 def testrailURL = "https://mirantis.testrail.com"
387 def testrailProject = "Mirantis Cloud Platform"
388 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
389 def testrailMilestone = "MCP1.1"
390 def jobURL = env.BUILD_URL
391
392 def reporterOptions = [
393 "--verbose",
394 "--env-description \"${testPlanDesc}\"",
395 "--testrail-run-update",
396 "--testrail-url \"${testrailURL}\"",
397 "--testrail-user \"\${TESTRAIL_USER}\"",
398 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
399 "--testrail-project \"${testrailProject}\"",
400 "--testrail-plan-name \"${testPlanName}\"",
401 "--testrail-milestone \"${testrailMilestone}\"",
402 "--testrail-suite \"${testSuiteName}\"",
403 "--xunit-name-template \"${methodname}\"",
404 "--testrail-name-template \"${testrail_name_template}\"",
405 "--test-results-link \"${jobURL}\"",
406 ] + reporter_extra_options
407
408 def script = """
409 . ${venvPath}/bin/activate
410 set -ex
Dennis Dmitriev39666082018-08-29 15:30:45 +0300411 report_xml=\$(find ${PARENT_WORKSPACE} -name "${report_name}")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300412 if [ -n "\${report_xml}" ]; then
413 report ${reporterOptions.join(' ')} \${report_xml}
414 fi
415 """
416
417 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
418
419 withCredentials([
420 [$class : 'UsernamePasswordMultiBinding',
421 credentialsId : testrail_cred_id,
422 passwordVariable: 'TESTRAIL_PASSWORD',
423 usernameVariable: 'TESTRAIL_USER']
424 ]) {
425 return run_cmd(script)
426 }
427}
428
429
430def create_deploy_result_report(deploy_expected_stacks, result, text) {
431 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
432 def classname = "Deploy"
433 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300434 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300435 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
436 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300437}