blob: 4c6a95bef55b94226fd2c7071ed5019904daa5cb [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'
10 script = """\
11 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"
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030023 script = """\
24 set +x;
25 echo 'activate python virtualenv ${VENV_PATH}';
26 . ${VENV_PATH}/bin/activate;
Dennis Dmitriev8df35442018-07-31 08:40:20 +030027 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030028 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030029 def result
30 try {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030031 return sh(script: script, returnStdout: returnStdout)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030032 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030033 def stderr = readFile("${stderr_path}")
34 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
35 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030036 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030037 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030038 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030039}
40
41def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030042 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030043}
44
Dennis Dmitriev27a96792018-07-30 07:52:03 +030045def build_pipeline_job(job_name, parameters) {
46 //Build a job, grab the results if failed and use the results in exception
47 def common = new com.mirantis.mk.Common()
48 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
49 common.prettyPrint(parameters)
50
51 def job_info = build job: "${job_name}",
52 parameters: parameters,
53 propagate: false
54
55 if (job_info.getResult() != "SUCCESS") {
56 currentBuild.result = job_info.getResult()
57 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030058 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030059 def workflow_details=run_cmd_stdout("""\
60 export JOB_NAME=${job_name}
61 export BUILD_NUMBER=${build_number}
62 python ./tcp_tests/utils/get_jenkins_job_stages.py
63 """)
64 throw new Exception(workflow_details)
65 }
66}
67
68def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
69 //Build a job, grab the results if failed and use the results in exception
70 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
71 def common = new com.mirantis.mk.Common()
72 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
73 common.prettyPrint(parameters)
74
75 def job_info = build job: "${job_name}",
76 parameters: parameters,
77 propagate: false
78
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020079 def build_number = job_info.getNumber()
80 def build_url = job_info.getAbsoluteUrl()
81 def build_status = job_info.getResult()
82 try {
83 // Try to grab 'tar.gz' articacts from the shell job'
84 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
85 projectName: job_name,
86 selector: specific("${build_number}"),
87 filter: "**/*.tar.gz",
88 target: '.',
89 flatten: true,
90 fingerprintArtifacts: true)
91 } catch (none) {
92 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
93 }
94
Dennis Dmitriev27a96792018-07-30 07:52:03 +030095 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +030096 def job_url = "${build_url}"
97 currentBuild.result = build_status
98 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030099 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300100 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
101 projectName: job_name,
102 selector: specific("${build_number}"),
103 filter: "${junit_report_source_dir}/${junit_report_filename}",
104 target: '.',
105 flatten: true,
106 fingerprintArtifacts: true)
107
108 def String junit_report_xml = readFile("${junit_report_filename}")
109 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
110 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300111 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300112 } else {
113 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
114 }
115 }
116}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300117
118def prepare_working_dir() {
119 println "Clean the working directory ${env.WORKSPACE}"
120 deleteDir()
121
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300122 // do not fail if environment doesn't exists
123 println "Remove environment ${ENV_NAME}"
124 run_cmd("""\
125 dos.py erase ${ENV_NAME} || true
126 """)
127 println "Remove config drive ISO"
128 run_cmd("""\
129 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
130 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300131
132 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300133 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
134 if [ -n "$TCP_QA_REFS" ]; then
135 set -e
136 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
137 fi
138 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300139 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300140}
141
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300142def update_working_dir() {
143 // Use to fetch a patchset from gerrit to the working dir
144 run_cmd("""\
145 if [ -n "$TCP_QA_REFS" ]; then
146 set -e
147 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
148 fi
149 pip install -r tcp_tests/requirements.txt
150 """)
151}
152
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300153def swarm_bootstrap_salt_cluster_devops() {
154 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300155 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
156 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
157 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
158 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
159 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
160 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
161 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200162 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
163 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200164 def env_ipmi_user = env.IPMI_USER ?: ''
165 def env_ipmi_pass = env.IPMI_PASS ?: ''
166 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
167 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300168 def parameters = [
169 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
170 string(name: 'PARENT_WORKSPACE', value: pwd()),
171 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
172 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
173 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
174 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
175 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
176 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300177 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
178 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
179 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
180 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
181 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
182 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
183 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200184 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
185 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200186 string(name: 'IPMI_USER', value: env_ipmi_user),
187 string(name: 'IPMI_PASS', value: env_ipmi_pass),
188 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
189 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300190 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
191 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300192
193 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300194}
195
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200196def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300197 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
198 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300199 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300200 def parameters = [
201 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
202 string(name: 'PARENT_WORKSPACE', value: pwd()),
203 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
204 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200205 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300206 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300207 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
208 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300209 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300210}
211
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200212def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300213 // Run openstack_deploy job on CICD Jenkins for specified stacks
214 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300215 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300216 def parameters = [
217 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
218 string(name: 'PARENT_WORKSPACE', value: pwd()),
219 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
220 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200221 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300222 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300223 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
224 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300225 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300226}
227
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300228def swarm_run_pytest(String passed_steps) {
229 // Run pytest tests
230 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300231 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200232 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300233 def parameters = [
234 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
235 string(name: 'PASSED_STEPS', value: passed_steps),
236 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
237 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
238 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300239 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300240 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
241 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
242 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
243 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
244 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200245 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200246
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300247 ]
248 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
249 common.prettyPrint(parameters)
250 build job: 'swarm-run-pytest',
251 parameters: parameters
252}
253
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300254def swarm_testrail_report(String passed_steps) {
255 // Run pytest tests
256 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300257 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200258 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300259 def parameters = [
260 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
261 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
262 string(name: 'PASSED_STEPS', value: passed_steps),
263 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
264 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300265 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200266 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300267 ]
268 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
269 common.prettyPrint(parameters)
270 build job: 'swarm-testrail-report',
271 parameters: parameters
272}
273
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300274def generate_cookied_model() {
275 def common = new com.mirantis.mk.Common()
276 // do not fail if environment doesn't exists
277 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
278 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
279 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
280 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
281 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
282 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
283 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
284 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
285
286 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
287 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300288 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
289 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
290 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300291
292 def parameters = [
293 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
294 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
295 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
296 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
297 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
298 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300299 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
300 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
301 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300302 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
303 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
304 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
305 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200306 string(name: 'IPMI_USER', value: env.IPMI_USER),
307 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
308 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300309 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300310
311 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300312}
313
314def generate_configdrive_iso() {
315 def common = new com.mirantis.mk.Common()
316 def SALT_MASTER_IP=run_cmd_stdout("""\
317 export ENV_NAME=${ENV_NAME}
318 . ./tcp_tests/utils/env_salt
319 echo \$SALT_MASTER_IP
320 """).trim().split().last()
321 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300322
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300323 def dhcp_ranges_json=run_cmd_stdout("""\
324 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
325 fgrep "admin-pool01"|
326 cut -d"=" -f2
327 """).trim().split("\n").last()
328 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
329 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
330 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
331
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300332 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
333 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300334 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200335 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
336 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300337
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300338 def parameters = [
339 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
340 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
341 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
342 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
343 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
344 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
345 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
346 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
347 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300348 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300349 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
350 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200351 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
352 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300353 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
354 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300355 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300356 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300357 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300358}
359
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300360def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300361 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200362 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300363 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200364 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300365 try {
366 run_cmd("""\
367 export ENV_NAME=${ENV_NAME}
368 . ./tcp_tests/utils/env_salt
369 . ./tcp_tests/utils/env_jenkins_day01
370 export JENKINS_BUILD_TIMEOUT=${timeout}
371 JOB_PARAMETERS=\"{
372 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
373 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
374 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200375 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300376 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
377 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200378 // Wait for IO calm down on cluster nodes
379 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300380 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300381 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300382 def workflow_details=run_cmd_stdout("""\
383 . ./tcp_tests/utils/env_salt
384 . ./tcp_tests/utils/env_jenkins_day01
385 export JOB_NAME=deploy_openstack
386 export BUILD_NUMBER=lastBuild
387 python ./tcp_tests/utils/get_jenkins_job_stages.py
388 """)
389 throw new Exception(workflow_details)
390 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300391}
392
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300393def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300394 // stack_to_install="k8s,calico,stacklight"
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 Platform 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_cicd
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}:platform {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"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300410 """)
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_cicd
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
426def sanity_check_component(stack) {
427 // Run sanity check for the component ${stack}.
428 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300429 try {
430 run_cmd("""\
431 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
432 """)
433 } catch (e) {
434 def String junit_report_xml = readFile("deploy_${stack}.xml")
435 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
436 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
437 throw new Exception(msg + junit_report_xml_pretty)
438 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300439}
440
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300441def download_logs(archive_name_prefix) {
442 // Archive and download logs and debug info from salt nodes in the lab
443 // Do not fail in case of error to not lose the original error from the parent exception.
444 def common = new com.mirantis.mk.Common()
445 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
446 run_cmd("""\
447 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
448 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
449 """)
450}
451
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300452def devops_snapshot_info(snapshot_name) {
453 // Print helper message after snapshot
454 def common = new com.mirantis.mk.Common()
455
456 def SALT_MASTER_IP=run_cmd_stdout("""\
457 . ./tcp_tests/utils/env_salt
458 echo \$SALT_MASTER_IP
459 """).trim().split().last()
460 def login = "root" // set fixed 'root' login for now
461 def password = "r00tme" // set fixed 'root' login for now
462 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
463 def VENV_PATH='/home/jenkins/fuel-devops30'
464
465 common.printMsg("""\
466#########################
467# To revert the snapshot:
468#########################
469. ${VENV_PATH}/bin/activate;
470dos.py revert ${ENV_NAME} ${snapshot_name};
471dos.py resume ${ENV_NAME};
472# dos.py time-sync ${ENV_NAME}; # Optional\n
473ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
474""", "cyan")
475}
476
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300477def devops_snapshot(stack) {
478 // Make the snapshot with name "${stack}_deployed"
479 // for all VMs in the environment.
480 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
481 // then make a copy for the created snapshot to allow the system
482 // tests to revert this snapshot along with the metadata from the INI file.
483 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300484 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300485 dos.py suspend ${ENV_NAME}
486 dos.py snapshot ${ENV_NAME} ${stack}_deployed
487 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300488 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300489
490 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
491 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
492
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300493 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
494 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
495 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300496 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300497 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300498}
499
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300500def get_steps_list(steps) {
501 // Make a list from comma separated string
502 return steps.split(',').collect { it.split(':')[0] }
503}
504
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300505def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
506 // <filename> is name of the XML report file that will be created
507 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
508 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300509
510 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
511 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
512
Dennis Dmitriev39666082018-08-29 15:30:45 +0300513 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300514<?xml version=\"1.0\" encoding=\"utf-8\"?>
515 <testsuite>
516 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300517 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300518 <system-out>${stdout}</system-out>
519 <system-err>${stderr}</system-err>
520 </testcase>
521 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300522"""
523 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300524}
525
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300526def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
527 def venvPath = '/home/jenkins/venv_testrail_reporter'
528 def testPlanDesc = env.ENV_NAME
529 def testrailURL = "https://mirantis.testrail.com"
530 def testrailProject = "Mirantis Cloud Platform"
531 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
532 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300533 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300534 def jobURL = env.BUILD_URL
535
536 def reporterOptions = [
537 "--verbose",
538 "--env-description \"${testPlanDesc}\"",
539 "--testrail-run-update",
540 "--testrail-url \"${testrailURL}\"",
541 "--testrail-user \"\${TESTRAIL_USER}\"",
542 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
543 "--testrail-project \"${testrailProject}\"",
544 "--testrail-plan-name \"${testPlanName}\"",
545 "--testrail-milestone \"${testrailMilestone}\"",
546 "--testrail-suite \"${testSuiteName}\"",
547 "--xunit-name-template \"${methodname}\"",
548 "--testrail-name-template \"${testrail_name_template}\"",
549 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300550 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300551 ] + reporter_extra_options
552
553 def script = """
554 . ${venvPath}/bin/activate
555 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300556 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300557 """
558
559 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
560
561 withCredentials([
562 [$class : 'UsernamePasswordMultiBinding',
563 credentialsId : testrail_cred_id,
564 passwordVariable: 'TESTRAIL_PASSWORD',
565 usernameVariable: 'TESTRAIL_USER']
566 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300567 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300568 }
569}
570
571
572def create_deploy_result_report(deploy_expected_stacks, result, text) {
573 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
574 def classname = "Deploy"
575 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300576 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300577 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
578 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300579}