blob: 58da420e8a83e0f8e3235526c2e26a078e7e5dac [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 ?: ''
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200207 def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300208 def parameters = [
209 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
210 string(name: 'PASSED_STEPS', value: passed_steps),
211 string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"),
212 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
213 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300214 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300215 booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false),
216 string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"),
217 string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"),
218 string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"),
219 string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"),
Tatyana Leontovich05f79402018-11-16 15:04:02 +0200220 string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200221
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300222 ]
223 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
224 common.prettyPrint(parameters)
225 build job: 'swarm-run-pytest',
226 parameters: parameters
227}
228
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300229def swarm_testrail_report(String passed_steps) {
230 // Run pytest tests
231 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300232 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200233 def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300234 def parameters = [
235 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
236 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
237 string(name: 'PASSED_STEPS', value: passed_steps),
238 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
239 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300240 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Tatyana Leontovichf3718442018-10-31 13:36:13 +0200241 string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300242 ]
243 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
244 common.prettyPrint(parameters)
245 build job: 'swarm-testrail-report',
246 parameters: parameters
247}
248
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300249def generate_cookied_model() {
250 def common = new com.mirantis.mk.Common()
251 // do not fail if environment doesn't exists
252 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
253 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
254 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
255 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
256 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
257 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
258 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
259 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
260
261 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
262 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300263 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
264 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
265 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300266
267 def parameters = [
268 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
269 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
270 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
271 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
272 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
273 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300274 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
275 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
276 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300277 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
278 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
279 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
280 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
281 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300282
283 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300284}
285
286def generate_configdrive_iso() {
287 def common = new com.mirantis.mk.Common()
288 def SALT_MASTER_IP=run_cmd_stdout("""\
289 export ENV_NAME=${ENV_NAME}
290 . ./tcp_tests/utils/env_salt
291 echo \$SALT_MASTER_IP
292 """).trim().split().last()
293 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300294
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300295 def dhcp_ranges_json=run_cmd_stdout("""\
296 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
297 fgrep "admin-pool01"|
298 cut -d"=" -f2
299 """).trim().split("\n").last()
300 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
301 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
302 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
303
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300304 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
305 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300306 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300307
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300308 def parameters = [
309 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
310 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
311 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
312 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
313 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
314 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
315 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
316 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
317 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300318 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300319 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
320 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
321 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
322 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300323 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
324 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300325 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300326 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300327 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300328}
329
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300330def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300331 // stack_to_install="core,cicd"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200332 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300333 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200334 common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300335 try {
336 run_cmd("""\
337 export ENV_NAME=${ENV_NAME}
338 . ./tcp_tests/utils/env_salt
339 . ./tcp_tests/utils/env_jenkins_day01
340 export JENKINS_BUILD_TIMEOUT=${timeout}
341 JOB_PARAMETERS=\"{
342 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
343 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
344 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200345 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300346 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
347 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200348 // Wait for IO calm down on cluster nodes
349 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300350 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300351 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300352 def workflow_details=run_cmd_stdout("""\
353 . ./tcp_tests/utils/env_salt
354 . ./tcp_tests/utils/env_jenkins_day01
355 export JOB_NAME=deploy_openstack
356 export BUILD_NUMBER=lastBuild
357 python ./tcp_tests/utils/get_jenkins_job_stages.py
358 """)
359 throw new Exception(workflow_details)
360 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300361}
362
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300363def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300364 // stack_to_install="k8s,calico,stacklight"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200365 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300366 def stack = "${stack_to_install}"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200367 common.printMsg("Deploy Platform components: ${stack_to_install}", "blue")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300368 try {
369 run_cmd("""\
370 export ENV_NAME=${ENV_NAME}
371 . ./tcp_tests/utils/env_salt
372 . ./tcp_tests/utils/env_jenkins_cicd
373 export JENKINS_BUILD_TIMEOUT=${timeout}
374 JOB_PARAMETERS=\"{
375 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
376 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
377 }\"
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200378 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] "
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300379 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 +0300380 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200381 // Wait for IO calm down on cluster nodes
382 sleep(60)
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300383 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300384 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300385 def workflow_details=run_cmd_stdout("""\
386 . ./tcp_tests/utils/env_salt
387 . ./tcp_tests/utils/env_jenkins_cicd
388 export JOB_NAME=deploy_openstack
389 export BUILD_NUMBER=lastBuild
390 python ./tcp_tests/utils/get_jenkins_job_stages.py
391 """)
392 throw new Exception(workflow_details)
393 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300394}
395
396def sanity_check_component(stack) {
397 // Run sanity check for the component ${stack}.
398 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300399 try {
400 run_cmd("""\
401 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
402 """)
403 } catch (e) {
404 def String junit_report_xml = readFile("deploy_${stack}.xml")
405 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
406 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
407 throw new Exception(msg + junit_report_xml_pretty)
408 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300409}
410
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300411def download_logs(archive_name_prefix) {
412 // Archive and download logs and debug info from salt nodes in the lab
413 // Do not fail in case of error to not lose the original error from the parent exception.
414 def common = new com.mirantis.mk.Common()
415 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
416 run_cmd("""\
417 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
418 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
419 """)
420}
421
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300422def devops_snapshot_info(snapshot_name) {
423 // Print helper message after snapshot
424 def common = new com.mirantis.mk.Common()
425
426 def SALT_MASTER_IP=run_cmd_stdout("""\
427 . ./tcp_tests/utils/env_salt
428 echo \$SALT_MASTER_IP
429 """).trim().split().last()
430 def login = "root" // set fixed 'root' login for now
431 def password = "r00tme" // set fixed 'root' login for now
432 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
433 def VENV_PATH='/home/jenkins/fuel-devops30'
434
435 common.printMsg("""\
436#########################
437# To revert the snapshot:
438#########################
439. ${VENV_PATH}/bin/activate;
440dos.py revert ${ENV_NAME} ${snapshot_name};
441dos.py resume ${ENV_NAME};
442# dos.py time-sync ${ENV_NAME}; # Optional\n
443ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
444""", "cyan")
445}
446
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300447def devops_snapshot(stack) {
448 // Make the snapshot with name "${stack}_deployed"
449 // for all VMs in the environment.
450 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
451 // then make a copy for the created snapshot to allow the system
452 // tests to revert this snapshot along with the metadata from the INI file.
453 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300454 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300455 dos.py suspend ${ENV_NAME}
456 dos.py snapshot ${ENV_NAME} ${stack}_deployed
457 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300458 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300459
460 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
461 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
462
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300463 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
464 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
465 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300466 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300467 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300468}
469
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300470def get_steps_list(steps) {
471 // Make a list from comma separated string
472 return steps.split(',').collect { it.split(':')[0] }
473}
474
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300475def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
476 // <filename> is name of the XML report file that will be created
477 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
478 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300479
480 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
481 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
482
Dennis Dmitriev39666082018-08-29 15:30:45 +0300483 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300484<?xml version=\"1.0\" encoding=\"utf-8\"?>
485 <testsuite>
486 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300487 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300488 <system-out>${stdout}</system-out>
489 <system-err>${stderr}</system-err>
490 </testcase>
491 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300492"""
493 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300494}
495
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300496def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
497 def venvPath = '/home/jenkins/venv_testrail_reporter'
498 def testPlanDesc = env.ENV_NAME
499 def testrailURL = "https://mirantis.testrail.com"
500 def testrailProject = "Mirantis Cloud Platform"
501 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
502 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300503 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300504 def jobURL = env.BUILD_URL
505
506 def reporterOptions = [
507 "--verbose",
508 "--env-description \"${testPlanDesc}\"",
509 "--testrail-run-update",
510 "--testrail-url \"${testrailURL}\"",
511 "--testrail-user \"\${TESTRAIL_USER}\"",
512 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
513 "--testrail-project \"${testrailProject}\"",
514 "--testrail-plan-name \"${testPlanName}\"",
515 "--testrail-milestone \"${testrailMilestone}\"",
516 "--testrail-suite \"${testSuiteName}\"",
517 "--xunit-name-template \"${methodname}\"",
518 "--testrail-name-template \"${testrail_name_template}\"",
519 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300520 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300521 ] + reporter_extra_options
522
523 def script = """
524 . ${venvPath}/bin/activate
525 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300526 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300527 """
528
529 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
530
531 withCredentials([
532 [$class : 'UsernamePasswordMultiBinding',
533 credentialsId : testrail_cred_id,
534 passwordVariable: 'TESTRAIL_PASSWORD',
535 usernameVariable: 'TESTRAIL_USER']
536 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300537 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300538 }
539}
540
541
542def create_deploy_result_report(deploy_expected_stacks, result, text) {
543 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
544 def classname = "Deploy"
545 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300546 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300547 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
548 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300549}