blob: e4779cda64a430ee3e8e0bc45ed001f7ac14fec3 [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 Dmitriev8df35442018-07-31 08:40:20 +03005def run_cmd(String cmd, Boolean returnStdout=false) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03006 def common = new com.mirantis.mk.Common()
7 common.printMsg("Run shell command:\n" + cmd, "blue")
8 def VENV_PATH='/home/jenkins/fuel-devops30'
Dennis Dmitriev27a96792018-07-30 07:52:03 +03009 def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log"
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030010 script = """\
11 set +x;
12 echo 'activate python virtualenv ${VENV_PATH}';
13 . ${VENV_PATH}/bin/activate;
Dennis Dmitriev8df35442018-07-31 08:40:20 +030014 bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030015 """
Dennis Dmitriev27a96792018-07-30 07:52:03 +030016 def result
17 try {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030018 return sh(script: script, returnStdout: returnStdout)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030019 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030020 def stderr = readFile("${stderr_path}")
21 def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr
22 throw new Exception(error_message)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030023 } finally {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030024 sh(script: "rm ${stderr_path} || true")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030025 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030026}
27
28def run_cmd_stdout(cmd) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +030029 return run_cmd(cmd, true)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030030}
31
Dennis Dmitriev27a96792018-07-30 07:52:03 +030032def build_pipeline_job(job_name, parameters) {
33 //Build a job, grab the results if failed and use the results in exception
34 def common = new com.mirantis.mk.Common()
35 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
36 common.prettyPrint(parameters)
37
38 def job_info = build job: "${job_name}",
39 parameters: parameters,
40 propagate: false
41
42 if (job_info.getResult() != "SUCCESS") {
43 currentBuild.result = job_info.getResult()
44 def build_number = job_info.getNumber()
45 common.printMsg("Job '${job_name}' failed, getting details", "red")
46 def workflow_details=run_cmd_stdout("""\
47 export JOB_NAME=${job_name}
48 export BUILD_NUMBER=${build_number}
49 python ./tcp_tests/utils/get_jenkins_job_stages.py
50 """)
51 throw new Exception(workflow_details)
52 }
53}
54
55def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') {
56 //Build a job, grab the results if failed and use the results in exception
57 //junit_report_filename: if not null, try to copy this JUnit report first from remote job
58 def common = new com.mirantis.mk.Common()
59 common.printMsg("Start building job '${job_name}' with parameters:", "purple")
60 common.prettyPrint(parameters)
61
62 def job_info = build job: "${job_name}",
63 parameters: parameters,
64 propagate: false
65
66 if (job_info.getResult() != "SUCCESS") {
67 def build_status = job_info.getResult()
68 def build_number = job_info.getNumber()
69 def build_url = job_info.getAbsoluteUrl()
70 def job_url = "${build_url}"
71 currentBuild.result = build_status
72 if (junit_report_filename) {
73 common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "red")
74 step($class: 'hudson.plugins.copyartifact.CopyArtifact',
75 projectName: job_name,
76 selector: specific("${build_number}"),
77 filter: "${junit_report_source_dir}/${junit_report_filename}",
78 target: '.',
79 flatten: true,
80 fingerprintArtifacts: true)
81
82 def String junit_report_xml = readFile("${junit_report_filename}")
83 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
Dennis Dmitriev3f9329c2018-08-30 18:17:49 +030084 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
85 def String junit_report_xml_filtered = junit_report_xml_pretty.replaceAll("<","&lt;").replaceAll(">", "&gt;")
Dennis Dmitriev27a96792018-07-30 07:52:03 +030086 def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n"
Dennis Dmitriev39666082018-08-29 15:30:45 +030087 throw new Exception(msg + junit_report_xml_filtered)
Dennis Dmitriev27a96792018-07-30 07:52:03 +030088 } else {
89 throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.")
90 }
91 }
92}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030093
94def prepare_working_dir() {
95 println "Clean the working directory ${env.WORKSPACE}"
96 deleteDir()
97
Dennis Dmitriev27a96792018-07-30 07:52:03 +030098 // do not fail if environment doesn't exists
99 println "Remove environment ${ENV_NAME}"
100 run_cmd("""\
101 dos.py erase ${ENV_NAME} || true
102 """)
103 println "Remove config drive ISO"
104 run_cmd("""\
105 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
106 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300107
108 run_cmd("""\
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300109 git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE}
110 if [ -n "$TCP_QA_REFS" ]; then
111 set -e
112 git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$?
113 fi
114 pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300115 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300116}
117
118def swarm_bootstrap_salt_cluster_devops() {
119 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300120 def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
121 def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
122 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
123 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
124 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
125 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
126 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300127 def parameters = [
128 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
129 string(name: 'PARENT_WORKSPACE', value: pwd()),
130 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
131 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
132 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
133 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
134 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
135 string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300136 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
137 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
138 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
139 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"),
140 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"),
141 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
142 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300143 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
144 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300145
146 build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300147}
148
149def swarm_deploy_cicd(String stack_to_install='core,cicd') {
150 // Run openstack_deploy job on cfg01 Jenkins for specified stacks
151 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300152 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300153 def parameters = [
154 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
155 string(name: 'PARENT_WORKSPACE', value: pwd()),
156 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
157 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300158 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300159 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
160 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300161 build_pipeline_job('swarm-deploy-cicd', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300162}
163
164def swarm_deploy_platform(String stack_to_install) {
165 // Run openstack_deploy job on CICD Jenkins for specified stacks
166 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300167 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300168 def parameters = [
169 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
170 string(name: 'PARENT_WORKSPACE', value: pwd()),
171 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
172 string(name: 'STACK_INSTALL', value: stack_to_install),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300173 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300174 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
175 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300176 build_pipeline_job('swarm-deploy-platform', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300177}
178
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300179def swarm_run_pytest(String passed_steps) {
180 // Run pytest tests
181 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300182 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300183 def parameters = [
184 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
185 string(name: 'PASSED_STEPS', value: passed_steps),
186 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
187 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
188 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300189 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300190 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
191 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
192 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
193 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
194 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
195 ]
196 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
197 common.prettyPrint(parameters)
198 build job: 'swarm-run-pytest',
199 parameters: parameters
200}
201
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300202def swarm_testrail_report(String passed_steps) {
203 // Run pytest tests
204 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300205 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300206 def parameters = [
207 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
208 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
209 string(name: 'PASSED_STEPS', value: passed_steps),
210 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
211 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300212 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300213 ]
214 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
215 common.prettyPrint(parameters)
216 build job: 'swarm-testrail-report',
217 parameters: parameters
218}
219
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300220def generate_cookied_model() {
221 def common = new com.mirantis.mk.Common()
222 // do not fail if environment doesn't exists
223 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
224 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
225 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
226 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
227 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
228 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
229 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
230 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
231
232 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
233 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300234 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
235 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
236 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300237
238 def parameters = [
239 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
240 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
241 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
242 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
243 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
244 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300245 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
246 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
247 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300248 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
249 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
250 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
251 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
252 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300253
254 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300255}
256
257def generate_configdrive_iso() {
258 def common = new com.mirantis.mk.Common()
259 def SALT_MASTER_IP=run_cmd_stdout("""\
260 export ENV_NAME=${ENV_NAME}
261 . ./tcp_tests/utils/env_salt
262 echo \$SALT_MASTER_IP
263 """).trim().split().last()
264 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300265
266 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
267 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
268
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300269 def parameters = [
270 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
271 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
272 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
273 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
274 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
275 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
276 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
277 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
278 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
279 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
280 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
281 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
282 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300283 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
284 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300285 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300286 build_pipeline_job('create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300287}
288
289def run_job_on_day01_node(stack_to_install, timeout=1800) {
290 // stack_to_install="core,cicd"
291 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300292 try {
293 run_cmd("""\
294 export ENV_NAME=${ENV_NAME}
295 . ./tcp_tests/utils/env_salt
296 . ./tcp_tests/utils/env_jenkins_day01
297 export JENKINS_BUILD_TIMEOUT=${timeout}
298 JOB_PARAMETERS=\"{
299 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
300 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
301 }\"
302 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
303 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
304 """)
305 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300306 def common = new com.mirantis.mk.Common()
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300307 common.printMsg("Product job 'deploy_openstack' failed, getting details", "red")
308 def workflow_details=run_cmd_stdout("""\
309 . ./tcp_tests/utils/env_salt
310 . ./tcp_tests/utils/env_jenkins_day01
311 export JOB_NAME=deploy_openstack
312 export BUILD_NUMBER=lastBuild
313 python ./tcp_tests/utils/get_jenkins_job_stages.py
314 """)
315 throw new Exception(workflow_details)
316 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300317}
318
319def run_job_on_cicd_nodes(stack_to_install, timeout=1800) {
320 // stack_to_install="k8s,calico,stacklight"
321 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300322 try {
323 run_cmd("""\
324 export ENV_NAME=${ENV_NAME}
325 . ./tcp_tests/utils/env_salt
326 . ./tcp_tests/utils/env_jenkins_cicd
327 export JENKINS_BUILD_TIMEOUT=${timeout}
328 JOB_PARAMETERS=\"{
329 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
330 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
331 }\"
332 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
333 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
334 sleep 60 # Wait for IO calm down on cluster nodes
335 """)
336 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300337 def common = new com.mirantis.mk.Common()
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300338 common.printMsg("Product job 'deploy_openstack' failed, getting details", "red")
339 def workflow_details=run_cmd_stdout("""\
340 . ./tcp_tests/utils/env_salt
341 . ./tcp_tests/utils/env_jenkins_cicd
342 export JOB_NAME=deploy_openstack
343 export BUILD_NUMBER=lastBuild
344 python ./tcp_tests/utils/get_jenkins_job_stages.py
345 """)
346 throw new Exception(workflow_details)
347 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300348}
349
350def sanity_check_component(stack) {
351 // Run sanity check for the component ${stack}.
352 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300353 try {
354 run_cmd("""\
355 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
356 """)
357 } catch (e) {
358 def String junit_report_xml = readFile("deploy_${stack}.xml")
359 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
360 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
361 throw new Exception(msg + junit_report_xml_pretty)
362 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300363}
364
365def devops_snapshot(stack) {
366 // Make the snapshot with name "${stack}_deployed"
367 // for all VMs in the environment.
368 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
369 // then make a copy for the created snapshot to allow the system
370 // tests to revert this snapshot along with the metadata from the INI file.
371 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300372 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300373 dos.py suspend ${ENV_NAME}
374 dos.py snapshot ${ENV_NAME} ${stack}_deployed
375 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300376 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300377
378 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
379 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
380
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300381 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
382 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
383 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300384 """)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300385}
386
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300387def get_steps_list(steps) {
388 // Make a list from comma separated string
389 return steps.split(',').collect { it.split(':')[0] }
390}
391
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300392def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
393 // <filename> is name of the XML report file that will be created
394 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
395 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitriev39666082018-08-29 15:30:45 +0300396 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300397<?xml version=\"1.0\" encoding=\"utf-8\"?>
398 <testsuite>
399 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
400 <${status} message=\"${status_message}\">${text}</${status}>
401 <system-out>${stdout}</system-out>
402 <system-err>${stderr}</system-err>
403 </testcase>
404 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300405"""
406 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300407}
408
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300409def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
410 def venvPath = '/home/jenkins/venv_testrail_reporter'
411 def testPlanDesc = env.ENV_NAME
412 def testrailURL = "https://mirantis.testrail.com"
413 def testrailProject = "Mirantis Cloud Platform"
414 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
415 def testrailMilestone = "MCP1.1"
416 def jobURL = env.BUILD_URL
417
418 def reporterOptions = [
419 "--verbose",
420 "--env-description \"${testPlanDesc}\"",
421 "--testrail-run-update",
422 "--testrail-url \"${testrailURL}\"",
423 "--testrail-user \"\${TESTRAIL_USER}\"",
424 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
425 "--testrail-project \"${testrailProject}\"",
426 "--testrail-plan-name \"${testPlanName}\"",
427 "--testrail-milestone \"${testrailMilestone}\"",
428 "--testrail-suite \"${testSuiteName}\"",
429 "--xunit-name-template \"${methodname}\"",
430 "--testrail-name-template \"${testrail_name_template}\"",
431 "--test-results-link \"${jobURL}\"",
432 ] + reporter_extra_options
433
434 def script = """
435 . ${venvPath}/bin/activate
436 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300437 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300438 """
439
440 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
441
442 withCredentials([
443 [$class : 'UsernamePasswordMultiBinding',
444 credentialsId : testrail_cred_id,
445 passwordVariable: 'TESTRAIL_PASSWORD',
446 usernameVariable: 'TESTRAIL_USER']
447 ]) {
448 return run_cmd(script)
449 }
450}
451
452
453def create_deploy_result_report(deploy_expected_stacks, result, text) {
454 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
455 def classname = "Deploy"
456 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300457 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300458 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
459 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300460}