blob: 4e819aea7b6a8040cdaac7ab766c63edf141d89e [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 ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200174 def env_ipmi_user = env.IPMI_USER ?: ''
175 def env_ipmi_pass = env.IPMI_PASS ?: ''
176 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
177 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200178 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300179 def parameters = [
180 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
181 string(name: 'PARENT_WORKSPACE', value: pwd()),
182 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
183 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
184 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
185 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
186 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
187 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300188 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
189 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
190 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
191 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
192 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
193 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
194 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200195 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
196 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200197 string(name: 'IPMI_USER', value: env_ipmi_user),
198 string(name: 'IPMI_PASS', value: env_ipmi_pass),
199 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
200 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200201 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300202 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
203 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300204
205 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300206}
207
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200208def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300209 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
210 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300211 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300212 def parameters = [
213 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
214 string(name: 'PARENT_WORKSPACE', value: pwd()),
215 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
216 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200217 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300218 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300219 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
220 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300221 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300222}
223
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200224def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300225 // Run openstack_deploy job on CICD Jenkins for specified stacks
226 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300227 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300228 def parameters = [
229 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
230 string(name: 'PARENT_WORKSPACE', value: pwd()),
231 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
232 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200233 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300234 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300235 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
236 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300237 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300238}
239
sgudz2ed95852019-03-01 14:48:52 +0200240def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
241 // Run openstack_deploy job on day01 Jenkins for specified stacks
242 def common = new com.mirantis.mk.Common()
243 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
244 def parameters = [
245 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
246 string(name: 'PARENT_WORKSPACE', value: pwd()),
247 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
248 string(name: 'STACK_INSTALL', value: stack_to_install),
249 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
250 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
251 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
252 ]
253 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
254}
255
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300256def swarm_run_pytest(String passed_steps) {
257 // Run pytest tests
258 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300259 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200260 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200261 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300262 def parameters = [
263 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
264 string(name: 'PASSED_STEPS', value: passed_steps),
265 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
266 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
267 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300268 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300269 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
270 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
271 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
272 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
273 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200274 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200275 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200276
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300277 ]
278 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
279 common.prettyPrint(parameters)
280 build job: 'swarm-run-pytest',
281 parameters: parameters
282}
283
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300284def swarm_testrail_report(String passed_steps) {
285 // Run pytest tests
286 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300287 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200288 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300289 def parameters = [
290 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200291 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300292 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
293 string(name: 'PASSED_STEPS', value: passed_steps),
294 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
295 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300296 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200297 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300298 ]
299 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
300 common.prettyPrint(parameters)
301 build job: 'swarm-testrail-report',
302 parameters: parameters
303}
304
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300305def generate_cookied_model() {
306 def common = new com.mirantis.mk.Common()
307 // do not fail if environment doesn't exists
308 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
309 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
310 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
311 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
312 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
313 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
314 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
315 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
316
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +0400317 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 +0200318 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300319 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
320 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
321 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200322 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300323
324 def parameters = [
325 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
326 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
327 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
328 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
329 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
330 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300331 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
332 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
333 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300334 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
335 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
336 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
337 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200338 string(name: 'IPMI_USER', value: env.IPMI_USER),
339 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200340 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
sgudzc97385a2018-11-29 17:01:53 +0200341 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300342 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300343
344 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300345}
346
347def generate_configdrive_iso() {
348 def common = new com.mirantis.mk.Common()
349 def SALT_MASTER_IP=run_cmd_stdout("""\
350 export ENV_NAME=${ENV_NAME}
351 . ./tcp_tests/utils/env_salt
352 echo \$SALT_MASTER_IP
353 """).trim().split().last()
354 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300355
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300356 def dhcp_ranges_json=run_cmd_stdout("""\
357 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
358 fgrep "admin-pool01"|
359 cut -d"=" -f2
360 """).trim().split("\n").last()
361 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
362 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
363 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
364
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300365 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
366 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300367 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200368 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
369 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300370
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300371 def parameters = [
372 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
373 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
374 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
375 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
376 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200377 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300378 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
379 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
380 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300381 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300382 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
383 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200384 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
385 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300386 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
387 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300388 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300389 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300390 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300391}
392
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300393def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300394 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200395 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300396 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200397 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300398 try {
399 run_cmd("""\
400 export ENV_NAME=${ENV_NAME}
401 . ./tcp_tests/utils/env_salt
402 . ./tcp_tests/utils/env_jenkins_day01
403 export JENKINS_BUILD_TIMEOUT=${timeout}
404 JOB_PARAMETERS=\"{
405 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
406 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
407 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200408 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300409 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
410 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200411 // Wait for IO calm down on cluster nodes
412 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300413 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300414 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300415 def workflow_details=run_cmd_stdout("""\
416 . ./tcp_tests/utils/env_salt
417 . ./tcp_tests/utils/env_jenkins_day01
418 export JOB_NAME=deploy_openstack
419 export BUILD_NUMBER=lastBuild
420 python ./tcp_tests/utils/get_jenkins_job_stages.py
421 """)
422 throw new Exception(workflow_details)
423 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300424}
425
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300426def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300427 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200428 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300429 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200430 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300431 try {
432 run_cmd("""\
433 export ENV_NAME=${ENV_NAME}
434 . ./tcp_tests/utils/env_salt
435 . ./tcp_tests/utils/env_jenkins_cicd
436 export JENKINS_BUILD_TIMEOUT=${timeout}
437 JOB_PARAMETERS=\"{
438 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
439 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
440 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200441 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300442 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 +0300443 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200444 // Wait for IO calm down on cluster nodes
445 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300446 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300447 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300448 def workflow_details=run_cmd_stdout("""\
449 . ./tcp_tests/utils/env_salt
450 . ./tcp_tests/utils/env_jenkins_cicd
451 export JOB_NAME=deploy_openstack
452 export BUILD_NUMBER=lastBuild
453 python ./tcp_tests/utils/get_jenkins_job_stages.py
454 """)
455 throw new Exception(workflow_details)
456 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300457}
458
459def sanity_check_component(stack) {
460 // Run sanity check for the component ${stack}.
461 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300462 try {
463 run_cmd("""\
464 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
465 """)
466 } catch (e) {
467 def String junit_report_xml = readFile("deploy_${stack}.xml")
468 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
469 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
470 throw new Exception(msg + junit_report_xml_pretty)
471 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300472}
473
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300474def download_logs(archive_name_prefix) {
475 // Archive and download logs and debug info from salt nodes in the lab
476 // Do not fail in case of error to not lose the original error from the parent exception.
477 def common = new com.mirantis.mk.Common()
478 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
479 run_cmd("""\
480 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
481 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
482 """)
483}
484
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300485def devops_snapshot_info(snapshot_name) {
486 // Print helper message after snapshot
487 def common = new com.mirantis.mk.Common()
488
489 def SALT_MASTER_IP=run_cmd_stdout("""\
490 . ./tcp_tests/utils/env_salt
491 echo \$SALT_MASTER_IP
492 """).trim().split().last()
493 def login = "root" // set fixed 'root' login for now
494 def password = "r00tme" // set fixed 'root' login for now
495 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
496 def VENV_PATH='/home/jenkins/fuel-devops30'
497
498 common.printMsg("""\
499#########################
500# To revert the snapshot:
501#########################
502. ${VENV_PATH}/bin/activate;
503dos.py revert ${ENV_NAME} ${snapshot_name};
504dos.py resume ${ENV_NAME};
505# dos.py time-sync ${ENV_NAME}; # Optional\n
506ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
507""", "cyan")
508}
509
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300510def devops_snapshot(stack) {
511 // Make the snapshot with name "${stack}_deployed"
512 // for all VMs in the environment.
513 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
514 // then make a copy for the created snapshot to allow the system
515 // tests to revert this snapshot along with the metadata from the INI file.
516 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300517 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300518 dos.py suspend ${ENV_NAME}
519 dos.py snapshot ${ENV_NAME} ${stack}_deployed
520 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300521 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300522
523 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
524 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
525
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300526 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
527 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
528 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300529 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300530 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300531}
532
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300533def get_steps_list(steps) {
534 // Make a list from comma separated string
535 return steps.split(',').collect { it.split(':')[0] }
536}
537
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300538def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
539 // <filename> is name of the XML report file that will be created
540 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
541 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300542
543 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
544 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
545
Dennis Dmitriev39666082018-08-29 15:30:45 +0300546 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300547<?xml version=\"1.0\" encoding=\"utf-8\"?>
548 <testsuite>
549 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300550 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300551 <system-out>${stdout}</system-out>
552 <system-err>${stderr}</system-err>
553 </testcase>
554 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300555"""
556 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300557}
558
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300559def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
560 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200561 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300562 def testrailURL = "https://mirantis.testrail.com"
563 def testrailProject = "Mirantis Cloud Platform"
564 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
565 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}