blob: 4ff3f68be21f6eaa0e335356dad721045345a8d9 [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 Dmitriev4c383472019-04-12 13:58:06 +03009def verbose_sh(String script, Boolean returnStatus=false, Boolean returnStdout=false, Boolean verboseStdout=false) {
10 def common = new com.mirantis.mk.Common()
11 common.printMsg("Run shell command:\n" + script, "blue")
12 def result = sh(script: script, returnStatus: returnStatus, returnStdout: returnStdout)
13 if (verboseStdout) {
14 common.printMsg("Output:\n" + result, "cyan")
15 }
16 return result
17}
18
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030019def run_sh(String cmd) {
20 // run shell script without catching any output
21 def common = new com.mirantis.mk.Common()
22 common.printMsg("Run shell command:\n" + cmd, "blue")
23 def VENV_PATH='/home/jenkins/fuel-devops30'
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020024 def script = """\
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +030025 set -ex;
26 . ${VENV_PATH}/bin/activate;
27 bash -c '${cmd.stripIndent()}'
28 """
29 return sh(script: script)
30}
31
Dennis Dmitriev8df35442018-07-31 08:40:20 +030032def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030033 def common = new com.mirantis.mk.Common()
34 common.printMsg("Run shell command:\n" + cmd, "blue")
35 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +030036 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020037 def script = """#!/bin/bash
38 set +x
39 echo 'activate python virtualenv ${VENV_PATH}'
40 . ${VENV_PATH}/bin/activate
41 bash -c -e -x '${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030042 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030043 try {
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020044 def stdout = sh(script: script, returnStdout: returnStdout)
45 def stderr = readFile("${stderr_path}")
46 def error_message = "\n<<<<<< STDERR: >>>>>>\n" + stderr
47 common.printMsg(error_message, "yellow")
48 common.printMsg("", "reset")
49 return stdout
Dennis Dmitriev27a96792018-07-30 07:52:03 +030050 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030051 def stderr = readFile("${stderr_path}")
52 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
Dmitry Tyzhnenkob39de052019-03-21 17:05:07 +020053 common.printMsg(error_message, "red")
54 common.printMsg("", "reset")
Dennis Dmitriev8df35442018-07-31 08:40:20 +030055 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030056 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030057 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030058 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030059}
60
61def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030062 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030063}
64
Dennis Dmitriev27a96792018-07-30 07:52:03 +030065def build_pipeline_job(job_name, parameters) {
66 //Build a job, grab the results if failed and use the results in exception
67 def common = new com.mirantis.mk.Common()
68 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
69 common.prettyPrint(parameters)
70
71 def job_info = build job: "${job_name}",
72 parameters: parameters,
73 propagate: false
74
75 if (job_info.getResult() != "SUCCESS") {
76 currentBuild.result = job_info.getResult()
77 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030078 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030079 def workflow_details=run_cmd_stdout("""\
80 export JOB_NAME=${job_name}
81 export BUILD_NUMBER=${build_number}
82 python ./tcp_tests/utils/get_jenkins_job_stages.py
83 """)
84 throw new Exception(workflow_details)
85 }
86}
87
88def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
89 //Build a job, grab the results if failed and use the results in exception
90 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
91 def common = new com.mirantis.mk.Common()
92 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
93 common.prettyPrint(parameters)
94
95 def job_info = build job: "${job_name}",
96 parameters: parameters,
97 propagate: false
98
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020099 def build_number = job_info.getNumber()
100 def build_url = job_info.getAbsoluteUrl()
101 def build_status = job_info.getResult()
102 try {
103 // Try to grab 'tar.gz' articacts from the shell job'
104 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
105 projectName: job_name,
106 selector: specific("${build_number}"),
107 filter: "**/*.tar.gz",
108 target: '.',
109 flatten: true,
110 fingerprintArtifacts: true)
111 } catch (none) {
112 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
113 }
114
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300115 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300116 def job_url = "${build_url}"
117 currentBuild.result = build_status
118 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300119 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300120 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
121 projectName: job_name,
122 selector: specific("${build_number}"),
123 filter: "${junit_report_source_dir}/${junit_report_filename}",
124 target: '.',
125 flatten: true,
126 fingerprintArtifacts: true)
127
128 def String junit_report_xml = readFile("${junit_report_filename}")
129 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
130 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300131 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300132 } else {
133 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
134 }
135 }
136}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300137
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300138def prepare_working_dir(env_manager) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300139 println "Clean the working directory ${env.WORKSPACE}"
140 deleteDir()
141
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300142 if (env_manager == 'devops') {
143 // do not fail if environment doesn't exists
144 println "Remove fuel-devops environment '${ENV_NAME}'"
145 run_cmd("""\
146 dos.py erase ${ENV_NAME} || true
147 """)
148 } else if (env_manager == 'heat') {
149 // delete heat stack
150 println "Remove heat stack '${ENV_NAME}'"
151 withCredentials([
152 [$class : 'UsernamePasswordMultiBinding',
153 credentialsId : env.OS_CREDENTIALS,
154 passwordVariable: 'OS_PASSWORD',
155 usernameVariable: 'OS_USERNAME']
156 ]) {
157 run_cmd("""\
158 export OS_IDENTITY_API_VERSION=3
159 export OS_AUTH_URL=${OS_AUTH_URL}
160 export OS_USERNAME=${OS_USERNAME}
161 export OS_PASSWORD=${OS_PASSWORD}
162 export OS_PROJECT_NAME=${OS_PROJECT_NAME}
163 export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME}
164 openstack --insecure stack delete -y ${ENV_NAME} || true
Hanna Arhipova8b45a712020-05-25 14:21:58 +0300165 timeout 20m /bin/bash -c "while openstack --insecure stack show ${ENV_NAME} -f value -c stack_status; do sleep 10; done"
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300166 """)
167 }
168
169 } else {
170 throw new Exception("Unknown env_manager: '${env_manager}'")
171 }
172
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300173 println "Remove config drive ISO"
174 run_cmd("""\
175 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
176 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300177
178 run_cmd("""\
Hanna Arhipova5173aad2019-11-11 12:42:31 +0200179 git clone https://gerrit.mcp.mirantis.com/mcp/tcp-qa ${env.WORKSPACE}
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300180 if [ -n "$TCP_QA_REFS" ]; then
181 set -e
Hanna Arhipova5173aad2019-11-11 12:42:31 +0200182 git fetch https://gerrit.mcp.mirantis.com/mcp/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300183 fi
184 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300185 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300186}
187
Dennis Dmitriev056ecbf2019-05-20 15:36:29 +0300188def update_working_dir(Boolean updateRequirements=true) {
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300189 // Use to fetch a patchset from gerrit to the working dir
190 run_cmd("""\
191 if [ -n "$TCP_QA_REFS" ]; then
192 set -e
Hanna Arhipova5173aad2019-11-11 12:42:31 +0200193 git reset --hard && git fetch https://gerrit.mcp.mirantis.com/mcp/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
Dennis Dmitriev056ecbf2019-05-20 15:36:29 +0300194 fi""")
195 if (updateRequirements) {
196 run_cmd("""\
197 pip install -r tcp_tests/requirements.txt
198 """)
199 }
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300200}
201
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300202def swarm_bootstrap_salt_cluster_devops() {
203 def common = new com.mirantis.mk.Common()
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200204 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: is_released_version(env.MCP_VERSION) ? "refs/tags/${env.MCP_VERSION}" : 'master'
205 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "refs/tags/${env.MCP_VERSION}"
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300206 def jenkins_pipelines_branch = env.JENKINS_PIPELINE_BRANCH ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300207 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
208 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
209 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
210 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300211 def mcp_common_scripts_refs = env.MCP_COMMON_SCRIPTS_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300212 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200213 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
214 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300215 def deploy_network_mask = env.DEPLOY_NETWORK_NETMASK ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200216 def env_ipmi_user = env.IPMI_USER ?: ''
217 def env_ipmi_pass = env.IPMI_PASS ?: ''
Oleksii Butenkoab538de2019-09-23 18:26:57 +0300218 def env_cisco_pass = env.CISCO_PASS ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200219 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
220 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200221 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300222 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300223 def parameters = [
224 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
225 string(name: 'PARENT_WORKSPACE', value: pwd()),
226 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
227 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
228 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
229 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
230 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
231 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300232 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
233 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
234 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
235 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
236 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
237 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
238 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200239 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
240 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300241 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200242 string(name: 'IPMI_USER', value: env_ipmi_user),
243 string(name: 'IPMI_PASS', value: env_ipmi_pass),
Oleksii Butenkoab538de2019-09-23 18:26:57 +0300244 string(name: 'CISCO_PASS', value: env_cisco_pass),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200245 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
246 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200247 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300248 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300249 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
250 string(name: 'UPDATE_VERSION', value: "${update_version}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300251 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
252 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300253
254 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300255}
256
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300257def swarm_bootstrap_salt_cluster_heat(String jenkins_slave_node_name) {
258 // jenkins_slave_node_name
259 def common = new com.mirantis.mk.Common()
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200260 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "refs/tags/${env.MCP_VERSION}"
261 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "refs/tags/${env.MCP_VERSION}"
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300262 def mcp_common_scripts_refs = env.MCP_COMMON_SCRIPTS_REFS ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300263 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
264 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300265 def jenkins_pipelines_branch = env.JENKINS_PIPELINE_BRANCH ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300266 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
267 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
268 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
269 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
270 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
271 def env_ipmi_user = env.IPMI_USER ?: ''
272 def env_ipmi_pass = env.IPMI_PASS ?: ''
Oleksii Butenkoab538de2019-09-23 18:26:57 +0300273 def env_cisco_pass = env.CISCO_PASS ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300274 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
275 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
276 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300277 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300278 def parameters = [
279 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
280 string(name: 'JENKINS_SLAVE_NODE_NAME', value: jenkins_slave_node_name),
281 string(name: 'PARENT_WORKSPACE', value: pwd()),
282 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
283 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
284 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
285 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
286 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
287 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
288 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
289 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
290 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
291 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
292 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
293 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
294 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
295 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
296 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300297 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
298 string(name: 'UPDATE_VERSION', value: "${update_version}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300299 string(name: 'IPMI_USER', value: env_ipmi_user),
300 string(name: 'IPMI_PASS', value: env_ipmi_pass),
Oleksii Butenkoab538de2019-09-23 18:26:57 +0300301 string(name: 'CISCO_PASS', value: env_cisco_pass),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300302 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
303 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
304 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
305 string(name: 'OS_AUTH_URL', value: "${OS_AUTH_URL}"),
306 string(name: 'OS_PROJECT_NAME', value: "${OS_PROJECT_NAME}"),
307 string(name: 'OS_USER_DOMAIN_NAME', value: "${OS_USER_DOMAIN_NAME}"),
308 string(name: 'OS_CREDENTIALS', value: "${OS_CREDENTIALS}"),
309 string(name: 'LAB_PARAM_DEFAULTS', value: "${LAB_PARAM_DEFAULTS}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300310 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300311 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
312 ]
313
314 build_pipeline_job('swarm-bootstrap-salt-cluster-heat', parameters)
315}
316
PGlazoved19b352020-05-21 16:42:27 +0400317def swarm_deploy_cicd(String stack_to_install, String install_timeout, String jenkins_slave_node_name, Boolean make_snapshot_stages, String batch_size, Boolean dist_upgrade_nodes, Boolean upgrade_saltstack) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300318 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
319 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300320 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300321 def parameters = [
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300322 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300323 string(name: 'PARENT_WORKSPACE', value: pwd()),
324 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
325 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200326 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300327 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Hanna Arhipova6f493522019-12-25 04:23:28 +0200328 string(name: 'BATCH_SIZE', value: batch_size),
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +0100329 booleanParam(name: 'DIST_UPGRADE_NODES', value: dist_upgrade_nodes),
PGlazoved19b352020-05-21 16:42:27 +0400330 booleanParam(name: 'UPGRADE_SALTSTACK', value: upgrade_saltstack),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300331 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300332 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
333 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300334 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300335}
336
Hanna Arhipovaddd35a22020-05-27 12:39:26 +0300337def swarm_deploy_platform(String stack_to_install, String install_timeout, String jenkins_slave_node_name, Boolean make_snapshot_stages, String batch_size, Boolean dist_upgrade_nodes, Boolean upgrade_saltstack) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300338 // Run openstack_deploy job on CICD Jenkins for specified stacks
339 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300340 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300341 def parameters = [
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300342 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300343 string(name: 'PARENT_WORKSPACE', value: pwd()),
344 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
345 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200346 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300347 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Hanna Arhipova6f493522019-12-25 04:23:28 +0200348 string(name: 'BATCH_SIZE', value: batch_size),
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +0100349 booleanParam(name: 'DIST_UPGRADE_NODES', value: dist_upgrade_nodes),
PGlazoved19b352020-05-21 16:42:27 +0400350 booleanParam(name: 'UPGRADE_SALTSTACK', value: upgrade_saltstack),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300351 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300352 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
353 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300354 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300355}
356
sgudz2ed95852019-03-01 14:48:52 +0200357def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
358 // Run openstack_deploy job on day01 Jenkins for specified stacks
359 def common = new com.mirantis.mk.Common()
360 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
361 def parameters = [
362 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
363 string(name: 'PARENT_WORKSPACE', value: pwd()),
364 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
365 string(name: 'STACK_INSTALL', value: stack_to_install),
366 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
367 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
368 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
369 ]
370 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
371}
372
Dennis Dmitriev02447412019-04-17 18:02:46 +0300373def swarm_run_pytest(String passed_steps, String jenkins_slave_node_name, Boolean make_snapshot_stages) {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300374 // Run pytest tests
375 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300376 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Oleksii Butenkoec78c9f2019-04-04 16:26:20 +0300377 def tempest_extra_args = env.TEMPEST_EXTRA_ARGS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200378 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200379 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Andrew Baraniukd1586342019-06-12 11:41:20 +0300380 def tempest_pattern=env.TEMPEST_PATTERN ?: 'tempest'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300381 def parameters = [
382 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
383 string(name: 'PASSED_STEPS', value: passed_steps),
Hanna Arhipova798759d2020-02-19 14:07:50 +0200384 text(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300385 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300386 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300387 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300388 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200389 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200390 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Hanna Arhipovac8875442020-07-10 13:22:59 +0300391 string(name: 'TEMPEST_PATTERN', value: "${tempest_pattern}"),
392 string(name: 'TEMPEST_EXTRA_ARGS', value: "${tempest_extra_args}"),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300393 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300394 ]
395 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
396 common.prettyPrint(parameters)
397 build job: 'swarm-run-pytest',
398 parameters: parameters
399}
400
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300401def swarm_testrail_report(String passed_steps, String node_with_reports) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300402 // Run pytest tests
403 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300404 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200405 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400406 def test_plan_name_prefix = env.TEST_PLAN_NAME_PREFIX ?: ''
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300407 def parameters = [
408 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200409 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300410 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
411 string(name: 'PASSED_STEPS', value: passed_steps),
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300412 string(name: 'PARENT_NODE_NAME', value: node_with_reports),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300413 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300414 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200415 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Hanna Arhipova705a2892020-09-25 12:40:39 +0300416 string(name: 'TEST_PLAN_NAME_PREFIX', value: "${test_plan_name_prefix}")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300417 ]
418 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
419 common.prettyPrint(parameters)
420 build job: 'swarm-testrail-report',
421 parameters: parameters
422}
423
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300424def generate_cookied_model(IPV4_NET_ADMIN, IPV4_NET_CONTROL, IPV4_NET_TENANT, IPV4_NET_EXTERNAL) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300425 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300426 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
427 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
428 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
429 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
430
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200431 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: is_released_version(env.MCP_VERSION) ? "refs/tags/${env.MCP_VERSION}" : 'master'
432 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "refs/tags/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300433 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
434 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
435 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300436 def jenkins_pipelines_branch=env.JENKINS_PIPELINE_BRANCH ?: ''
sgudzb7953382019-02-18 17:59:30 +0200437 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300438 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300439
440 def parameters = [
441 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
442 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
443 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
444 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
445 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
446 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300447 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
448 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
449 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300450 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
451 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
452 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
453 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200454 string(name: 'IPMI_USER', value: env.IPMI_USER),
455 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
Oleksii Butenkoab538de2019-09-23 18:26:57 +0300456 string(name: 'CISCO_PASS', value: env.CISCO_PASS),
sgudzb7953382019-02-18 17:59:30 +0200457 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300458 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
sgudzc97385a2018-11-29 17:01:53 +0200459 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300460 string(name: 'UPDATE_VERSION', value: "${update_version}"),
461
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300462 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300463
464 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300465}
466
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300467def generate_configdrive_iso(SALT_MASTER_IP, ADMIN_NETWORK_GW) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300468 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300469 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300470 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
471
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300472 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300473 def mcp_common_scripts_ref = env.MCP_COMMON_SCRIPTS_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300474 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300475 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300476 def update_version = env.UPDATE_VERSION?: 'proposed'
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200477 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
478 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300479 def deploy_network_mask = env.DEPLOY_NETWORK_NETMASK ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300480
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300481 def parameters = [
482 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200483 string(name: 'MODEL_URL', value: "http://sre-ci.scc.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300484 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
485 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
486 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Hanna Arhipovac2965a42020-01-21 12:27:33 +0200487 string(name: 'COMMON_SCRIPTS_COMMIT', value: "refs/tags/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300488 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
489 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
490 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300491 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300492 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
493 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200494 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
495 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300496 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300497 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
498 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300499 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300500 string(name: 'UPDATE_VERSION', value: "${update_version}"),
501 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_ref}"),
502 string(name: 'MCP_SALT_REPO_UPDATES', value: "'deb [arch=amd64] http://mirror.mirantis.com/update/${UPDATE_VERSION}/salt-formulas/xenial xenial main'"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300503 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300504 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300505}
506
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300507def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300508 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200509 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300510 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200511 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300512 try {
513 run_cmd("""\
514 export ENV_NAME=${ENV_NAME}
515 . ./tcp_tests/utils/env_salt
516 . ./tcp_tests/utils/env_jenkins_day01
517 export JENKINS_BUILD_TIMEOUT=${timeout}
518 JOB_PARAMETERS=\"{
519 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
Hanna Arhipova6f493522019-12-25 04:23:28 +0200520 \\\"BATCH_SIZE\\\": \\\"\${BATCH_SIZE}\\\",
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +0100521 \\\"STACK_INSTALL\\\": \\\"${stack}\\\",
PGlazoved19b352020-05-21 16:42:27 +0400522 \\\"DIST_UPGRADE_NODES\\\": \\\"\${DIST_UPGRADE_NODES}\\\",
523 \\\"UPGRADE_SALTSTACK\\\": \\\"\${UPGRADE_SALTSTACK}\\\"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300524 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200525 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300526 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
527 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200528 // Wait for IO calm down on cluster nodes
529 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300530 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300531 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300532 def workflow_details=run_cmd_stdout("""\
533 . ./tcp_tests/utils/env_salt
534 . ./tcp_tests/utils/env_jenkins_day01
535 export JOB_NAME=deploy_openstack
536 export BUILD_NUMBER=lastBuild
537 python ./tcp_tests/utils/get_jenkins_job_stages.py
538 """)
539 throw new Exception(workflow_details)
540 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300541}
542
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300543def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300544 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200545 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300546 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200547 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300548 try {
549 run_cmd("""\
550 export ENV_NAME=${ENV_NAME}
551 . ./tcp_tests/utils/env_salt
552 . ./tcp_tests/utils/env_jenkins_cicd
553 export JENKINS_BUILD_TIMEOUT=${timeout}
554 JOB_PARAMETERS=\"{
555 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
Hanna Arhipova6f493522019-12-25 04:23:28 +0200556 \\\"BATCH_SIZE\\\": \\\"\${BATCH_SIZE}\\\",
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +0100557 \\\"STACK_INSTALL\\\": \\\"${stack}\\\",
PGlazoved19b352020-05-21 16:42:27 +0400558 \\\"DIST_UPGRADE_NODES\\\": \\\"\${DIST_UPGRADE_NODES}\\\",
559 \\\"UPGRADE_SALTSTACK\\\": \\\"\${UPGRADE_SALTSTACK}\\\"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300560 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200561 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300562 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 +0300563 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200564 // Wait for IO calm down on cluster nodes
565 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300566 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300567 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300568 def workflow_details=run_cmd_stdout("""\
569 . ./tcp_tests/utils/env_salt
570 . ./tcp_tests/utils/env_jenkins_cicd
571 export JOB_NAME=deploy_openstack
572 export BUILD_NUMBER=lastBuild
573 python ./tcp_tests/utils/get_jenkins_job_stages.py
574 """)
575 throw new Exception(workflow_details)
576 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300577}
578
579def sanity_check_component(stack) {
580 // Run sanity check for the component ${stack}.
581 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300582 try {
583 run_cmd("""\
Dennis Dmitriev27007322019-05-03 19:21:44 +0300584 export LOG_NAME=deploy_${stack}_test.log
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300585 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
586 """)
587 } catch (e) {
588 def String junit_report_xml = readFile("deploy_${stack}.xml")
589 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
590 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
591 throw new Exception(msg + junit_report_xml_pretty)
592 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300593}
594
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300595def download_logs(archive_name_prefix) {
596 // Archive and download logs and debug info from salt nodes in the lab
597 // Do not fail in case of error to not lose the original error from the parent exception.
598 def common = new com.mirantis.mk.Common()
599 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
600 run_cmd("""\
601 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
602 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
603 """)
604}
605
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300606def devops_snapshot_info(snapshot_name) {
607 // Print helper message after snapshot
608 def common = new com.mirantis.mk.Common()
609
610 def SALT_MASTER_IP=run_cmd_stdout("""\
611 . ./tcp_tests/utils/env_salt
612 echo \$SALT_MASTER_IP
613 """).trim().split().last()
614 def login = "root" // set fixed 'root' login for now
615 def password = "r00tme" // set fixed 'root' login for now
616 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
617 def VENV_PATH='/home/jenkins/fuel-devops30'
618
619 common.printMsg("""\
620#########################
621# To revert the snapshot:
622#########################
623. ${VENV_PATH}/bin/activate;
624dos.py revert ${ENV_NAME} ${snapshot_name};
625dos.py resume ${ENV_NAME};
626# dos.py time-sync ${ENV_NAME}; # Optional\n
627ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
628""", "cyan")
629}
630
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300631def devops_snapshot(stacks) {
632 // Make snapshots with names "${stack}_deployed" for each stack
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300633 // for all VMs in the environment.
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300634
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300635 run_cmd("""\
636 dos.py suspend ${ENV_NAME}
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300637 """)
638
639 for (stack in "${stacks}".split(",")) {
640 run_cmd("""\
641 dos.py snapshot ${ENV_NAME} ${stack}_deployed
642 """)
643 devops_snapshot_info("${stack}_deployed")
644 }
645
646 run_cmd("""\
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300647 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300648 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300649
650 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
651 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300652 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300653}
654
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300655def get_steps_list(steps) {
656 // Make a list from comma separated string
657 return steps.split(',').collect { it.split(':')[0] }
658}
659
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300660def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
661 // <filename> is name of the XML report file that will be created
662 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
663 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300664
665 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
Hanna Arhipova70685072021-01-25 16:11:57 +0200666 def String text_filtered = text.replaceAll("&", "&amp;").
667 replaceAll("<","&lt;").
Hanna Arhipova413c1db2020-02-11 15:37:48 +0200668 replaceAll(">", "&gt;").
669 replaceAll("[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+", "")
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300670
Dennis Dmitriev39666082018-08-29 15:30:45 +0300671 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300672<?xml version=\"1.0\" encoding=\"utf-8\"?>
673 <testsuite>
674 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300675 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300676 <system-out>${stdout}</system-out>
677 <system-err>${stderr}</system-err>
678 </testcase>
679 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300680"""
681 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300682}
683
Hanna Arhipova1b92f9b2020-10-05 15:50:25 +0300684def upload_results_to_testrail(report_name, testPlanName, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300685 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200686 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300687 def testrailURL = "https://mirantis.testrail.com"
688 def testrailProject = "Mirantis Cloud Platform"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300689 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300690 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300691 def jobURL = env.BUILD_URL
692
693 def reporterOptions = [
694 "--verbose",
695 "--env-description \"${testPlanDesc}\"",
696 "--testrail-run-update",
697 "--testrail-url \"${testrailURL}\"",
698 "--testrail-user \"\${TESTRAIL_USER}\"",
699 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
700 "--testrail-project \"${testrailProject}\"",
701 "--testrail-plan-name \"${testPlanName}\"",
702 "--testrail-milestone \"${testrailMilestone}\"",
703 "--testrail-suite \"${testSuiteName}\"",
704 "--xunit-name-template \"${methodname}\"",
705 "--testrail-name-template \"${testrail_name_template}\"",
706 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300707 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300708 ] + reporter_extra_options
709
710 def script = """
711 . ${venvPath}/bin/activate
712 set -ex
Ekaterina Chernova0d81efc2019-10-28 16:23:17 +0300713 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300714 """
715
716 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
717
718 withCredentials([
719 [$class : 'UsernamePasswordMultiBinding',
720 credentialsId : testrail_cred_id,
721 passwordVariable: 'TESTRAIL_PASSWORD',
722 usernameVariable: 'TESTRAIL_USER']
723 ]) {
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300724 def ret = [:]
725 ret.stdout = ''
726 ret.exception = ''
727 try {
728 ret.stdout = run_cmd_stdout(script)
729 } catch (Exception ex) {
730 ret.exception = ("""\
731##### Report to '${testSuiteName}' failed: #####\n""" + ex.message + "\n\n")
732 }
733 return ret
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300734 }
735}
736
737
738def create_deploy_result_report(deploy_expected_stacks, result, text) {
739 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
740 def classname = "Deploy"
741 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300742 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300743 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
744 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300745}
Hanna Arhipova1b92f9b2020-10-05 15:50:25 +0300746
747def mark_test_results(testPlanName, testSuiteName) {
748 def venvPath = '/home/jenkins/venv_testrail_analyzer'
749 def testrailURL = "https://mirantis.testrail.com"
750 def testrailProject = "Mirantis Cloud Platform"
751 def configName = env.LAB_CONFIG_NAME
752 def testRunName = "${configName} <${testSuiteName}>"
753
754 def script = """
755 . ${venvPath}/bin/activate
756 set -ex
757 export TESTRAIL_URL=${testrailURL}
758 testrail-reporter analyze -p "${testrailProject}" -t "${testPlanName}" -r "${testRunName}" checklist.yaml
759 """
760
761 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
762
763 withCredentials([
764 [$class : 'UsernamePasswordMultiBinding',
765 credentialsId : testrail_cred_id,
766 passwordVariable: 'TESTRAIL_PASSWORD',
767 usernameVariable: 'TESTRAIL_USER']
768 ]) {
769 def ret = [:]
770 ret.stdout = ''
771 ret.exception = ''
772 try {
773 ret.stdout = run_cmd_stdout(script)
774 } catch (Exception ex) {
775 ret.exception = ("""\
776##### Report to '${testRunName}' failed: #####\n""" + ex.message + "\n\n")
777 }
778 return ret
779 }
Hanna Arhipova3be50622021-01-11 13:11:45 +0200780}
781
782def reboot_hardware_nodes() {
783 bm_ips = [
784 "185.8.59.227",
785 "185.8.59.229",
786 "5.43.225.88",
787 "5.43.225.112",
788 "5.43.225.208",
789 "5.43.227.118",
790 "185.8.58.248",
791 "185.8.59.222",
792 "5.43.225.228",
793 "5.43.229.28",
794 "5.43.225.23",
795 "185.8.58.9",
796 "185.8.58.246",
797 "185.8.58.243",
798 "185.8.58.244"
799 ]
800
801 withCredentials([
802 [$class : 'UsernamePasswordMultiBinding',
803 credentialsId : 'lab_engineer',
804 passwordVariable: 'lab_pass',
805 usernameVariable: 'lab_user']
806 ]) {
807 for (ip in bm_ips) { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} chassis power off")}
808 for (ip in bm_ips) { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} chassis bootdev pxe")}
809 }
Hanna Arhipova1b92f9b2020-10-05 15:50:25 +0300810}