blob: 53927f7eece44938205b12b15eb128ee8f01a65a [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}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300294 ]
295 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
296 common.prettyPrint(parameters)
297 build job: 'swarm-testrail-report',
298 parameters: parameters
299}
300
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300301def generate_cookied_model() {
302 def common = new com.mirantis.mk.Common()
303 // do not fail if environment doesn't exists
304 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
305 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
306 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
307 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
308 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
309 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
310 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
311 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
312
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200313 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
314 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300315 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
316 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
317 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200318 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300319
320 def parameters = [
321 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
322 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
323 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
324 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
325 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
326 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300327 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
328 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
329 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300330 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
331 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
332 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
333 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200334 string(name: 'IPMI_USER', value: env.IPMI_USER),
335 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200336 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
sgudzc97385a2018-11-29 17:01:53 +0200337 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300338 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300339
340 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300341}
342
343def generate_configdrive_iso() {
344 def common = new com.mirantis.mk.Common()
345 def SALT_MASTER_IP=run_cmd_stdout("""\
346 export ENV_NAME=${ENV_NAME}
347 . ./tcp_tests/utils/env_salt
348 echo \$SALT_MASTER_IP
349 """).trim().split().last()
350 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300351
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300352 def dhcp_ranges_json=run_cmd_stdout("""\
353 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
354 fgrep "admin-pool01"|
355 cut -d"=" -f2
356 """).trim().split("\n").last()
357 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
358 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
359 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
360
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300361 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
362 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300363 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200364 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
365 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300366
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300367 def parameters = [
368 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
369 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
370 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
371 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
372 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200373 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300374 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
375 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
376 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300377 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300378 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
379 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200380 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
381 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300382 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
383 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300384 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300385 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300386 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300387}
388
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300389def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300390 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200391 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300392 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200393 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300394 try {
395 run_cmd("""\
396 export ENV_NAME=${ENV_NAME}
397 . ./tcp_tests/utils/env_salt
398 . ./tcp_tests/utils/env_jenkins_day01
399 export JENKINS_BUILD_TIMEOUT=${timeout}
400 JOB_PARAMETERS=\"{
401 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
402 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
403 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200404 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300405 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
406 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200407 // Wait for IO calm down on cluster nodes
408 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300409 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300410 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300411 def workflow_details=run_cmd_stdout("""\
412 . ./tcp_tests/utils/env_salt
413 . ./tcp_tests/utils/env_jenkins_day01
414 export JOB_NAME=deploy_openstack
415 export BUILD_NUMBER=lastBuild
416 python ./tcp_tests/utils/get_jenkins_job_stages.py
417 """)
418 throw new Exception(workflow_details)
419 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300420}
421
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300422def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300423 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200424 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300425 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200426 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300427 try {
428 run_cmd("""\
429 export ENV_NAME=${ENV_NAME}
430 . ./tcp_tests/utils/env_salt
431 . ./tcp_tests/utils/env_jenkins_cicd
432 export JENKINS_BUILD_TIMEOUT=${timeout}
433 JOB_PARAMETERS=\"{
434 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
435 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
436 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200437 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300438 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 +0300439 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200440 // Wait for IO calm down on cluster nodes
441 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300442 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300443 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300444 def workflow_details=run_cmd_stdout("""\
445 . ./tcp_tests/utils/env_salt
446 . ./tcp_tests/utils/env_jenkins_cicd
447 export JOB_NAME=deploy_openstack
448 export BUILD_NUMBER=lastBuild
449 python ./tcp_tests/utils/get_jenkins_job_stages.py
450 """)
451 throw new Exception(workflow_details)
452 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300453}
454
455def sanity_check_component(stack) {
456 // Run sanity check for the component ${stack}.
457 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300458 try {
459 run_cmd("""\
460 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
461 """)
462 } catch (e) {
463 def String junit_report_xml = readFile("deploy_${stack}.xml")
464 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
465 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
466 throw new Exception(msg + junit_report_xml_pretty)
467 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300468}
469
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300470def download_logs(archive_name_prefix) {
471 // Archive and download logs and debug info from salt nodes in the lab
472 // Do not fail in case of error to not lose the original error from the parent exception.
473 def common = new com.mirantis.mk.Common()
474 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
475 run_cmd("""\
476 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
477 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
478 """)
479}
480
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300481def devops_snapshot_info(snapshot_name) {
482 // Print helper message after snapshot
483 def common = new com.mirantis.mk.Common()
484
485 def SALT_MASTER_IP=run_cmd_stdout("""\
486 . ./tcp_tests/utils/env_salt
487 echo \$SALT_MASTER_IP
488 """).trim().split().last()
489 def login = "root" // set fixed 'root' login for now
490 def password = "r00tme" // set fixed 'root' login for now
491 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
492 def VENV_PATH='/home/jenkins/fuel-devops30'
493
494 common.printMsg("""\
495#########################
496# To revert the snapshot:
497#########################
498. ${VENV_PATH}/bin/activate;
499dos.py revert ${ENV_NAME} ${snapshot_name};
500dos.py resume ${ENV_NAME};
501# dos.py time-sync ${ENV_NAME}; # Optional\n
502ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
503""", "cyan")
504}
505
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300506def devops_snapshot(stack) {
507 // Make the snapshot with name "${stack}_deployed"
508 // for all VMs in the environment.
509 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
510 // then make a copy for the created snapshot to allow the system
511 // tests to revert this snapshot along with the metadata from the INI file.
512 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300513 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300514 dos.py suspend ${ENV_NAME}
515 dos.py snapshot ${ENV_NAME} ${stack}_deployed
516 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300517 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300518
519 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
520 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
521
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300522 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
523 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
524 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300525 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300526 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300527}
528
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300529def get_steps_list(steps) {
530 // Make a list from comma separated string
531 return steps.split(',').collect { it.split(':')[0] }
532}
533
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300534def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
535 // <filename> is name of the XML report file that will be created
536 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
537 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300538
539 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
540 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
541
Dennis Dmitriev39666082018-08-29 15:30:45 +0300542 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300543<?xml version=\"1.0\" encoding=\"utf-8\"?>
544 <testsuite>
545 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300546 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300547 <system-out>${stdout}</system-out>
548 <system-err>${stderr}</system-err>
549 </testcase>
550 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300551"""
552 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300553}
554
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300555def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
556 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200557 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300558 def testrailURL = "https://mirantis.testrail.com"
559 def testrailProject = "Mirantis Cloud Platform"
560 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
561 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300562 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300563 def jobURL = env.BUILD_URL
564
565 def reporterOptions = [
566 "--verbose",
567 "--env-description \"${testPlanDesc}\"",
568 "--testrail-run-update",
569 "--testrail-url \"${testrailURL}\"",
570 "--testrail-user \"\${TESTRAIL_USER}\"",
571 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
572 "--testrail-project \"${testrailProject}\"",
573 "--testrail-plan-name \"${testPlanName}\"",
574 "--testrail-milestone \"${testrailMilestone}\"",
575 "--testrail-suite \"${testSuiteName}\"",
576 "--xunit-name-template \"${methodname}\"",
577 "--testrail-name-template \"${testrail_name_template}\"",
578 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300579 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300580 ] + reporter_extra_options
581
582 def script = """
583 . ${venvPath}/bin/activate
584 set -ex
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200585 report ${reporterOptions.join(' ')} '${report_name}'
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300586 """
587
588 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
589
590 withCredentials([
591 [$class : 'UsernamePasswordMultiBinding',
592 credentialsId : testrail_cred_id,
593 passwordVariable: 'TESTRAIL_PASSWORD',
594 usernameVariable: 'TESTRAIL_USER']
595 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300596 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300597 }
598}
599
600
601def create_deploy_result_report(deploy_expected_stacks, result, text) {
602 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
603 def classname = "Deploy"
604 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300605 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300606 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
607 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300608}