blob: d052f324c4155f0dc4f7ddc86d77d5d72f35fe17 [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 Dmitrieveb50ce12018-09-27 13:34:32 +03005def run_sh(String cmd) {
6 // run shell script without catching any output
7 def common = new com.mirantis.mk.Common()
8 common.printMsg("Run shell command:\n" + cmd, "blue")
9 def VENV_PATH='/home/jenkins/fuel-devops30'
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020010 def script = """\
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030011 set -ex;
12 . ${VENV_PATH}/bin/activate;
13 bash -c '${cmd.stripIndent()}'
14 """
15 return sh(script: script)
16}
17
Dennis Dmitriev8df35442018-07-31 08:40:20 +030018def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030019 def common = new com.mirantis.mk.Common()
20 common.printMsg("Run shell command:\n" + cmd, "blue")
21 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +030022 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020023 def script = """#!/bin/bash
24 set +x
25 echo 'activate python virtualenv ${VENV_PATH}'
26 . ${VENV_PATH}/bin/activate
27 bash -c -e -x '${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030028 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030029 try {
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020030 def stdout = sh(script: script, returnStdout: returnStdout)
31 def stderr = readFile("${stderr_path}")
32 def error_message = "\n<<<<<< STDERR: >>>>>>\n" + stderr
33 common.printMsg(error_message, "yellow")
34 common.printMsg("", "reset")
35 return stdout
Dennis Dmitriev27a96792018-07-30 07:52:03 +030036 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030037 def stderr = readFile("${stderr_path}")
38 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020039 common.printMsg(error_message, "red")
40 common.printMsg("", "reset")
Dennis Dmitriev8df35442018-07-31 08:40:20 +030041 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030042 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030043 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030044 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030045}
46
47def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030048 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030049}
50
Dennis Dmitriev27a96792018-07-30 07:52:03 +030051def build_pipeline_job(job_name, parameters) {
52 //Build a job, grab the results if failed and use the results in exception
53 def common = new com.mirantis.mk.Common()
54 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
55 common.prettyPrint(parameters)
56
57 def job_info = build job: "${job_name}",
58 parameters: parameters,
59 propagate: false
60
61 if (job_info.getResult() != "SUCCESS") {
62 currentBuild.result = job_info.getResult()
63 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030064 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030065 def workflow_details=run_cmd_stdout("""\
66 export JOB_NAME=${job_name}
67 export BUILD_NUMBER=${build_number}
68 python ./tcp_tests/utils/get_jenkins_job_stages.py
69 """)
70 throw new Exception(workflow_details)
71 }
72}
73
74def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
75 //Build a job, grab the results if failed and use the results in exception
76 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
77 def common = new com.mirantis.mk.Common()
78 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
79 common.prettyPrint(parameters)
80
81 def job_info = build job: "${job_name}",
82 parameters: parameters,
83 propagate: false
84
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020085 def build_number = job_info.getNumber()
86 def build_url = job_info.getAbsoluteUrl()
87 def build_status = job_info.getResult()
88 try {
89 // Try to grab 'tar.gz' articacts from the shell job'
90 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
91 projectName: job_name,
92 selector: specific("${build_number}"),
93 filter: "**/*.tar.gz",
94 target: '.',
95 flatten: true,
96 fingerprintArtifacts: true)
97 } catch (none) {
98 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
99 }
100
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300101 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300102 def job_url = "${build_url}"
103 currentBuild.result = build_status
104 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300105 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300106 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
107 projectName: job_name,
108 selector: specific("${build_number}"),
109 filter: "${junit_report_source_dir}/${junit_report_filename}",
110 target: '.',
111 flatten: true,
112 fingerprintArtifacts: true)
113
114 def String junit_report_xml = readFile("${junit_report_filename}")
115 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
116 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300117 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300118 } else {
119 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
120 }
121 }
122}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300123
124def prepare_working_dir() {
125 println "Clean the working directory ${env.WORKSPACE}"
126 deleteDir()
127
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300128 // do not fail if environment doesn't exists
129 println "Remove environment ${ENV_NAME}"
130 run_cmd("""\
131 dos.py erase ${ENV_NAME} || true
132 """)
133 println "Remove config drive ISO"
134 run_cmd("""\
135 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
136 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300137
138 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300139 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
140 if [ -n "$TCP_QA_REFS" ]; then
141 set -e
142 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
143 fi
144 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300145 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300146}
147
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300148def update_working_dir() {
149 // Use to fetch a patchset from gerrit to the working dir
150 run_cmd("""\
151 if [ -n "$TCP_QA_REFS" ]; then
152 set -e
153 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
154 fi
155 pip install -r tcp_tests/requirements.txt
156 """)
157}
158
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300159def swarm_bootstrap_salt_cluster_devops() {
160 def common = new com.mirantis.mk.Common()
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200161 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
162 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300163 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
164 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
165 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
166 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
167 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200168 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
169 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200170 def env_ipmi_user = env.IPMI_USER ?: ''
171 def env_ipmi_pass = env.IPMI_PASS ?: ''
172 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
173 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200174 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300175 def parameters = [
176 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
177 string(name: 'PARENT_WORKSPACE', value: pwd()),
178 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
179 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
180 string(name: 'MCP_VERSION', 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 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300184 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
185 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
186 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
187 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
188 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
189 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
190 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200191 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
192 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200193 string(name: 'IPMI_USER', value: env_ipmi_user),
194 string(name: 'IPMI_PASS', value: env_ipmi_pass),
195 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
196 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200197 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300198 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
199 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300200
201 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300202}
203
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200204def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300205 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
206 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300207 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300208 def parameters = [
209 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
210 string(name: 'PARENT_WORKSPACE', value: pwd()),
211 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
212 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200213 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300214 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300215 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
216 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300217 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300218}
219
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200220def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300221 // Run openstack_deploy job on CICD Jenkins for specified stacks
222 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300223 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300224 def parameters = [
225 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
226 string(name: 'PARENT_WORKSPACE', value: pwd()),
227 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
228 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200229 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300230 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300231 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
232 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300233 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300234}
235
sgudz2ed95852019-03-01 14:48:52 +0200236def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
237 // Run openstack_deploy job on day01 Jenkins for specified stacks
238 def common = new com.mirantis.mk.Common()
239 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
240 def parameters = [
241 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
242 string(name: 'PARENT_WORKSPACE', value: pwd()),
243 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
244 string(name: 'STACK_INSTALL', value: stack_to_install),
245 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
246 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
247 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
248 ]
249 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
250}
251
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300252def swarm_run_pytest(String passed_steps) {
253 // Run pytest tests
254 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300255 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200256 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200257 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300258 def parameters = [
259 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
260 string(name: 'PASSED_STEPS', value: passed_steps),
261 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
262 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
263 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300264 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300265 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
266 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
267 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
268 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
269 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200270 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200271 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200272
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300273 ]
274 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
275 common.prettyPrint(parameters)
276 build job: 'swarm-run-pytest',
277 parameters: parameters
278}
279
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300280def swarm_testrail_report(String passed_steps) {
281 // Run pytest tests
282 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300283 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200284 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300285 def parameters = [
286 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200287 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300288 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
289 string(name: 'PASSED_STEPS', value: passed_steps),
290 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
291 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300292 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200293 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Vladimir Jigulin151097d2019-03-21 18:39:47 +0400294 string(name: 'TEST_PLAN_NAME_PREFIX', value: env.TESTRAIL_TEST_PLAN_NAME_PREFIX ?: ''),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300295 ]
296 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
297 common.prettyPrint(parameters)
298 build job: 'swarm-testrail-report',
299 parameters: parameters
300}
301
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300302def generate_cookied_model() {
303 def common = new com.mirantis.mk.Common()
304 // do not fail if environment doesn't exists
305 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
306 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
307 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
308 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
309 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
310 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
311 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
312 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
313
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200314 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
315 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300316 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
317 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
318 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200319 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300320
321 def parameters = [
322 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
323 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
324 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
325 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
326 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
327 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300328 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
329 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
330 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300331 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
332 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
333 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
334 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200335 string(name: 'IPMI_USER', value: env.IPMI_USER),
336 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200337 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
sgudzc97385a2018-11-29 17:01:53 +0200338 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300339 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300340
341 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300342}
343
344def generate_configdrive_iso() {
345 def common = new com.mirantis.mk.Common()
346 def SALT_MASTER_IP=run_cmd_stdout("""\
347 export ENV_NAME=${ENV_NAME}
348 . ./tcp_tests/utils/env_salt
349 echo \$SALT_MASTER_IP
350 """).trim().split().last()
351 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300352
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300353 def dhcp_ranges_json=run_cmd_stdout("""\
354 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
355 fgrep "admin-pool01"|
356 cut -d"=" -f2
357 """).trim().split("\n").last()
358 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
359 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
360 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
361
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300362 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
363 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300364 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200365 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
366 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300367
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300368 def parameters = [
369 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
370 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
371 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
372 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
373 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200374 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300375 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
376 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
377 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300378 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300379 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
380 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200381 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
382 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300383 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
384 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300385 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300386 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300387 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300388}
389
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300390def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300391 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200392 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300393 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200394 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300395 try {
396 run_cmd("""\
397 export ENV_NAME=${ENV_NAME}
398 . ./tcp_tests/utils/env_salt
399 . ./tcp_tests/utils/env_jenkins_day01
400 export JENKINS_BUILD_TIMEOUT=${timeout}
401 JOB_PARAMETERS=\"{
402 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
403 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
404 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200405 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300406 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
407 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200408 // Wait for IO calm down on cluster nodes
409 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300410 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300411 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300412 def workflow_details=run_cmd_stdout("""\
413 . ./tcp_tests/utils/env_salt
414 . ./tcp_tests/utils/env_jenkins_day01
415 export JOB_NAME=deploy_openstack
416 export BUILD_NUMBER=lastBuild
417 python ./tcp_tests/utils/get_jenkins_job_stages.py
418 """)
419 throw new Exception(workflow_details)
420 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300421}
422
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300423def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300424 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200425 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300426 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200427 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300428 try {
429 run_cmd("""\
430 export ENV_NAME=${ENV_NAME}
431 . ./tcp_tests/utils/env_salt
432 . ./tcp_tests/utils/env_jenkins_cicd
433 export JENKINS_BUILD_TIMEOUT=${timeout}
434 JOB_PARAMETERS=\"{
435 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
436 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
437 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200438 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300439 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300440 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200441 // Wait for IO calm down on cluster nodes
442 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300443 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300444 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300445 def workflow_details=run_cmd_stdout("""\
446 . ./tcp_tests/utils/env_salt
447 . ./tcp_tests/utils/env_jenkins_cicd
448 export JOB_NAME=deploy_openstack
449 export BUILD_NUMBER=lastBuild
450 python ./tcp_tests/utils/get_jenkins_job_stages.py
451 """)
452 throw new Exception(workflow_details)
453 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300454}
455
456def sanity_check_component(stack) {
457 // Run sanity check for the component ${stack}.
458 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300459 try {
460 run_cmd("""\
461 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
462 """)
463 } catch (e) {
464 def String junit_report_xml = readFile("deploy_${stack}.xml")
465 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
466 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
467 throw new Exception(msg + junit_report_xml_pretty)
468 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300469}
470
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300471def download_logs(archive_name_prefix) {
472 // Archive and download logs and debug info from salt nodes in the lab
473 // Do not fail in case of error to not lose the original error from the parent exception.
474 def common = new com.mirantis.mk.Common()
475 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
476 run_cmd("""\
477 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
478 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
479 """)
480}
481
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300482def devops_snapshot_info(snapshot_name) {
483 // Print helper message after snapshot
484 def common = new com.mirantis.mk.Common()
485
486 def SALT_MASTER_IP=run_cmd_stdout("""\
487 . ./tcp_tests/utils/env_salt
488 echo \$SALT_MASTER_IP
489 """).trim().split().last()
490 def login = "root" // set fixed 'root' login for now
491 def password = "r00tme" // set fixed 'root' login for now
492 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
493 def VENV_PATH='/home/jenkins/fuel-devops30'
494
495 common.printMsg("""\
496#########################
497# To revert the snapshot:
498#########################
499. ${VENV_PATH}/bin/activate;
500dos.py revert ${ENV_NAME} ${snapshot_name};
501dos.py resume ${ENV_NAME};
502# dos.py time-sync ${ENV_NAME}; # Optional\n
503ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
504""", "cyan")
505}
506
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300507def devops_snapshot(stack) {
508 // Make the snapshot with name "${stack}_deployed"
509 // for all VMs in the environment.
510 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
511 // then make a copy for the created snapshot to allow the system
512 // tests to revert this snapshot along with the metadata from the INI file.
513 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300514 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300515 dos.py suspend ${ENV_NAME}
516 dos.py snapshot ${ENV_NAME} ${stack}_deployed
517 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300518 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300519
520 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
521 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
522
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300523 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
524 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
525 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300526 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300527 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300528}
529
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300530def get_steps_list(steps) {
531 // Make a list from comma separated string
532 return steps.split(',').collect { it.split(':')[0] }
533}
534
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300535def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
536 // <filename> is name of the XML report file that will be created
537 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
538 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300539
540 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
541 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
542
Dennis Dmitriev39666082018-08-29 15:30:45 +0300543 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300544<?xml version=\"1.0\" encoding=\"utf-8\"?>
545 <testsuite>
546 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300547 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300548 <system-out>${stdout}</system-out>
549 <system-err>${stderr}</system-err>
550 </testcase>
551 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300552"""
553 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300554}
555
Vladimir Jigulin151097d2019-03-21 18:39:47 +0400556def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[], testPlanNamePrefix=null) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300557 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200558 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300559 def testrailURL = "https://mirantis.testrail.com"
560 def testrailProject = "Mirantis Cloud Platform"
Vladimir Jigulin151097d2019-03-21 18:39:47 +0400561 if (!testPlanNamePrefix) {
562 testPlanNamePrefix = "[MCP-Q2]System"
563 }
564 def testPlanName = "${testPlanNamePrefix}-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300565 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300566 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300567 def jobURL = env.BUILD_URL
568
569 def reporterOptions = [
570 "--verbose",
571 "--env-description \"${testPlanDesc}\"",
572 "--testrail-run-update",
573 "--testrail-url \"${testrailURL}\"",
574 "--testrail-user \"\${TESTRAIL_USER}\"",
575 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
576 "--testrail-project \"${testrailProject}\"",
577 "--testrail-plan-name \"${testPlanName}\"",
578 "--testrail-milestone \"${testrailMilestone}\"",
579 "--testrail-suite \"${testSuiteName}\"",
580 "--xunit-name-template \"${methodname}\"",
581 "--testrail-name-template \"${testrail_name_template}\"",
582 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300583 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300584 ] + reporter_extra_options
585
586 def script = """
587 . ${venvPath}/bin/activate
588 set -ex
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200589 report ${reporterOptions.join(' ')} '${report_name}'
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300590 """
591
592 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
593
594 withCredentials([
595 [$class : 'UsernamePasswordMultiBinding',
596 credentialsId : testrail_cred_id,
597 passwordVariable: 'TESTRAIL_PASSWORD',
598 usernameVariable: 'TESTRAIL_USER']
599 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300600 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300601 }
602}
603
604
605def create_deploy_result_report(deploy_expected_stacks, result, text) {
606 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
607 def classname = "Deploy"
608 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300609 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300610 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
611 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300612}