blob: 4a0a134ad707e70ac82d19227abb535bf0ebb455 [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}"),
219 ]
220 common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple")
221 common.prettyPrint(parameters)
222 build job: 'swarm-run-pytest',
223 parameters: parameters
224}
225
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300226def swarm_testrail_report(String passed_steps) {
227 // Run pytest tests
228 def common = new com.mirantis.mk.Common()
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300229 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300230 def parameters = [
231 string(name: 'ENV_NAME', value: "${ENV_NAME}"),
232 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
233 string(name: 'PASSED_STEPS', value: passed_steps),
234 string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"),
235 string(name: 'PARENT_WORKSPACE', value: pwd()),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300236 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300237 ]
238 common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple")
239 common.prettyPrint(parameters)
240 build job: 'swarm-testrail-report',
241 parameters: parameters
242}
243
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300244def generate_cookied_model() {
245 def common = new com.mirantis.mk.Common()
246 // do not fail if environment doesn't exists
247 def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
248 def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
249 def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
250 def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
251 println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN)
252 println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL)
253 println("IPV4_NET_TENANT=" + IPV4_NET_TENANT)
254 println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL)
255
256 def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION
257 def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300258 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
259 def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: ''
260 def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: ''
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300261
262 def parameters = [
263 string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"),
264 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
265 string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"),
266 string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"),
267 string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"),
268 string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300269 string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"),
270 string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"),
271 string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300272 string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN),
273 string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL),
274 string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT),
275 string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL),
276 ]
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300277
278 build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300279}
280
281def generate_configdrive_iso() {
282 def common = new com.mirantis.mk.Common()
283 def SALT_MASTER_IP=run_cmd_stdout("""\
284 export ENV_NAME=${ENV_NAME}
285 . ./tcp_tests/utils/env_salt
286 echo \$SALT_MASTER_IP
287 """).trim().split().last()
288 println("SALT_MASTER_IP=" + SALT_MASTER_IP)
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300289
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300290 def dhcp_ranges_json=run_cmd_stdout("""\
291 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
292 fgrep "admin-pool01"|
293 cut -d"=" -f2
294 """).trim().split("\n").last()
295 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
296 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
297 println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW)
298
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300299 def mk_pipelines_ref = env.MK_PIPELINES_REF ?: ''
300 def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: ''
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300301 def tcp_qa_refs = env.TCP_QA_REFS ?: ''
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300302
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300303 def parameters = [
304 string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"),
305 string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"),
306 string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"),
307 booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true),
308 string(name: 'MCP_VERSION', value: "${MCP_VERSION}"),
309 string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"),
310 string(name: 'NODE_NAME', value: "${NODE_NAME}"),
311 string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"),
312 string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300313 string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300314 string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"),
315 booleanParam(name: 'PIPELINES_FROM_ISO', value: true),
316 string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"),
317 string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"),
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300318 string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"),
319 string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"),
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300320 string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"),
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300321 ]
Dennis Dmitrievf220d972018-10-10 15:19:14 +0300322 build_pipeline_job('swarm-create-cfg-config-drive', parameters)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300323}
324
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300325def run_job_on_day01_node(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300326 // stack_to_install="core,cicd"
327 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300328 try {
329 run_cmd("""\
330 export ENV_NAME=${ENV_NAME}
331 . ./tcp_tests/utils/env_salt
332 . ./tcp_tests/utils/env_jenkins_day01
333 export JENKINS_BUILD_TIMEOUT=${timeout}
334 JOB_PARAMETERS=\"{
335 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
336 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
337 }\"
338 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
339 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
340 """)
341 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300342 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300343 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300344 def workflow_details=run_cmd_stdout("""\
345 . ./tcp_tests/utils/env_salt
346 . ./tcp_tests/utils/env_jenkins_day01
347 export JOB_NAME=deploy_openstack
348 export BUILD_NUMBER=lastBuild
349 python ./tcp_tests/utils/get_jenkins_job_stages.py
350 """)
351 throw new Exception(workflow_details)
352 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300353}
354
Dennis Dmitriev13e804b2018-10-09 19:25:14 +0300355def run_job_on_cicd_nodes(stack_to_install, timeout=2400) {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300356 // stack_to_install="k8s,calico,stacklight"
357 def stack = "${stack_to_install}"
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300358 try {
359 run_cmd("""\
360 export ENV_NAME=${ENV_NAME}
361 . ./tcp_tests/utils/env_salt
362 . ./tcp_tests/utils/env_jenkins_cicd
363 export JENKINS_BUILD_TIMEOUT=${timeout}
364 JOB_PARAMETERS=\"{
365 \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\",
366 \\\"STACK_INSTALL\\\": \\\"${stack}\\\"
367 }\"
368 JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] "
369 python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX"
370 sleep 60 # Wait for IO calm down on cluster nodes
371 """)
372 } catch (e) {
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300373 def common = new com.mirantis.mk.Common()
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300374 common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple")
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300375 def workflow_details=run_cmd_stdout("""\
376 . ./tcp_tests/utils/env_salt
377 . ./tcp_tests/utils/env_jenkins_cicd
378 export JOB_NAME=deploy_openstack
379 export BUILD_NUMBER=lastBuild
380 python ./tcp_tests/utils/get_jenkins_job_stages.py
381 """)
382 throw new Exception(workflow_details)
383 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300384}
385
386def sanity_check_component(stack) {
387 // Run sanity check for the component ${stack}.
388 // Result will be stored in JUnit XML file deploy_${stack}.xml
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300389 try {
390 run_cmd("""\
391 py.test --junit-xml=deploy_${stack}.xml -m check_${stack}
392 """)
393 } catch (e) {
394 def String junit_report_xml = readFile("deploy_${stack}.xml")
395 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
396 def String msg = "Sanity check for '${stack}' failed, JUnit report:\n"
397 throw new Exception(msg + junit_report_xml_pretty)
398 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300399}
400
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300401def download_logs(archive_name_prefix) {
402 // Archive and download logs and debug info from salt nodes in the lab
403 // Do not fail in case of error to not lose the original error from the parent exception.
404 def common = new com.mirantis.mk.Common()
405 common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue")
406 run_cmd("""\
407 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
408 ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true
409 """)
410}
411
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300412def devops_snapshot_info(snapshot_name) {
413 // Print helper message after snapshot
414 def common = new com.mirantis.mk.Common()
415
416 def SALT_MASTER_IP=run_cmd_stdout("""\
417 . ./tcp_tests/utils/env_salt
418 echo \$SALT_MASTER_IP
419 """).trim().split().last()
420 def login = "root" // set fixed 'root' login for now
421 def password = "r00tme" // set fixed 'root' login for now
422 def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE
423 def VENV_PATH='/home/jenkins/fuel-devops30'
424
425 common.printMsg("""\
426#########################
427# To revert the snapshot:
428#########################
429. ${VENV_PATH}/bin/activate;
430dos.py revert ${ENV_NAME} ${snapshot_name};
431dos.py resume ${ENV_NAME};
432# dos.py time-sync ${ENV_NAME}; # Optional\n
433ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password}
434""", "cyan")
435}
436
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300437def devops_snapshot(stack) {
438 // Make the snapshot with name "${stack}_deployed"
439 // for all VMs in the environment.
440 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
441 // then make a copy for the created snapshot to allow the system
442 // tests to revert this snapshot along with the metadata from the INI file.
443 run_cmd("""\
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300444 set -ex
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300445 dos.py suspend ${ENV_NAME}
446 dos.py snapshot ${ENV_NAME} ${stack}_deployed
447 dos.py resume ${ENV_NAME}
Dennis Dmitriev1fed6662018-07-27 18:22:13 +0300448 sleep 20 # Wait for I/O on the host calms down
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300449
450 CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1)
451 dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME}
452
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300453 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
454 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
455 fi
Dennis Dmitriev8df35442018-07-31 08:40:20 +0300456 """)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300457 devops_snapshot_info("${stack}_deployed")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300458}
459
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300460def get_steps_list(steps) {
461 // Make a list from comma separated string
462 return steps.split(',').collect { it.split(':')[0] }
463}
464
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300465def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') {
466 // <filename> is name of the XML report file that will be created
467 // <status> is one of the 'success', 'skipped', 'failure' or 'error'
468 // 'error' status is assumed as 'Blocker' in TestRail reporter
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300469
470 // Replace '<' and '>' to '&lt;' and '&gt;' to avoid conflicts between xml tags in the message and JUnit report
471 def String text_filtered = text.replaceAll("<","&lt;").replaceAll(">", "&gt;")
472
Dennis Dmitriev39666082018-08-29 15:30:45 +0300473 def script = """\
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300474<?xml version=\"1.0\" encoding=\"utf-8\"?>
475 <testsuite>
476 <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\">
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300477 <${status} message=\"${status_message}\">${text_filtered}</${status}>
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300478 <system-out>${stdout}</system-out>
479 <system-err>${stderr}</system-err>
480 </testcase>
481 </testsuite>
Dennis Dmitriev39666082018-08-29 15:30:45 +0300482"""
483 writeFile(file: filename, text: script, encoding: "UTF-8")
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300484}
485
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300486def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) {
487 def venvPath = '/home/jenkins/venv_testrail_reporter'
488 def testPlanDesc = env.ENV_NAME
489 def testrailURL = "https://mirantis.testrail.com"
490 def testrailProject = "Mirantis Cloud Platform"
491 def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}"
492 def testrailMilestone = "MCP1.1"
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300493 def testrailCaseMaxNameLenght = 250
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300494 def jobURL = env.BUILD_URL
495
496 def reporterOptions = [
497 "--verbose",
498 "--env-description \"${testPlanDesc}\"",
499 "--testrail-run-update",
500 "--testrail-url \"${testrailURL}\"",
501 "--testrail-user \"\${TESTRAIL_USER}\"",
502 "--testrail-password \"\${TESTRAIL_PASSWORD}\"",
503 "--testrail-project \"${testrailProject}\"",
504 "--testrail-plan-name \"${testPlanName}\"",
505 "--testrail-milestone \"${testrailMilestone}\"",
506 "--testrail-suite \"${testSuiteName}\"",
507 "--xunit-name-template \"${methodname}\"",
508 "--testrail-name-template \"${testrail_name_template}\"",
509 "--test-results-link \"${jobURL}\"",
Dennis Dmitriev707b2152018-10-23 19:12:48 +0300510 "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}",
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300511 ] + reporter_extra_options
512
513 def script = """
514 . ${venvPath}/bin/activate
515 set -ex
Dennis Dmitrievee5ef232018-08-31 13:53:18 +0300516 report ${reporterOptions.join(' ')} ${report_name}
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300517 """
518
519 def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests'
520
521 withCredentials([
522 [$class : 'UsernamePasswordMultiBinding',
523 credentialsId : testrail_cred_id,
524 passwordVariable: 'TESTRAIL_PASSWORD',
525 usernameVariable: 'TESTRAIL_USER']
526 ]) {
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300527 return run_cmd_stdout(script)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300528 }
529}
530
531
532def create_deploy_result_report(deploy_expected_stacks, result, text) {
533 def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error']
534 def classname = "Deploy"
535 def name = "deployment_${ENV_NAME}"
Dennis Dmitriev39666082018-08-29 15:30:45 +0300536 def filename = "${name}.xml"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300537 def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch
538 create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '')
Dennis Dmitriev27a96792018-07-30 07:52:03 +0300539}