blob: 0e0fdda745de95be9d3edc72d6c2ece0a6dc0e79 [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
165 while openstack --insecure stack show ${ENV_NAME} -f value -c stack_status; do sleep 10; done
166 """)
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("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300179 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
180 if [ -n "$TCP_QA_REFS" ]; then
181 set -e
182 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
183 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
Sergey Galkin173f4c22019-08-22 15:23:50 +0400193 git reset --hard && git fetch https://review.gerrithub.io/Mirantis/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()
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +0400204 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 +0200205 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${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 ?: ''
218 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
219 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200220 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300221 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300222 def parameters = [
223 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
224 string(name: 'PARENT_WORKSPACE', value: pwd()),
225 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
226 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
227 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
228 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
229 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
230 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300231 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
232 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
233 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
234 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
235 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
236 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
237 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200238 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
239 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300240 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200241 string(name: 'IPMI_USER', value: env_ipmi_user),
242 string(name: 'IPMI_PASS', value: env_ipmi_pass),
243 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
244 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200245 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300246 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300247 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
248 string(name: 'UPDATE_VERSION', value: "${update_version}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300249 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
250 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300251
252 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300253}
254
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300255def swarm_bootstrap_salt_cluster_heat(String jenkins_slave_node_name) {
256 // jenkins_slave_node_name
257 def common = new com.mirantis.mk.Common()
258 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
259 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300260 def mcp_common_scripts_refs = env.MCP_COMMON_SCRIPTS_REFS ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300261 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
262 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300263 def jenkins_pipelines_branch = env.JENKINS_PIPELINE_BRANCH ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300264 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
265 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
266 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
267 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
268 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
269 def env_ipmi_user = env.IPMI_USER ?: ''
270 def env_ipmi_pass = env.IPMI_PASS ?: ''
271 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
272 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
273 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300274 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300275 def parameters = [
276 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
277 string(name: 'JENKINS_SLAVE_NODE_NAME', value: jenkins_slave_node_name),
278 string(name: 'PARENT_WORKSPACE', value: pwd()),
279 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
280 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
281 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
282 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
283 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
284 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
285 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
286 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
287 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
288 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
289 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
290 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
291 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
292 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
293 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300294 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_refs}"),
295 string(name: 'UPDATE_VERSION', value: "${update_version}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300296 string(name: 'IPMI_USER', value: env_ipmi_user),
297 string(name: 'IPMI_PASS', value: env_ipmi_pass),
298 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
299 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
300 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
301 string(name: 'OS_AUTH_URL', value: "${OS_AUTH_URL}"),
302 string(name: 'OS_PROJECT_NAME', value: "${OS_PROJECT_NAME}"),
303 string(name: 'OS_USER_DOMAIN_NAME', value: "${OS_USER_DOMAIN_NAME}"),
304 string(name: 'OS_CREDENTIALS', value: "${OS_CREDENTIALS}"),
305 string(name: 'LAB_PARAM_DEFAULTS', value: "${LAB_PARAM_DEFAULTS}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300306 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300307 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
308 ]
309
310 build_pipeline_job('swarm-bootstrap-salt-cluster-heat', parameters)
311}
312
Dennis Dmitriev02447412019-04-17 18:02:46 +0300313def swarm_deploy_cicd(String stack_to_install, String install_timeout, String jenkins_slave_node_name, Boolean make_snapshot_stages) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300314 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
315 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300316 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300317 def parameters = [
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300318 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300319 string(name: 'PARENT_WORKSPACE', value: pwd()),
320 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
321 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200322 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300323 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300324 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300325 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
326 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300327 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300328}
329
Dennis Dmitriev02447412019-04-17 18:02:46 +0300330def swarm_deploy_platform(String stack_to_install, String install_timeout, String jenkins_slave_node_name, Boolean make_snapshot_stages) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300331 // Run openstack_deploy job on CICD Jenkins for specified stacks
332 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300333 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300334 def parameters = [
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300335 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300336 string(name: 'PARENT_WORKSPACE', value: pwd()),
337 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
338 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200339 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300340 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300341 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300342 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
343 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300344 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300345}
346
sgudz2ed95852019-03-01 14:48:52 +0200347def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
348 // Run openstack_deploy job on day01 Jenkins for specified stacks
349 def common = new com.mirantis.mk.Common()
350 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
351 def parameters = [
352 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
353 string(name: 'PARENT_WORKSPACE', value: pwd()),
354 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
355 string(name: 'STACK_INSTALL', value: stack_to_install),
356 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
357 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
358 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
359 ]
360 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
361}
362
Dennis Dmitriev02447412019-04-17 18:02:46 +0300363def swarm_run_pytest(String passed_steps, String jenkins_slave_node_name, Boolean make_snapshot_stages) {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300364 // Run pytest tests
365 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300366 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Oleksii Butenkoec78c9f2019-04-04 16:26:20 +0300367 def tempest_extra_args = env.TEMPEST_EXTRA_ARGS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200368 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200369 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Andrew Baraniukd1586342019-06-12 11:41:20 +0300370 def tempest_pattern=env.TEMPEST_PATTERN ?: 'tempest'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300371 def parameters = [
372 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
373 string(name: 'PASSED_STEPS', value: passed_steps),
374 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300375 string(name: 'PARENT_NODE_NAME', value: jenkins_slave_node_name),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300376 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300377 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300378 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
379 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
380 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
381 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
382 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200383 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200384 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Andrew Baraniukd1586342019-06-12 11:41:20 +0300385 string(name: 'TEMPEST_PATTERN', value: "${tempest_pattern}"),
Oleksii Butenkoec78c9f2019-04-04 16:26:20 +0300386 string(name: 'TEMPEST_EXTRA_ARGS', value: "${tempest_extra_args}"),
Dennis Dmitriev02447412019-04-17 18:02:46 +0300387 booleanParam(name: 'MAKE_SNAPSHOT_STAGES', value: make_snapshot_stages),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300388 ]
389 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
390 common.prettyPrint(parameters)
391 build job: 'swarm-run-pytest',
392 parameters: parameters
393}
394
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300395def swarm_testrail_report(String passed_steps, String node_with_reports) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300396 // Run pytest tests
397 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300398 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200399 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400400 def test_plan_name_prefix = env.TEST_PLAN_NAME_PREFIX ?: ''
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300401 def parameters = [
402 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200403 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300404 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
405 string(name: 'PASSED_STEPS', value: passed_steps),
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300406 string(name: 'PARENT_NODE_NAME', value: node_with_reports),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300407 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300408 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200409 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400410 string(name: 'TEST_PLAN_NAME_PREFIX', value: "${test_plan_name_prefix}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300411 ]
412 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
413 common.prettyPrint(parameters)
414 build job: 'swarm-testrail-report',
415 parameters: parameters
416}
417
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300418def generate_cookied_model(IPV4_NET_ADMIN, IPV4_NET_CONTROL, IPV4_NET_TENANT, IPV4_NET_EXTERNAL) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300419 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300420 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
421 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
422 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
423 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
424
Vladimir Jigulin6a1ef812019-03-21 19:34:07 +0400425 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 +0200426 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300427 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
428 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
429 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300430 def jenkins_pipelines_branch=env.JENKINS_PIPELINE_BRANCH ?: ''
sgudzb7953382019-02-18 17:59:30 +0200431 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300432 def update_version = env.UPDATE_VERSION ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300433
434 def parameters = [
435 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
436 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
437 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
438 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
439 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
440 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300441 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
442 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
443 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300444 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
445 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
446 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
447 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200448 string(name: 'IPMI_USER', value: env.IPMI_USER),
449 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200450 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +0300451 string(name: 'JENKINS_PIPELINE_BRANCH', value: "${jenkins_pipelines_branch}"),
sgudzc97385a2018-11-29 17:01:53 +0200452 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300453 string(name: 'UPDATE_VERSION', value: "${update_version}"),
454
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300455 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300456
457 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300458}
459
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300460def generate_configdrive_iso(SALT_MASTER_IP, ADMIN_NETWORK_GW) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300461 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300462 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300463 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
464
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300465 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300466 def mcp_common_scripts_ref = env.MCP_COMMON_SCRIPTS_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300467 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300468 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300469 def update_version = env.UPDATE_VERSION?: 'proposed'
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200470 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
471 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300472 def deploy_network_mask = env.DEPLOY_NETWORK_NETMASK ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300473
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300474 def parameters = [
475 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
Dmitry Tyzhnenko240b67c2019-05-21 16:55:55 +0300476 string(name: 'MODEL_URL', value: "http://172.19.112.216:8098/${LAB_CONFIG_NAME}.git"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300477 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
478 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
479 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200480 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300481 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
482 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
483 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300484 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300485 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
486 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200487 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
488 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Tatyana Leontovich1f069162019-04-02 19:57:55 +0300489 string(name: 'DEPLOY_NETWORK_NETMASK', value: "${deploy_network_mask}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300490 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
491 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300492 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300493 string(name: 'UPDATE_VERSION', value: "${update_version}"),
494 string(name: 'MCP_COMMON_SCRIPTS_REFS', value: "${mcp_common_scripts_ref}"),
495 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 +0300496 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300497 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300498}
499
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300500def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300501 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200502 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300503 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200504 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300505 try {
506 run_cmd("""\
507 export ENV_NAME=${ENV_NAME}
508 . ./tcp_tests/utils/env_salt
509 . ./tcp_tests/utils/env_jenkins_day01
510 export JENKINS_BUILD_TIMEOUT=${timeout}
511 JOB_PARAMETERS=\"{
512 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
513 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
514 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200515 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300516 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
517 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200518 // Wait for IO calm down on cluster nodes
519 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300520 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300521 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300522 def workflow_details=run_cmd_stdout("""\
523 . ./tcp_tests/utils/env_salt
524 . ./tcp_tests/utils/env_jenkins_day01
525 export JOB_NAME=deploy_openstack
526 export BUILD_NUMBER=lastBuild
527 python ./tcp_tests/utils/get_jenkins_job_stages.py
528 """)
529 throw new Exception(workflow_details)
530 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300531}
532
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300533def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300534 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200535 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300536 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200537 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300538 try {
539 run_cmd("""\
540 export ENV_NAME=${ENV_NAME}
541 . ./tcp_tests/utils/env_salt
542 . ./tcp_tests/utils/env_jenkins_cicd
543 export JENKINS_BUILD_TIMEOUT=${timeout}
544 JOB_PARAMETERS=\"{
545 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
546 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
547 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200548 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300549 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 +0300550 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200551 // Wait for IO calm down on cluster nodes
552 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300553 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300554 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300555 def workflow_details=run_cmd_stdout("""\
556 . ./tcp_tests/utils/env_salt
557 . ./tcp_tests/utils/env_jenkins_cicd
558 export JOB_NAME=deploy_openstack
559 export BUILD_NUMBER=lastBuild
560 python ./tcp_tests/utils/get_jenkins_job_stages.py
561 """)
562 throw new Exception(workflow_details)
563 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300564}
565
566def sanity_check_component(stack) {
567 // Run sanity check for the component ${stack}.
568 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300569 try {
570 run_cmd("""\
Dennis Dmitriev27007322019-05-03 19:21:44 +0300571 export LOG_NAME=deploy_${stack}_test.log
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300572 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
573 """)
574 } catch (e) {
575 def String junit_report_xml = readFile("deploy_${stack}.xml")
576 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
577 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
578 throw new Exception(msg + junit_report_xml_pretty)
579 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300580}
581
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300582def download_logs(archive_name_prefix) {
583 // Archive and download logs and debug info from salt nodes in the lab
584 // Do not fail in case of error to not lose the original error from the parent exception.
585 def common = new com.mirantis.mk.Common()
586 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
587 run_cmd("""\
588 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
589 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
590 """)
591}
592
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300593def devops_snapshot_info(snapshot_name) {
594 // Print helper message after snapshot
595 def common = new com.mirantis.mk.Common()
596
597 def SALT_MASTER_IP=run_cmd_stdout("""\
598 . ./tcp_tests/utils/env_salt
599 echo \$SALT_MASTER_IP
600 """).trim().split().last()
601 def login = "root" // set fixed 'root' login for now
602 def password = "r00tme" // set fixed 'root' login for now
603 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
604 def VENV_PATH='/home/jenkins/fuel-devops30'
605
606 common.printMsg("""\
607#########################
608# To revert the snapshot:
609#########################
610. ${VENV_PATH}/bin/activate;
611dos.py revert ${ENV_NAME} ${snapshot_name};
612dos.py resume ${ENV_NAME};
613# dos.py time-sync ${ENV_NAME}; # Optional\n
614ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
615""", "cyan")
616}
617
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300618def devops_snapshot(stacks) {
619 // Make snapshots with names "${stack}_deployed" for each stack
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300620 // for all VMs in the environment.
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300621
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300622 run_cmd("""\
623 dos.py suspend ${ENV_NAME}
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +0300624 """)
625
626 for (stack in "${stacks}".split(",")) {
627 run_cmd("""\
628 dos.py snapshot ${ENV_NAME} ${stack}_deployed
629 """)
630 devops_snapshot_info("${stack}_deployed")
631 }
632
633 run_cmd("""\
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300634 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300635 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300636
637 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
638 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300639 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300640}
641
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300642def get_steps_list(steps) {
643 // Make a list from comma separated string
644 return steps.split(',').collect { it.split(':')[0] }
645}
646
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300647def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
648 // <filename> is name of the XML report file that will be created
649 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
650 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300651
652 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
653 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
654
Dennis Dmitriev39666082018-08-29 15:30:45 +0300655 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300656<?xml version=\"1.0\" encoding=\"utf-8\"?>
657 <testsuite>
658 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300659 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300660 <system-out>${stdout}</system-out>
661 <system-err>${stderr}</system-err>
662 </testcase>
663 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300664"""
665 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300666}
667
Dennis Dmitrievaf59f7e2019-04-02 11:54:06 +0000668def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300669 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200670 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300671 def testrailURL = "https://mirantis.testrail.com"
672 def testrailProject = "Mirantis Cloud Platform"
Tatyana Leontovich43854972019-05-24 23:02:22 +0300673 def testPlanNamePrefix = env.TEST_PLAN_NAME_PREFIX ?: "[2019.2.0-update]System"
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400674 def testPlanName = "${testPlanNamePrefix}-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300675 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300676 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300677 def jobURL = env.BUILD_URL
678
679 def reporterOptions = [
680 "--verbose",
681 "--env-description \"${testPlanDesc}\"",
682 "--testrail-run-update",
683 "--testrail-url \"${testrailURL}\"",
684 "--testrail-user \"\${TESTRAIL_USER}\"",
685 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
686 "--testrail-project \"${testrailProject}\"",
687 "--testrail-plan-name \"${testPlanName}\"",
688 "--testrail-milestone \"${testrailMilestone}\"",
689 "--testrail-suite \"${testSuiteName}\"",
690 "--xunit-name-template \"${methodname}\"",
691 "--testrail-name-template \"${testrail_name_template}\"",
692 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300693 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300694 ] + reporter_extra_options
695
696 def script = """
697 . ${venvPath}/bin/activate
698 set -ex
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200699 report ${reporterOptions.join(' ')} '${report_name}'
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300700 """
701
702 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
703
704 withCredentials([
705 [$class : 'UsernamePasswordMultiBinding',
706 credentialsId : testrail_cred_id,
707 passwordVariable: 'TESTRAIL_PASSWORD',
708 usernameVariable: 'TESTRAIL_USER']
709 ]) {
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300710 def ret = [:]
711 ret.stdout = ''
712 ret.exception = ''
713 try {
714 ret.stdout = run_cmd_stdout(script)
715 } catch (Exception ex) {
716 ret.exception = ("""\
717##### Report to '${testSuiteName}' failed: #####\n""" + ex.message + "\n\n")
718 }
719 return ret
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300720 }
721}
722
723
724def create_deploy_result_report(deploy_expected_stacks, result, text) {
725 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
726 def classname = "Deploy"
727 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300728 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300729 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
730 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300731}