blob: 92b43b2b8ce3ca7c02afff57ed4d32e0ba732934 [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001package com.mirantis.system_qa
2
Dennis Dmitriev27a96792018-07-30 07:52:03 +03003import groovy.xml.XmlUtil
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03004
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +03005def run_sh(String cmd) {
6 // run shell script without catching any output
7 def common = new com.mirantis.mk.Common()
8 common.printMsg("Run shell command:\n" + cmd, "blue")
9 def VENV_PATH='/home/jenkins/fuel-devops30'
10 script = """\
11 set -ex;
12 . ${VENV_PATH}/bin/activate;
13 bash -c '${cmd.stripIndent()}'
14 """
15 return sh(script: script)
16}
17
Dennis Dmitriev8df35442018-07-31 08:40:20 +030018def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030019 def common = new com.mirantis.mk.Common()
20 common.printMsg("Run shell command:\n" + cmd, "blue")
21 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +030022 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030023 script = """\
24 set +x;
25 echo 'activate python virtualenv ${VENV_PATH}';
26 . ${VENV_PATH}/bin/activate;
Dennis Dmitriev8df35442018-07-31 08:40:20 +030027 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030028 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030029 def result
30 try {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030031 return sh(script: script, returnStdout: returnStdout)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030032 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030033 def stderr = readFile("${stderr_path}")
34 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
35 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030036 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030037 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030038 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030039}
40
41def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030042 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030043}
44
Dennis Dmitriev27a96792018-07-30 07:52:03 +030045def build_pipeline_job(job_name, parameters) {
46 //Build a job, grab the results if failed and use the results in exception
47 def common = new com.mirantis.mk.Common()
48 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
49 common.prettyPrint(parameters)
50
51 def job_info = build job: "${job_name}",
52 parameters: parameters,
53 propagate: false
54
55 if (job_info.getResult() != "SUCCESS") {
56 currentBuild.result = job_info.getResult()
57 def build_number = job_info.getNumber()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030058 common.printMsg("Job '${job_name}' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030059 def workflow_details=run_cmd_stdout("""\
60 export JOB_NAME=${job_name}
61 export BUILD_NUMBER=${build_number}
62 python ./tcp_tests/utils/get_jenkins_job_stages.py
63 """)
64 throw new Exception(workflow_details)
65 }
66}
67
68def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
69 //Build a job, grab the results if failed and use the results in exception
70 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
71 def common = new com.mirantis.mk.Common()
72 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
73 common.prettyPrint(parameters)
74
75 def job_info = build job: "${job_name}",
76 parameters: parameters,
77 propagate: false
78
Dennis Dmitriev4115ae72018-11-20 13:43:35 +020079 def build_number = job_info.getNumber()
80 def build_url = job_info.getAbsoluteUrl()
81 def build_status = job_info.getResult()
82 try {
83 // Try to grab 'tar.gz' articacts from the shell job'
84 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
85 projectName: job_name,
86 selector: specific("${build_number}"),
87 filter: "**/*.tar.gz",
88 target: '.',
89 flatten: true,
90 fingerprintArtifacts: true)
91 } catch (none) {
92 common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple")
93 }
94
Dennis Dmitriev27a96792018-07-30 07:52:03 +030095 if (job_info.getResult() != "SUCCESS") {
Dennis Dmitriev27a96792018-07-30 07:52:03 +030096 def job_url = "${build_url}"
97 currentBuild.result = build_status
98 if (junit_report_filename) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030099 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300100 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
101 projectName: job_name,
102 selector: specific("${build_number}"),
103 filter: "${junit_report_source_dir}/${junit_report_filename}",
104 target: '.',
105 flatten: true,
106 fingerprintArtifacts: true)
107
108 def String junit_report_xml = readFile("${junit_report_filename}")
109 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
110 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300111 throw new Exception(msg + junit_report_xml_pretty)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300112 } else {
113 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
114 }
115 }
116}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300117
118def prepare_working_dir() {
119 println "Clean the working directory ${env.WORKSPACE}"
120 deleteDir()
121
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300122 // do not fail if environment doesn't exists
123 println "Remove environment ${ENV_NAME}"
124 run_cmd("""\
125 dos.py erase ${ENV_NAME} || true
126 """)
127 println "Remove config drive ISO"
128 run_cmd("""\
129 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
130 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300131
132 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300133 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
134 if [ -n "$TCP_QA_REFS" ]; then
135 set -e
136 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
137 fi
138 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300139 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300140}
141
Dennis Dmitrieveb50ce12018-09-27 13:34:32 +0300142def update_working_dir() {
143 // Use to fetch a patchset from gerrit to the working dir
144 run_cmd("""\
145 if [ -n "$TCP_QA_REFS" ]; then
146 set -e
147 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
148 fi
149 pip install -r tcp_tests/requirements.txt
150 """)
151}
152
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300153def swarm_bootstrap_salt_cluster_devops() {
154 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300155 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
156 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
157 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
158 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
159 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
160 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
161 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300162 def parameters = [
163 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
164 string(name: 'PARENT_WORKSPACE', value: pwd()),
165 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
166 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
167 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
168 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
169 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
170 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300171 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
172 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
173 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
174 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
175 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
176 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
177 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300178 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
179 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300180
181 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300182}
183
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200184def swarm_deploy_cicd(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300185 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
186 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300187 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300188 def parameters = [
189 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
190 string(name: 'PARENT_WORKSPACE', value: pwd()),
191 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
192 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200193 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300194 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300195 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
196 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300197 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300198}
199
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200200def swarm_deploy_platform(String stack_to_install, String install_timeout) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300201 // Run openstack_deploy job on CICD Jenkins for specified stacks
202 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300203 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300204 def parameters = [
205 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
206 string(name: 'PARENT_WORKSPACE', value: pwd()),
207 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
208 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200209 string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300210 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300211 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
212 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300213 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300214}
215
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300216def swarm_run_pytest(String passed_steps) {
217 // Run pytest tests
218 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300219 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200220 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300221 def parameters = [
222 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
223 string(name: 'PASSED_STEPS', value: passed_steps),
224 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
225 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
226 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300227 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300228 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
229 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
230 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
231 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
232 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200233 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200234
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300235 ]
236 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
237 common.prettyPrint(parameters)
238 build job: 'swarm-run-pytest',
239 parameters: parameters
240}
241
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300242def swarm_testrail_report(String passed_steps) {
243 // Run pytest tests
244 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300245 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200246 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300247 def parameters = [
248 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
249 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
250 string(name: 'PASSED_STEPS', value: passed_steps),
251 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
252 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300253 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200254 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300255 ]
256 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
257 common.prettyPrint(parameters)
258 build job: 'swarm-testrail-report',
259 parameters: parameters
260}
261
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300262def generate_cookied_model() {
263 def common = new com.mirantis.mk.Common()
264 // do not fail if environment doesn't exists
265 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
266 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
267 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
268 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
269 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
270 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
271 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
272 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
273
274 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
275 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300276 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
277 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
278 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300279
280 def parameters = [
281 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
282 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
283 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
284 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
285 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
286 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300287 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
288 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
289 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300290 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
291 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
292 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
293 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
294 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300295
296 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300297}
298
299def generate_configdrive_iso() {
300 def common = new com.mirantis.mk.Common()
301 def SALT_MASTER_IP=run_cmd_stdout("""\
302 export ENV_NAME=${ENV_NAME}
303 . ./tcp_tests/utils/env_salt
304 echo \$SALT_MASTER_IP
305 """).trim().split().last()
306 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300307
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300308 def dhcp_ranges_json=run_cmd_stdout("""\
309 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
310 fgrep "admin-pool01"|
311 cut -d"=" -f2
312 """).trim().split("\n").last()
313 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
314 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
315 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
316
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300317 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
318 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300319 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300320
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300321 def parameters = [
322 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
323 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
324 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
325 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
326 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
327 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
328 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
329 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
330 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300331 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300332 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
333 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
334 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
335 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300336 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
337 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300338 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300339 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300340 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300341}
342
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300343def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300344 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200345 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300346 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200347 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300348 try {
349 run_cmd("""\
350 export ENV_NAME=${ENV_NAME}
351 . ./tcp_tests/utils/env_salt
352 . ./tcp_tests/utils/env_jenkins_day01
353 export JENKINS_BUILD_TIMEOUT=${timeout}
354 JOB_PARAMETERS=\"{
355 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
356 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
357 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200358 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300359 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
360 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200361 // Wait for IO calm down on cluster nodes
362 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300363 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300364 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300365 def workflow_details=run_cmd_stdout("""\
366 . ./tcp_tests/utils/env_salt
367 . ./tcp_tests/utils/env_jenkins_day01
368 export JOB_NAME=deploy_openstack
369 export BUILD_NUMBER=lastBuild
370 python ./tcp_tests/utils/get_jenkins_job_stages.py
371 """)
372 throw new Exception(workflow_details)
373 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300374}
375
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300376def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300377 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200378 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300379 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200380 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300381 try {
382 run_cmd("""\
383 export ENV_NAME=${ENV_NAME}
384 . ./tcp_tests/utils/env_salt
385 . ./tcp_tests/utils/env_jenkins_cicd
386 export JENKINS_BUILD_TIMEOUT=${timeout}
387 JOB_PARAMETERS=\"{
388 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
389 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
390 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200391 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300392 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 +0300393 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200394 // Wait for IO calm down on cluster nodes
395 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300396 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300397 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300398 def workflow_details=run_cmd_stdout("""\
399 . ./tcp_tests/utils/env_salt
400 . ./tcp_tests/utils/env_jenkins_cicd
401 export JOB_NAME=deploy_openstack
402 export BUILD_NUMBER=lastBuild
403 python ./tcp_tests/utils/get_jenkins_job_stages.py
404 """)
405 throw new Exception(workflow_details)
406 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300407}
408
409def sanity_check_component(stack) {
410 // Run sanity check for the component ${stack}.
411 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300412 try {
413 run_cmd("""\
414 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
415 """)
416 } catch (e) {
417 def String junit_report_xml = readFile("deploy_${stack}.xml")
418 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
419 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
420 throw new Exception(msg + junit_report_xml_pretty)
421 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300422}
423
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300424def download_logs(archive_name_prefix) {
425 // Archive and download logs and debug info from salt nodes in the lab
426 // Do not fail in case of error to not lose the original error from the parent exception.
427 def common = new com.mirantis.mk.Common()
428 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
429 run_cmd("""\
430 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
431 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
432 """)
433}
434
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300435def devops_snapshot_info(snapshot_name) {
436 // Print helper message after snapshot
437 def common = new com.mirantis.mk.Common()
438
439 def SALT_MASTER_IP=run_cmd_stdout("""\
440 . ./tcp_tests/utils/env_salt
441 echo \$SALT_MASTER_IP
442 """).trim().split().last()
443 def login = "root" // set fixed 'root' login for now
444 def password = "r00tme" // set fixed 'root' login for now
445 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
446 def VENV_PATH='/home/jenkins/fuel-devops30'
447
448 common.printMsg("""\
449#########################
450# To revert the snapshot:
451#########################
452. ${VENV_PATH}/bin/activate;
453dos.py revert ${ENV_NAME} ${snapshot_name};
454dos.py resume ${ENV_NAME};
455# dos.py time-sync ${ENV_NAME}; # Optional\n
456ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
457""", "cyan")
458}
459
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300460def devops_snapshot(stack) {
461 // Make the snapshot with name "${stack}_deployed"
462 // for all VMs in the environment.
463 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
464 // then make a copy for the created snapshot to allow the system
465 // tests to revert this snapshot along with the metadata from the INI file.
466 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300467 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300468 dos.py suspend ${ENV_NAME}
469 dos.py snapshot ${ENV_NAME} ${stack}_deployed
470 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300471 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300472
473 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
474 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
475
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300476 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
477 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
478 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300479 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300480 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300481}
482
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300483def get_steps_list(steps) {
484 // Make a list from comma separated string
485 return steps.split(',').collect { it.split(':')[0] }
486}
487
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300488def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
489 // <filename> is name of the XML report file that will be created
490 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
491 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300492
493 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
494 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
495
Dennis Dmitriev39666082018-08-29 15:30:45 +0300496 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300497<?xml version=\"1.0\" encoding=\"utf-8\"?>
498 <testsuite>
499 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300500 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300501 <system-out>${stdout}</system-out>
502 <system-err>${stderr}</system-err>
503 </testcase>
504 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300505"""
506 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300507}
508
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300509def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
510 def venvPath = '/home/jenkins/venv_testrail_reporter'
511 def testPlanDesc = env.ENV_NAME
512 def testrailURL = "https://mirantis.testrail.com"
513 def testrailProject = "Mirantis Cloud Platform"
514 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
515 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300516 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300517 def jobURL = env.BUILD_URL
518
519 def reporterOptions = [
520 "--verbose",
521 "--env-description \"${testPlanDesc}\"",
522 "--testrail-run-update",
523 "--testrail-url \"${testrailURL}\"",
524 "--testrail-user \"\${TESTRAIL_USER}\"",
525 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
526 "--testrail-project \"${testrailProject}\"",
527 "--testrail-plan-name \"${testPlanName}\"",
528 "--testrail-milestone \"${testrailMilestone}\"",
529 "--testrail-suite \"${testSuiteName}\"",
530 "--xunit-name-template \"${methodname}\"",
531 "--testrail-name-template \"${testrail_name_template}\"",
532 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300533 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300534 ] + reporter_extra_options
535
536 def script = """
537 . ${venvPath}/bin/activate
538 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300539 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300540 """
541
542 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
543
544 withCredentials([
545 [$class : 'UsernamePasswordMultiBinding',
546 credentialsId : testrail_cred_id,
547 passwordVariable: 'TESTRAIL_PASSWORD',
548 usernameVariable: 'TESTRAIL_USER']
549 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300550 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300551 }
552}
553
554
555def create_deploy_result_report(deploy_expected_stacks, result, text) {
556 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
557 def classname = "Deploy"
558 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300559 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300560 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
561 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300562}