blob: d34867ec0f6af39d3c40b293ad603b8496644666 [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
79 if (job_info.getResult() != "SUCCESS") {
80 def build_status = job_info.getResult()
81 def build_number = job_info.getNumber()
82 def build_url = job_info.getAbsoluteUrl()
83 def job_url = "${build_url}"
84 currentBuild.result = build_status
85 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030086 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030087 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
88 projectName: job_name,
89 selector: specific("${build_number}"),
90 filter: "${junit_report_source_dir}/${junit_report_filename}",
91 target: '.',
92 flatten: true,
93 fingerprintArtifacts: true)
94
95 def String junit_report_xml = readFile("${junit_report_filename}")
96 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
97 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030098 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030099 } else {
100 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
101 }
102 }
103}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300104
105def prepare_working_dir() {
106 println "Clean the working directory ${env.WORKSPACE}"
107 deleteDir()
108
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300109 // do not fail if environment doesn't exists
110 println "Remove environment ${ENV_NAME}"
111 run_cmd("""\
112 dos.py erase ${ENV_NAME} || true
113 """)
114 println "Remove config drive ISO"
115 run_cmd("""\
116 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
117 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300118
119 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300120 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
121 if [ -n "$TCP_QA_REFS" ]; then
122 set -e
123 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
124 fi
125 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300126 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300127}
128
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300129def update_working_dir() {
130 // Use to fetch a patchset from gerrit to the working dir
131 run_cmd("""\
132 if [ -n "$TCP_QA_REFS" ]; then
133 set -e
134 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
135 fi
136 pip install -r tcp_tests/requirements.txt
137 """)
138}
139
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300140def swarm_bootstrap_salt_cluster_devops() {
141 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300142 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
143 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
144 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
145 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
146 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
147 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
148 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300149 def parameters = [
150 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
151 string(name: 'PARENT_WORKSPACE', value: pwd()),
152 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
153 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
154 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
155 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
156 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
157 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300158 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
159 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
160 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
161 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
162 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
163 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
164 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300165 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
166 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300167
168 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300169}
170
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200171def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300172 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
173 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300174 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300175 def parameters = [
176 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
177 string(name: 'PARENT_WORKSPACE', value: pwd()),
178 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
179 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200180 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300181 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300182 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
183 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300184 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300185}
186
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200187def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300188 // Run openstack_deploy job on CICD Jenkins for specified stacks
189 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300190 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300191 def parameters = [
192 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
193 string(name: 'PARENT_WORKSPACE', value: pwd()),
194 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
195 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200196 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300197 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300198 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
199 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300200 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300201}
202
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300203def swarm_run_pytest(String passed_steps) {
204 // Run pytest tests
205 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300206 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300207 def parameters = [
208 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
209 string(name: 'PASSED_STEPS', value: passed_steps),
210 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
211 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
212 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300213 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300214 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
215 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
216 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
217 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
218 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200219 string(name: 'TEMPEST_IMAGE_VERSION', value: "${TEMPEST_IMAGE_VERSION}"),
220
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300221 ]
222 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
223 common.prettyPrint(parameters)
224 build job: 'swarm-run-pytest',
225 parameters: parameters
226}
227
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300228def swarm_testrail_report(String passed_steps) {
229 // Run pytest tests
230 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300231 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200232 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300233 def parameters = [
234 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
235 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
236 string(name: 'PASSED_STEPS', value: passed_steps),
237 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
238 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300239 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200240 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300241 ]
242 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
243 common.prettyPrint(parameters)
244 build job: 'swarm-testrail-report',
245 parameters: parameters
246}
247
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300248def generate_cookied_model() {
249 def common = new com.mirantis.mk.Common()
250 // do not fail if environment doesn't exists
251 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
252 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
253 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
254 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
255 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
256 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
257 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
258 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
259
260 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
261 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300262 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
263 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
264 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300265
266 def parameters = [
267 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
268 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
269 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
270 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
271 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
272 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300273 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
274 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
275 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300276 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
277 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
278 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
279 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
280 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300281
282 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300283}
284
285def generate_configdrive_iso() {
286 def common = new com.mirantis.mk.Common()
287 def SALT_MASTER_IP=run_cmd_stdout("""\
288 export ENV_NAME=${ENV_NAME}
289 . ./tcp_tests/utils/env_salt
290 echo \$SALT_MASTER_IP
291 """).trim().split().last()
292 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300293
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300294 def dhcp_ranges_json=run_cmd_stdout("""\
295 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
296 fgrep "admin-pool01"|
297 cut -d"=" -f2
298 """).trim().split("\n").last()
299 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
300 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
301 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
302
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300303 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
304 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300305 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300306
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300307 def parameters = [
308 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
309 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
310 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
311 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
312 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
313 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
314 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
315 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
316 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300317 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300318 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
319 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
320 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
321 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300322 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
323 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300324 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300325 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300326 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300327}
328
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300329def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300330 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200331 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300332 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200333 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300334 try {
335 run_cmd("""\
336 export ENV_NAME=${ENV_NAME}
337 . ./tcp_tests/utils/env_salt
338 . ./tcp_tests/utils/env_jenkins_day01
339 export JENKINS_BUILD_TIMEOUT=${timeout}
340 JOB_PARAMETERS=\"{
341 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
342 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
343 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200344 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300345 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
346 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200347 // Wait for IO calm down on cluster nodes
348 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300349 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300350 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300351 def workflow_details=run_cmd_stdout("""\
352 . ./tcp_tests/utils/env_salt
353 . ./tcp_tests/utils/env_jenkins_day01
354 export JOB_NAME=deploy_openstack
355 export BUILD_NUMBER=lastBuild
356 python ./tcp_tests/utils/get_jenkins_job_stages.py
357 """)
358 throw new Exception(workflow_details)
359 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300360}
361
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300362def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300363 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200364 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300365 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200366 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300367 try {
368 run_cmd("""\
369 export ENV_NAME=${ENV_NAME}
370 . ./tcp_tests/utils/env_salt
371 . ./tcp_tests/utils/env_jenkins_cicd
372 export JENKINS_BUILD_TIMEOUT=${timeout}
373 JOB_PARAMETERS=\"{
374 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
375 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
376 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200377 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300378 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 +0300379 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200380 // Wait for IO calm down on cluster nodes
381 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300382 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300383 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300384 def workflow_details=run_cmd_stdout("""\
385 . ./tcp_tests/utils/env_salt
386 . ./tcp_tests/utils/env_jenkins_cicd
387 export JOB_NAME=deploy_openstack
388 export BUILD_NUMBER=lastBuild
389 python ./tcp_tests/utils/get_jenkins_job_stages.py
390 """)
391 throw new Exception(workflow_details)
392 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300393}
394
395def sanity_check_component(stack) {
396 // Run sanity check for the component ${stack}.
397 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300398 try {
399 run_cmd("""\
400 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
401 """)
402 } catch (e) {
403 def String junit_report_xml = readFile("deploy_${stack}.xml")
404 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
405 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
406 throw new Exception(msg + junit_report_xml_pretty)
407 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300408}
409
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300410def download_logs(archive_name_prefix) {
411 // Archive and download logs and debug info from salt nodes in the lab
412 // Do not fail in case of error to not lose the original error from the parent exception.
413 def common = new com.mirantis.mk.Common()
414 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
415 run_cmd("""\
416 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
417 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
418 """)
419}
420
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300421def devops_snapshot_info(snapshot_name) {
422 // Print helper message after snapshot
423 def common = new com.mirantis.mk.Common()
424
425 def SALT_MASTER_IP=run_cmd_stdout("""\
426 . ./tcp_tests/utils/env_salt
427 echo \$SALT_MASTER_IP
428 """).trim().split().last()
429 def login = "root" // set fixed 'root' login for now
430 def password = "r00tme" // set fixed 'root' login for now
431 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
432 def VENV_PATH='/home/jenkins/fuel-devops30'
433
434 common.printMsg("""\
435#########################
436# To revert the snapshot:
437#########################
438. ${VENV_PATH}/bin/activate;
439dos.py revert ${ENV_NAME} ${snapshot_name};
440dos.py resume ${ENV_NAME};
441# dos.py time-sync ${ENV_NAME}; # Optional\n
442ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
443""", "cyan")
444}
445
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300446def devops_snapshot(stack) {
447 // Make the snapshot with name "${stack}_deployed"
448 // for all VMs in the environment.
449 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
450 // then make a copy for the created snapshot to allow the system
451 // tests to revert this snapshot along with the metadata from the INI file.
452 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300453 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300454 dos.py suspend ${ENV_NAME}
455 dos.py snapshot ${ENV_NAME} ${stack}_deployed
456 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300457 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300458
459 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
460 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
461
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300462 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
463 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
464 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300465 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300466 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300467}
468
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300469def get_steps_list(steps) {
470 // Make a list from comma separated string
471 return steps.split(',').collect { it.split(':')[0] }
472}
473
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300474def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
475 // <filename> is name of the XML report file that will be created
476 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
477 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300478
479 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
480 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
481
Dennis Dmitriev39666082018-08-29 15:30:45 +0300482 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300483<?xml version=\"1.0\" encoding=\"utf-8\"?>
484 <testsuite>
485 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300486 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300487 <system-out>${stdout}</system-out>
488 <system-err>${stderr}</system-err>
489 </testcase>
490 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300491"""
492 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300493}
494
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300495def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
496 def venvPath = '/home/jenkins/venv_testrail_reporter'
497 def testPlanDesc = env.ENV_NAME
498 def testrailURL = "https://mirantis.testrail.com"
499 def testrailProject = "Mirantis Cloud Platform"
500 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
501 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300502 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300503 def jobURL = env.BUILD_URL
504
505 def reporterOptions = [
506 "--verbose",
507 "--env-description \"${testPlanDesc}\"",
508 "--testrail-run-update",
509 "--testrail-url \"${testrailURL}\"",
510 "--testrail-user \"\${TESTRAIL_USER}\"",
511 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
512 "--testrail-project \"${testrailProject}\"",
513 "--testrail-plan-name \"${testPlanName}\"",
514 "--testrail-milestone \"${testrailMilestone}\"",
515 "--testrail-suite \"${testSuiteName}\"",
516 "--xunit-name-template \"${methodname}\"",
517 "--testrail-name-template \"${testrail_name_template}\"",
518 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300519 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300520 ] + reporter_extra_options
521
522 def script = """
523 . ${venvPath}/bin/activate
524 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300525 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300526 """
527
528 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
529
530 withCredentials([
531 [$class : 'UsernamePasswordMultiBinding',
532 credentialsId : testrail_cred_id,
533 passwordVariable: 'TESTRAIL_PASSWORD',
534 usernameVariable: 'TESTRAIL_USER']
535 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300536 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300537 }
538}
539
540
541def create_deploy_result_report(deploy_expected_stacks, result, text) {
542 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
543 def classname = "Deploy"
544 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300545 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300546 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
547 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300548}