blob: d50432f1bc4390287ea7de188024f9cddf7f7e9c [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
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +04005def is_released_version(version) {
6 return Character.isDigit(version.charAt(0))
7}
8
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +03009def run_sh(String cmd) {
10 // run shell script without catching any output
11 def common = new com.mirantis.mk.Common()
12 common.printMsg("Run shell command:\n" + cmd, "blue")
13 def VENV_PATH='/home/jenkins/fuel-devops30'
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020014 def script = """\
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030015 set -ex;
16 . ${VENV_PATH}/bin/activate;
17 bash -c '${cmd.stripIndent()}'
18 """
19 return sh(script: script)
20}
21
Dennis Dmitriev8df35442018-07-31 08:40:20 +030022def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030023 def common = new com.mirantis.mk.Common()
24 common.printMsg("Run shell command:\n" + cmd, "blue")
25 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +030026 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020027 def script = """#!/bin/bash
28 set +x
29 echo 'activate python virtualenv ${VENV_PATH}'
30 . ${VENV_PATH}/bin/activate
31 bash -c -e -x '${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030032 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030033 try {
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020034 def stdout = sh(script: script, returnStdout: returnStdout)
35 def stderr = readFile("${stderr_path}")
36 def error_message = "\n<<<<<< STDERR: >>>>>>\n" + stderr
37 common.printMsg(error_message, "yellow")
38 common.printMsg("", "reset")
39 return stdout
Dennis Dmitriev27a96792018-07-30 07:52:03 +030040 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030041 def stderr = readFile("${stderr_path}")
42 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020043 common.printMsg(error_message, "red")
44 common.printMsg("", "reset")
Dennis Dmitriev8df35442018-07-31 08:40:20 +030045 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030046 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030047 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030048 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030049}
50
51def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030052 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030053}
54
Dennis Dmitriev27a96792018-07-30 07:52:03 +030055def build_pipeline_job(job_name, parameters) {
56 //Build a job, grab the results if failed and use the results in exception
57 def common = new com.mirantis.mk.Common()
58 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
59 common.prettyPrint(parameters)
60
61 def job_info = build job: "${job_name}",
62 parameters: parameters,
63 propagate: false
64
65 if (job_info.getResult() != "SUCCESS") {
66 currentBuild.result = job_info.getResult()
67 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030068 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030069 def workflow_details=run_cmd_stdout("""\
70 export JOB_NAME=${job_name}
71 export BUILD_NUMBER=${build_number}
72 python ./tcp_tests/utils/get_jenkins_job_stages.py
73 """)
74 throw new Exception(workflow_details)
75 }
76}
77
78def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
79 //Build a job, grab the results if failed and use the results in exception
80 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
81 def common = new com.mirantis.mk.Common()
82 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
83 common.prettyPrint(parameters)
84
85 def job_info = build job: "${job_name}",
86 parameters: parameters,
87 propagate: false
88
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020089 def build_number = job_info.getNumber()
90 def build_url = job_info.getAbsoluteUrl()
91 def build_status = job_info.getResult()
92 try {
93 // Try to grab 'tar.gz' articacts from the shell job'
94 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
95 projectName: job_name,
96 selector: specific("${build_number}"),
97 filter: "**/*.tar.gz",
98 target: '.',
99 flatten: true,
100 fingerprintArtifacts: true)
101 } catch (none) {
102 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
103 }
104
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300105 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300106 def job_url = "${build_url}"
107 currentBuild.result = build_status
108 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300109 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300110 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
111 projectName: job_name,
112 selector: specific("${build_number}"),
113 filter: "${junit_report_source_dir}/${junit_report_filename}",
114 target: '.',
115 flatten: true,
116 fingerprintArtifacts: true)
117
118 def String junit_report_xml = readFile("${junit_report_filename}")
119 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
120 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300121 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300122 } else {
123 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
124 }
125 }
126}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300127
128def prepare_working_dir() {
129 println "Clean the working directory ${env.WORKSPACE}"
130 deleteDir()
131
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300132 // do not fail if environment doesn't exists
133 println "Remove environment ${ENV_NAME}"
134 run_cmd("""\
135 dos.py erase ${ENV_NAME} || true
136 """)
137 println "Remove config drive ISO"
138 run_cmd("""\
139 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
140 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300141
142 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300143 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
144 if [ -n "$TCP_QA_REFS" ]; then
145 set -e
146 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
147 fi
148 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300149 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300150}
151
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300152def update_working_dir() {
153 // Use to fetch a patchset from gerrit to the working dir
154 run_cmd("""\
155 if [ -n "$TCP_QA_REFS" ]; then
156 set -e
157 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
158 fi
159 pip install -r tcp_tests/requirements.txt
160 """)
161}
162
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300163def swarm_bootstrap_salt_cluster_devops() {
164 def common = new com.mirantis.mk.Common()
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +0400165 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: is_released_version(env.MCP_VERSION) ? "release/${env.MCP_VERSION}" : 'master'
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200166 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300167 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
168 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
169 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
170 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
171 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200172 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
173 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300174 def deploy_network_mask = env.DEPLOY_NETWORK_NETMASK ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200175 def env_ipmi_user = env.IPMI_USER ?: ''
176 def env_ipmi_pass = env.IPMI_PASS ?: ''
177 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
178 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200179 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300180 def parameters = [
181 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
182 string(name: 'PARENT_WORKSPACE', value: pwd()),
183 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
184 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
185 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
186 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
187 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
188 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300189 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
190 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
191 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
192 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
193 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
194 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
195 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200196 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
197 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300198 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200199 string(name: 'IPMI_USER', value: env_ipmi_user),
200 string(name: 'IPMI_PASS', value: env_ipmi_pass),
201 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
202 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200203 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300204 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
205 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300206
207 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300208}
209
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200210def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300211 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
212 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300213 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300214 def parameters = [
215 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
216 string(name: 'PARENT_WORKSPACE', value: pwd()),
217 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
218 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200219 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300220 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300221 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
222 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300223 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300224}
225
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200226def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300227 // Run openstack_deploy job on CICD Jenkins for specified stacks
228 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300229 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300230 def parameters = [
231 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
232 string(name: 'PARENT_WORKSPACE', value: pwd()),
233 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
234 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200235 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300236 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300237 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
238 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300239 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300240}
241
sgudz2ed95852019-03-01 14:48:52 +0200242def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
243 // Run openstack_deploy job on day01 Jenkins for specified stacks
244 def common = new com.mirantis.mk.Common()
245 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
246 def parameters = [
247 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
248 string(name: 'PARENT_WORKSPACE', value: pwd()),
249 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
250 string(name: 'STACK_INSTALL', value: stack_to_install),
251 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
252 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
253 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
254 ]
255 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
256}
257
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300258def swarm_run_pytest(String passed_steps) {
259 // Run pytest tests
260 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300261 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200262 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200263 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300264 def parameters = [
265 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
266 string(name: 'PASSED_STEPS', value: passed_steps),
267 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
268 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
269 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300270 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300271 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
272 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
273 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
274 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
275 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200276 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200277 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200278
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300279 ]
280 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
281 common.prettyPrint(parameters)
282 build job: 'swarm-run-pytest',
283 parameters: parameters
284}
285
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300286def swarm_testrail_report(String passed_steps) {
287 // Run pytest tests
288 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300289 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200290 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300291 def parameters = [
292 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200293 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300294 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
295 string(name: 'PASSED_STEPS', value: passed_steps),
296 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
297 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300298 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200299 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300300 ]
301 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
302 common.prettyPrint(parameters)
303 build job: 'swarm-testrail-report',
304 parameters: parameters
305}
306
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300307def generate_cookied_model() {
308 def common = new com.mirantis.mk.Common()
309 // do not fail if environment doesn't exists
310 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
311 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
312 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
313 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
314 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
315 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
316 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
317 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
318
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +0400319 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: is_released_version(env.MCP_VERSION) ? "release/${env.MCP_VERSION}" : 'master'
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200320 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300321 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
322 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
323 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200324 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300325
326 def parameters = [
327 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
328 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
329 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
330 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
331 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
332 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300333 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
334 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
335 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300336 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
337 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
338 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
339 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200340 string(name: 'IPMI_USER', value: env.IPMI_USER),
341 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200342 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
sgudzc97385a2018-11-29 17:01:53 +0200343 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300344 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300345
346 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300347}
348
349def generate_configdrive_iso() {
350 def common = new com.mirantis.mk.Common()
351 def SALT_MASTER_IP=run_cmd_stdout("""\
352 export ENV_NAME=${ENV_NAME}
353 . ./tcp_tests/utils/env_salt
354 echo \$SALT_MASTER_IP
355 """).trim().split().last()
356 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300357
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300358 def dhcp_ranges_json=run_cmd_stdout("""\
359 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
360 fgrep "admin-pool01"|
361 cut -d"=" -f2
362 """).trim().split("\n").last()
363 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
364 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
365 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
366
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300367 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
368 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300369 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200370 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
371 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300372 def deploy_network_mask = env.DEPLOY_NETWORK_NETMASK ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300373
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300374 def parameters = [
375 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
376 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
377 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
378 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
379 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200380 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300381 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
382 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
383 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300384 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300385 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
386 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200387 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
388 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300389 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300390 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
391 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300392 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300393 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300394 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300395}
396
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300397def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300398 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200399 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300400 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200401 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300402 try {
403 run_cmd("""\
404 export ENV_NAME=${ENV_NAME}
405 . ./tcp_tests/utils/env_salt
406 . ./tcp_tests/utils/env_jenkins_day01
407 export JENKINS_BUILD_TIMEOUT=${timeout}
408 JOB_PARAMETERS=\"{
409 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
410 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
411 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200412 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300413 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
414 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200415 // Wait for IO calm down on cluster nodes
416 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300417 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300418 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300419 def workflow_details=run_cmd_stdout("""\
420 . ./tcp_tests/utils/env_salt
421 . ./tcp_tests/utils/env_jenkins_day01
422 export JOB_NAME=deploy_openstack
423 export BUILD_NUMBER=lastBuild
424 python ./tcp_tests/utils/get_jenkins_job_stages.py
425 """)
426 throw new Exception(workflow_details)
427 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300428}
429
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300430def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300431 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200432 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300433 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200434 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300435 try {
436 run_cmd("""\
437 export ENV_NAME=${ENV_NAME}
438 . ./tcp_tests/utils/env_salt
439 . ./tcp_tests/utils/env_jenkins_cicd
440 export JENKINS_BUILD_TIMEOUT=${timeout}
441 JOB_PARAMETERS=\"{
442 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
443 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
444 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200445 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300446 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 +0300447 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200448 // Wait for IO calm down on cluster nodes
449 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300450 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300451 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300452 def workflow_details=run_cmd_stdout("""\
453 . ./tcp_tests/utils/env_salt
454 . ./tcp_tests/utils/env_jenkins_cicd
455 export JOB_NAME=deploy_openstack
456 export BUILD_NUMBER=lastBuild
457 python ./tcp_tests/utils/get_jenkins_job_stages.py
458 """)
459 throw new Exception(workflow_details)
460 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300461}
462
463def sanity_check_component(stack) {
464 // Run sanity check for the component ${stack}.
465 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300466 try {
467 run_cmd("""\
468 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
469 """)
470 } catch (e) {
471 def String junit_report_xml = readFile("deploy_${stack}.xml")
472 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
473 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
474 throw new Exception(msg + junit_report_xml_pretty)
475 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300476}
477
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300478def download_logs(archive_name_prefix) {
479 // Archive and download logs and debug info from salt nodes in the lab
480 // Do not fail in case of error to not lose the original error from the parent exception.
481 def common = new com.mirantis.mk.Common()
482 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
483 run_cmd("""\
484 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
485 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
486 """)
487}
488
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300489def devops_snapshot_info(snapshot_name) {
490 // Print helper message after snapshot
491 def common = new com.mirantis.mk.Common()
492
493 def SALT_MASTER_IP=run_cmd_stdout("""\
494 . ./tcp_tests/utils/env_salt
495 echo \$SALT_MASTER_IP
496 """).trim().split().last()
497 def login = "root" // set fixed 'root' login for now
498 def password = "r00tme" // set fixed 'root' login for now
499 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
500 def VENV_PATH='/home/jenkins/fuel-devops30'
501
502 common.printMsg("""\
503#########################
504# To revert the snapshot:
505#########################
506. ${VENV_PATH}/bin/activate;
507dos.py revert ${ENV_NAME} ${snapshot_name};
508dos.py resume ${ENV_NAME};
509# dos.py time-sync ${ENV_NAME}; # Optional\n
510ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
511""", "cyan")
512}
513
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300514def devops_snapshot(stack) {
515 // Make the snapshot with name "${stack}_deployed"
516 // for all VMs in the environment.
517 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
518 // then make a copy for the created snapshot to allow the system
519 // tests to revert this snapshot along with the metadata from the INI file.
520 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300521 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300522 dos.py suspend ${ENV_NAME}
523 dos.py snapshot ${ENV_NAME} ${stack}_deployed
524 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300525 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300526
527 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
528 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
529
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300530 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
531 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
532 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300533 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300534 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300535}
536
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300537def get_steps_list(steps) {
538 // Make a list from comma separated string
539 return steps.split(',').collect { it.split(':')[0] }
540}
541
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300542def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
543 // <filename> is name of the XML report file that will be created
544 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
545 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300546
547 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
548 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
549
Dennis Dmitriev39666082018-08-29 15:30:45 +0300550 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300551<?xml version=\"1.0\" encoding=\"utf-8\"?>
552 <testsuite>
553 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300554 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300555 <system-out>${stdout}</system-out>
556 <system-err>${stderr}</system-err>
557 </testcase>
558 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300559"""
560 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300561}
562
Dennis Dmitrievaf59f7e2019-04-02 11:54:06 +0000563def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300564 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200565 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300566 def testrailURL = "https://mirantis.testrail.com"
567 def testrailProject = "Mirantis Cloud Platform"
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400568 def testPlanNamePrefix = env.TEST_PLAN_NAME_PREFIX ?: "[MCP-Q2]System"
569 def testPlanName = "${testPlanNamePrefix}-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300570 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300571 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300572 def jobURL = env.BUILD_URL
573
574 def reporterOptions = [
575 "--verbose",
576 "--env-description \"${testPlanDesc}\"",
577 "--testrail-run-update",
578 "--testrail-url \"${testrailURL}\"",
579 "--testrail-user \"\${TESTRAIL_USER}\"",
580 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
581 "--testrail-project \"${testrailProject}\"",
582 "--testrail-plan-name \"${testPlanName}\"",
583 "--testrail-milestone \"${testrailMilestone}\"",
584 "--testrail-suite \"${testSuiteName}\"",
585 "--xunit-name-template \"${methodname}\"",
586 "--testrail-name-template \"${testrail_name_template}\"",
587 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300588 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300589 ] + reporter_extra_options
590
591 def script = """
592 . ${venvPath}/bin/activate
593 set -ex
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200594 report ${reporterOptions.join(' ')} '${report_name}'
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300595 """
596
597 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
598
599 withCredentials([
600 [$class : 'UsernamePasswordMultiBinding',
601 credentialsId : testrail_cred_id,
602 passwordVariable: 'TESTRAIL_PASSWORD',
603 usernameVariable: 'TESTRAIL_USER']
604 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300605 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300606 }
607}
608
609
610def create_deploy_result_report(deploy_expected_stacks, result, text) {
611 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
612 def classname = "Deploy"
613 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300614 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300615 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
616 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300617}