blob: 0483965283ee56beda4fce9fc122391c0dd18b69 [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001package com.mirantis.system_qa
2
Dennis Dmitriev27a96792018-07-30 07:52:03 +03003import groovy.xml.XmlUtil
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03004
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +03005def run_sh(String cmd) {
6 // run shell script without catching any output
7 def common = new com.mirantis.mk.Common()
8 common.printMsg("Run shell command:\n" + cmd, "blue")
9 def VENV_PATH='/home/jenkins/fuel-devops30'
10 script = """\
11 set -ex;
12 . ${VENV_PATH}/bin/activate;
13 bash -c '${cmd.stripIndent()}'
14 """
15 return sh(script: script)
16}
17
Dennis Dmitriev8df35442018-07-31 08:40:20 +030018def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030019 def common = new com.mirantis.mk.Common()
20 common.printMsg("Run shell command:\n" + cmd, "blue")
21 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +030022 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030023 script = """\
24 set +x;
25 echo 'activate python virtualenv ${VENV_PATH}';
26 . ${VENV_PATH}/bin/activate;
Dennis Dmitriev8df35442018-07-31 08:40:20 +030027 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030028 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030029 def result
30 try {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030031 return sh(script: script, returnStdout: returnStdout)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030032 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030033 def stderr = readFile("${stderr_path}")
34 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
35 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030036 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030037 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030038 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030039}
40
41def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030042 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030043}
44
Dennis Dmitriev27a96792018-07-30 07:52:03 +030045def build_pipeline_job(job_name, parameters) {
46 //Build a job, grab the results if failed and use the results in exception
47 def common = new com.mirantis.mk.Common()
48 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
49 common.prettyPrint(parameters)
50
51 def job_info = build job: "${job_name}",
52 parameters: parameters,
53 propagate: false
54
55 if (job_info.getResult() != "SUCCESS") {
56 currentBuild.result = job_info.getResult()
57 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030058 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030059 def workflow_details=run_cmd_stdout("""\
60 export JOB_NAME=${job_name}
61 export BUILD_NUMBER=${build_number}
62 python ./tcp_tests/utils/get_jenkins_job_stages.py
63 """)
64 throw new Exception(workflow_details)
65 }
66}
67
68def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
69 //Build a job, grab the results if failed and use the results in exception
70 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
71 def common = new com.mirantis.mk.Common()
72 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
73 common.prettyPrint(parameters)
74
75 def job_info = build job: "${job_name}",
76 parameters: parameters,
77 propagate: false
78
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020079 def build_number = job_info.getNumber()
80 def build_url = job_info.getAbsoluteUrl()
81 def build_status = job_info.getResult()
82 try {
83 // Try to grab 'tar.gz' articacts from the shell job'
84 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
85 projectName: job_name,
86 selector: specific("${build_number}"),
87 filter: "**/*.tar.gz",
88 target: '.',
89 flatten: true,
90 fingerprintArtifacts: true)
91 } catch (none) {
92 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
93 }
94
Dennis Dmitriev27a96792018-07-30 07:52:03 +030095 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +030096 def job_url = "${build_url}"
97 currentBuild.result = build_status
98 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030099 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300100 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
101 projectName: job_name,
102 selector: specific("${build_number}"),
103 filter: "${junit_report_source_dir}/${junit_report_filename}",
104 target: '.',
105 flatten: true,
106 fingerprintArtifacts: true)
107
108 def String junit_report_xml = readFile("${junit_report_filename}")
109 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
110 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300111 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300112 } else {
113 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
114 }
115 }
116}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300117
118def prepare_working_dir() {
119 println "Clean the working directory ${env.WORKSPACE}"
120 deleteDir()
121
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300122 // do not fail if environment doesn't exists
123 println "Remove environment ${ENV_NAME}"
124 run_cmd("""\
125 dos.py erase ${ENV_NAME} || true
126 """)
127 println "Remove config drive ISO"
128 run_cmd("""\
129 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
130 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300131
132 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300133 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
134 if [ -n "$TCP_QA_REFS" ]; then
135 set -e
136 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
137 fi
138 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300139 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300140}
141
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300142def update_working_dir() {
143 // Use to fetch a patchset from gerrit to the working dir
144 run_cmd("""\
145 if [ -n "$TCP_QA_REFS" ]; then
146 set -e
147 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
148 fi
149 pip install -r tcp_tests/requirements.txt
150 """)
151}
152
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300153def swarm_bootstrap_salt_cluster_devops() {
154 def common = new com.mirantis.mk.Common()
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200155 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
156 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300157 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
158 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
159 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
160 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
161 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200162 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
163 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitriev63460042018-12-11 13:08:11 +0200164 def env_ipmi_user = env.IPMI_USER ?: ''
165 def env_ipmi_pass = env.IPMI_PASS ?: ''
166 def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: ''
167 def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200168 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300169 def parameters = [
170 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
171 string(name: 'PARENT_WORKSPACE', value: pwd()),
172 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
173 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
174 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
175 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
176 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
177 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300178 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
179 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
180 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
181 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
182 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
183 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
184 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200185 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
186 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitriev63460042018-12-11 13:08:11 +0200187 string(name: 'IPMI_USER', value: env_ipmi_user),
188 string(name: 'IPMI_PASS', value: env_ipmi_pass),
189 string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface),
190 string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface),
sgudzb7953382019-02-18 17:59:30 +0200191 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300192 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
193 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300194
195 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300196}
197
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200198def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300199 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
200 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300201 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300202 def parameters = [
203 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
204 string(name: 'PARENT_WORKSPACE', value: pwd()),
205 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
206 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200207 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300208 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300209 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
210 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300211 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300212}
213
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200214def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300215 // Run openstack_deploy job on CICD Jenkins for specified stacks
216 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300217 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300218 def parameters = [
219 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
220 string(name: 'PARENT_WORKSPACE', value: pwd()),
221 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
222 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200223 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300224 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300225 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
226 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300227 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300228}
229
sgudz2ed95852019-03-01 14:48:52 +0200230def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) {
231 // Run openstack_deploy job on day01 Jenkins for specified stacks
232 def common = new com.mirantis.mk.Common()
233 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
234 def parameters = [
235 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
236 string(name: 'PARENT_WORKSPACE', value: pwd()),
237 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
238 string(name: 'STACK_INSTALL', value: stack_to_install),
239 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
240 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
241 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
242 ]
243 build_pipeline_job('swarm-deploy-platform-without-cicd', parameters)
244}
245
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300246def swarm_run_pytest(String passed_steps) {
247 // Run pytest tests
248 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300249 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200250 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200251 def tempest_target=env.TEMPEST_TARGET ?: 'gtw01'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300252 def parameters = [
253 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
254 string(name: 'PASSED_STEPS', value: passed_steps),
255 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
256 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
257 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300258 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300259 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
260 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
261 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
262 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
263 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200264 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200265 string(name: 'TEMPEST_TARGET', value: "${tempest_target}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200266
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300267 ]
268 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
269 common.prettyPrint(parameters)
270 build job: 'swarm-run-pytest',
271 parameters: parameters
272}
273
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300274def swarm_testrail_report(String passed_steps) {
275 // Run pytest tests
276 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300277 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200278 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300279 def parameters = [
280 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200281 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300282 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
283 string(name: 'PASSED_STEPS', value: passed_steps),
284 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
285 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300286 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200287 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300288 ]
289 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
290 common.prettyPrint(parameters)
291 build job: 'swarm-testrail-report',
292 parameters: parameters
293}
294
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300295def generate_cookied_model() {
296 def common = new com.mirantis.mk.Common()
297 // do not fail if environment doesn't exists
298 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
299 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
300 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
301 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
302 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
303 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
304 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
305 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
306
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200307 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}"
308 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}"
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300309 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
310 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
311 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
sgudzb7953382019-02-18 17:59:30 +0200312 def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300313
314 def parameters = [
315 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
316 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
317 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
318 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
319 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
320 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300321 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
322 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
323 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300324 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
325 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
326 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
327 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
sgudzc97385a2018-11-29 17:01:53 +0200328 string(name: 'IPMI_USER', value: env.IPMI_USER),
329 string(name: 'IPMI_PASS', value: env.IPMI_PASS),
sgudzb7953382019-02-18 17:59:30 +0200330 string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"),
sgudzc97385a2018-11-29 17:01:53 +0200331 string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300332 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300333
334 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300335}
336
337def generate_configdrive_iso() {
338 def common = new com.mirantis.mk.Common()
339 def SALT_MASTER_IP=run_cmd_stdout("""\
340 export ENV_NAME=${ENV_NAME}
341 . ./tcp_tests/utils/env_salt
342 echo \$SALT_MASTER_IP
343 """).trim().split().last()
344 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300345
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300346 def dhcp_ranges_json=run_cmd_stdout("""\
347 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
348 fgrep "admin-pool01"|
349 cut -d"=" -f2
350 """).trim().split("\n").last()
351 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
352 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
353 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
354
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300355 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
356 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300357 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200358 def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: ''
359 def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300360
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300361 def parameters = [
362 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
363 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
364 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
365 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
366 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
Dennis Dmitrieve3884652019-03-05 14:26:44 +0200367 string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300368 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
369 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
370 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300371 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300372 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
373 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
Dennis Dmitrievd9168b52018-12-19 18:53:52 +0200374 string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"),
375 string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300376 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
377 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300378 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300379 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300380 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300381}
382
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300383def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300384 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200385 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300386 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200387 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300388 try {
389 run_cmd("""\
390 export ENV_NAME=${ENV_NAME}
391 . ./tcp_tests/utils/env_salt
392 . ./tcp_tests/utils/env_jenkins_day01
393 export JENKINS_BUILD_TIMEOUT=${timeout}
394 JOB_PARAMETERS=\"{
395 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
396 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
397 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200398 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300399 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
400 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200401 // Wait for IO calm down on cluster nodes
402 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300403 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300404 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300405 def workflow_details=run_cmd_stdout("""\
406 . ./tcp_tests/utils/env_salt
407 . ./tcp_tests/utils/env_jenkins_day01
408 export JOB_NAME=deploy_openstack
409 export BUILD_NUMBER=lastBuild
410 python ./tcp_tests/utils/get_jenkins_job_stages.py
411 """)
412 throw new Exception(workflow_details)
413 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300414}
415
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300416def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300417 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200418 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300419 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200420 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300421 try {
422 run_cmd("""\
423 export ENV_NAME=${ENV_NAME}
424 . ./tcp_tests/utils/env_salt
425 . ./tcp_tests/utils/env_jenkins_cicd
426 export JENKINS_BUILD_TIMEOUT=${timeout}
427 JOB_PARAMETERS=\"{
428 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
429 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
430 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200431 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300432 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 +0300433 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200434 // Wait for IO calm down on cluster nodes
435 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300436 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300437 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300438 def workflow_details=run_cmd_stdout("""\
439 . ./tcp_tests/utils/env_salt
440 . ./tcp_tests/utils/env_jenkins_cicd
441 export JOB_NAME=deploy_openstack
442 export BUILD_NUMBER=lastBuild
443 python ./tcp_tests/utils/get_jenkins_job_stages.py
444 """)
445 throw new Exception(workflow_details)
446 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300447}
448
449def sanity_check_component(stack) {
450 // Run sanity check for the component ${stack}.
451 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300452 try {
453 run_cmd("""\
454 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
455 """)
456 } catch (e) {
457 def String junit_report_xml = readFile("deploy_${stack}.xml")
458 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
459 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
460 throw new Exception(msg + junit_report_xml_pretty)
461 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300462}
463
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300464def download_logs(archive_name_prefix) {
465 // Archive and download logs and debug info from salt nodes in the lab
466 // Do not fail in case of error to not lose the original error from the parent exception.
467 def common = new com.mirantis.mk.Common()
468 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
469 run_cmd("""\
470 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
471 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
472 """)
473}
474
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300475def devops_snapshot_info(snapshot_name) {
476 // Print helper message after snapshot
477 def common = new com.mirantis.mk.Common()
478
479 def SALT_MASTER_IP=run_cmd_stdout("""\
480 . ./tcp_tests/utils/env_salt
481 echo \$SALT_MASTER_IP
482 """).trim().split().last()
483 def login = "root" // set fixed 'root' login for now
484 def password = "r00tme" // set fixed 'root' login for now
485 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
486 def VENV_PATH='/home/jenkins/fuel-devops30'
487
488 common.printMsg("""\
489#########################
490# To revert the snapshot:
491#########################
492. ${VENV_PATH}/bin/activate;
493dos.py revert ${ENV_NAME} ${snapshot_name};
494dos.py resume ${ENV_NAME};
495# dos.py time-sync ${ENV_NAME}; # Optional\n
496ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
497""", "cyan")
498}
499
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300500def devops_snapshot(stack) {
501 // Make the snapshot with name "${stack}_deployed"
502 // for all VMs in the environment.
503 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
504 // then make a copy for the created snapshot to allow the system
505 // tests to revert this snapshot along with the metadata from the INI file.
506 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300507 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300508 dos.py suspend ${ENV_NAME}
509 dos.py snapshot ${ENV_NAME} ${stack}_deployed
510 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300511 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300512
513 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
514 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
515
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300516 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
517 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
518 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300519 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300520 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300521}
522
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300523def get_steps_list(steps) {
524 // Make a list from comma separated string
525 return steps.split(',').collect { it.split(':')[0] }
526}
527
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300528def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
529 // <filename> is name of the XML report file that will be created
530 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
531 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300532
533 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
534 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
535
Dennis Dmitriev39666082018-08-29 15:30:45 +0300536 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300537<?xml version=\"1.0\" encoding=\"utf-8\"?>
538 <testsuite>
539 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300540 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300541 <system-out>${stdout}</system-out>
542 <system-err>${stderr}</system-err>
543 </testcase>
544 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300545"""
546 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300547}
548
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300549def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
550 def venvPath = '/home/jenkins/venv_testrail_reporter'
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200551 def testPlanDesc = env.LAB_CONFIG_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300552 def testrailURL = "https://mirantis.testrail.com"
553 def testrailProject = "Mirantis Cloud Platform"
554 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
555 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300556 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300557 def jobURL = env.BUILD_URL
558
559 def reporterOptions = [
560 "--verbose",
561 "--env-description \"${testPlanDesc}\"",
562 "--testrail-run-update",
563 "--testrail-url \"${testrailURL}\"",
564 "--testrail-user \"\${TESTRAIL_USER}\"",
565 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
566 "--testrail-project \"${testrailProject}\"",
567 "--testrail-plan-name \"${testPlanName}\"",
568 "--testrail-milestone \"${testrailMilestone}\"",
569 "--testrail-suite \"${testSuiteName}\"",
570 "--xunit-name-template \"${methodname}\"",
571 "--testrail-name-template \"${testrail_name_template}\"",
572 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300573 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300574 ] + reporter_extra_options
575
576 def script = """
577 . ${venvPath}/bin/activate
578 set -ex
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200579 report ${reporterOptions.join(' ')} '${report_name}'
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300580 """
581
582 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
583
584 withCredentials([
585 [$class : 'UsernamePasswordMultiBinding',
586 credentialsId : testrail_cred_id,
587 passwordVariable: 'TESTRAIL_PASSWORD',
588 usernameVariable: 'TESTRAIL_USER']
589 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300590 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300591 }
592}
593
594
595def create_deploy_result_report(deploy_expected_stacks, result, text) {
596 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
597 def classname = "Deploy"
598 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300599 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300600 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
601 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300602}