Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 1 | package com.mirantis.system_qa |
| 2 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 3 | import groovy.xml.XmlUtil |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 4 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 5 | def 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' |
Dmitry Tyzhnenko | b39de05 | 2019-03-21 17:05:07 +0200 | [diff] [blame] | 10 | def script = """\ |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 11 | set -ex; |
| 12 | . ${VENV_PATH}/bin/activate; |
| 13 | bash -c '${cmd.stripIndent()}' |
| 14 | """ |
| 15 | return sh(script: script) |
| 16 | } |
| 17 | |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 18 | def run_cmd(String cmd, Boolean returnStdout=false) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 19 | 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 Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 22 | def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log" |
Dmitry Tyzhnenko | b39de05 | 2019-03-21 17:05:07 +0200 | [diff] [blame] | 23 | def script = """#!/bin/bash |
| 24 | set +x |
| 25 | echo 'activate python virtualenv ${VENV_PATH}' |
| 26 | . ${VENV_PATH}/bin/activate |
| 27 | bash -c -e -x '${cmd.stripIndent()}' 2>${stderr_path} |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 28 | """ |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 29 | try { |
Dmitry Tyzhnenko | b39de05 | 2019-03-21 17:05:07 +0200 | [diff] [blame] | 30 | def stdout = sh(script: script, returnStdout: returnStdout) |
| 31 | def stderr = readFile("${stderr_path}") |
| 32 | def error_message = "\n<<<<<< STDERR: >>>>>>\n" + stderr |
| 33 | common.printMsg(error_message, "yellow") |
| 34 | common.printMsg("", "reset") |
| 35 | return stdout |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 36 | } catch (e) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 37 | def stderr = readFile("${stderr_path}") |
| 38 | def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr |
Dmitry Tyzhnenko | b39de05 | 2019-03-21 17:05:07 +0200 | [diff] [blame] | 39 | common.printMsg(error_message, "red") |
| 40 | common.printMsg("", "reset") |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 41 | throw new Exception(error_message) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 42 | } finally { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 43 | sh(script: "rm ${stderr_path} || true") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 44 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | def run_cmd_stdout(cmd) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 48 | return run_cmd(cmd, true) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 49 | } |
| 50 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 51 | def build_pipeline_job(job_name, parameters) { |
| 52 | //Build a job, grab the results if failed and use the results in exception |
| 53 | def common = new com.mirantis.mk.Common() |
| 54 | common.printMsg("Start building job '${job_name}' with parameters:", "purple") |
| 55 | common.prettyPrint(parameters) |
| 56 | |
| 57 | def job_info = build job: "${job_name}", |
| 58 | parameters: parameters, |
| 59 | propagate: false |
| 60 | |
| 61 | if (job_info.getResult() != "SUCCESS") { |
| 62 | currentBuild.result = job_info.getResult() |
| 63 | def build_number = job_info.getNumber() |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 64 | common.printMsg("Job '${job_name}' failed, getting details", "purple") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 65 | def workflow_details=run_cmd_stdout("""\ |
| 66 | export JOB_NAME=${job_name} |
| 67 | export BUILD_NUMBER=${build_number} |
| 68 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 69 | """) |
| 70 | throw new Exception(workflow_details) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') { |
| 75 | //Build a job, grab the results if failed and use the results in exception |
| 76 | //junit_report_filename: if not null, try to copy this JUnit report first from remote job |
| 77 | def common = new com.mirantis.mk.Common() |
| 78 | common.printMsg("Start building job '${job_name}' with parameters:", "purple") |
| 79 | common.prettyPrint(parameters) |
| 80 | |
| 81 | def job_info = build job: "${job_name}", |
| 82 | parameters: parameters, |
| 83 | propagate: false |
| 84 | |
Dennis Dmitriev | 4115ae7 | 2018-11-20 13:43:35 +0200 | [diff] [blame] | 85 | def build_number = job_info.getNumber() |
| 86 | def build_url = job_info.getAbsoluteUrl() |
| 87 | def build_status = job_info.getResult() |
| 88 | try { |
| 89 | // Try to grab 'tar.gz' articacts from the shell job' |
| 90 | step($class: 'hudson.plugins.copyartifact.CopyArtifact', |
| 91 | projectName: job_name, |
| 92 | selector: specific("${build_number}"), |
| 93 | filter: "**/*.tar.gz", |
| 94 | target: '.', |
| 95 | flatten: true, |
| 96 | fingerprintArtifacts: true) |
| 97 | } catch (none) { |
| 98 | common.printMsg("No *.tar.gz files found in artifacts of the build ${build_url}", "purple") |
| 99 | } |
| 100 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 101 | if (job_info.getResult() != "SUCCESS") { |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 102 | def job_url = "${build_url}" |
| 103 | currentBuild.result = build_status |
| 104 | if (junit_report_filename) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 105 | common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "purple") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 106 | step($class: 'hudson.plugins.copyartifact.CopyArtifact', |
| 107 | projectName: job_name, |
| 108 | selector: specific("${build_number}"), |
| 109 | filter: "${junit_report_source_dir}/${junit_report_filename}", |
| 110 | target: '.', |
| 111 | flatten: true, |
| 112 | fingerprintArtifacts: true) |
| 113 | |
| 114 | def String junit_report_xml = readFile("${junit_report_filename}") |
| 115 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
| 116 | def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n" |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 117 | throw new Exception(msg + junit_report_xml_pretty) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 118 | } else { |
| 119 | throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.") |
| 120 | } |
| 121 | } |
| 122 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 123 | |
| 124 | def prepare_working_dir() { |
| 125 | println "Clean the working directory ${env.WORKSPACE}" |
| 126 | deleteDir() |
| 127 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 128 | // do not fail if environment doesn't exists |
| 129 | println "Remove environment ${ENV_NAME}" |
| 130 | run_cmd("""\ |
| 131 | dos.py erase ${ENV_NAME} || true |
| 132 | """) |
| 133 | println "Remove config drive ISO" |
| 134 | run_cmd("""\ |
| 135 | rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true |
| 136 | """) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 137 | |
| 138 | run_cmd("""\ |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 139 | git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE} |
| 140 | if [ -n "$TCP_QA_REFS" ]; then |
| 141 | set -e |
| 142 | git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$? |
| 143 | fi |
| 144 | pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 145 | """) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 146 | } |
| 147 | |
Dennis Dmitriev | eb50ce1 | 2018-09-27 13:34:32 +0300 | [diff] [blame] | 148 | def update_working_dir() { |
| 149 | // Use to fetch a patchset from gerrit to the working dir |
| 150 | run_cmd("""\ |
| 151 | if [ -n "$TCP_QA_REFS" ]; then |
| 152 | set -e |
| 153 | git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$? |
| 154 | fi |
| 155 | pip install -r tcp_tests/requirements.txt |
| 156 | """) |
| 157 | } |
| 158 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 159 | def swarm_bootstrap_salt_cluster_devops() { |
| 160 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | e388465 | 2019-03-05 14:26:44 +0200 | [diff] [blame] | 161 | def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}" |
| 162 | def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}" |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 163 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
| 164 | def mk_pipelines_ref = env.MK_PIPELINES_REF ?: '' |
| 165 | def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: '' |
| 166 | def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: '' |
| 167 | def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: '' |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 168 | def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: '' |
| 169 | def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: '' |
Dennis Dmitriev | 6346004 | 2018-12-11 13:08:11 +0200 | [diff] [blame] | 170 | def env_ipmi_user = env.IPMI_USER ?: '' |
| 171 | def env_ipmi_pass = env.IPMI_PASS ?: '' |
| 172 | def env_lab_mgm_iface = env.LAB_MANAGEMENT_IFACE ?: '' |
| 173 | def env_lab_ctl_iface = env.LAB_CONTROL_IFACE ?: '' |
sgudz | b795338 | 2019-02-18 17:59:30 +0200 | [diff] [blame] | 174 | def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 175 | def parameters = [ |
| 176 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 177 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 178 | string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"), |
| 179 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 180 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
| 181 | string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"), |
| 182 | string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"), |
| 183 | string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 184 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
| 185 | string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"), |
| 186 | string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"), |
| 187 | string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"), |
| 188 | string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"), |
| 189 | string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"), |
| 190 | string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"), |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 191 | string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"), |
| 192 | string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"), |
Dennis Dmitriev | 6346004 | 2018-12-11 13:08:11 +0200 | [diff] [blame] | 193 | string(name: 'IPMI_USER', value: env_ipmi_user), |
| 194 | string(name: 'IPMI_PASS', value: env_ipmi_pass), |
| 195 | string(name: 'LAB_MANAGEMENT_IFACE', value: env_lab_mgm_iface), |
| 196 | string(name: 'LAB_CONTROL_IFACE', value: env_lab_ctl_iface), |
sgudz | b795338 | 2019-02-18 17:59:30 +0200 | [diff] [blame] | 197 | string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 198 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 199 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 200 | |
| 201 | build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 202 | } |
| 203 | |
Dennis Dmitriev | 07d5b8a | 2018-10-29 19:43:00 +0200 | [diff] [blame] | 204 | def swarm_deploy_cicd(String stack_to_install, String install_timeout) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 205 | // Run openstack_deploy job on cfg01 Jenkins for specified stacks |
| 206 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 207 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 208 | def parameters = [ |
| 209 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 210 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 211 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 212 | string(name: 'STACK_INSTALL', value: stack_to_install), |
Dennis Dmitriev | 07d5b8a | 2018-10-29 19:43:00 +0200 | [diff] [blame] | 213 | string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 214 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 215 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 216 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 217 | build_pipeline_job('swarm-deploy-cicd', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 218 | } |
| 219 | |
Dennis Dmitriev | 07d5b8a | 2018-10-29 19:43:00 +0200 | [diff] [blame] | 220 | def swarm_deploy_platform(String stack_to_install, String install_timeout) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 221 | // Run openstack_deploy job on CICD Jenkins for specified stacks |
| 222 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 223 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 224 | def parameters = [ |
| 225 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 226 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 227 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 228 | string(name: 'STACK_INSTALL', value: stack_to_install), |
Dennis Dmitriev | 07d5b8a | 2018-10-29 19:43:00 +0200 | [diff] [blame] | 229 | string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 230 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 231 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 232 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 233 | build_pipeline_job('swarm-deploy-platform', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 234 | } |
| 235 | |
sgudz | 2ed9585 | 2019-03-01 14:48:52 +0200 | [diff] [blame] | 236 | def swarm_deploy_platform_non_cicd(String stack_to_install, String install_timeout) { |
| 237 | // Run openstack_deploy job on day01 Jenkins for specified stacks |
| 238 | def common = new com.mirantis.mk.Common() |
| 239 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
| 240 | def parameters = [ |
| 241 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 242 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 243 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 244 | string(name: 'STACK_INSTALL', value: stack_to_install), |
| 245 | string(name: 'STACK_INSTALL_TIMEOUT', value: install_timeout), |
| 246 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
| 247 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 248 | ] |
| 249 | build_pipeline_job('swarm-deploy-platform-without-cicd', parameters) |
| 250 | } |
| 251 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 252 | def swarm_run_pytest(String passed_steps) { |
| 253 | // Run pytest tests |
| 254 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 255 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Tatyana Leontovich | 05f7940 | 2018-11-16 15:04:02 +0200 | [diff] [blame] | 256 | def tempest_image_version = env.TEMPEST_IMAGE_VERSION ?: 'pike' |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 257 | def tempest_target=env.TEMPEST_TARGET ?: 'gtw01' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 258 | def parameters = [ |
| 259 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 260 | string(name: 'PASSED_STEPS', value: passed_steps), |
| 261 | string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"), |
| 262 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 263 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 264 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 265 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 266 | string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"), |
| 267 | string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"), |
| 268 | string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"), |
| 269 | string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"), |
Tatyana Leontovich | 05f7940 | 2018-11-16 15:04:02 +0200 | [diff] [blame] | 270 | string(name: 'TEMPEST_IMAGE_VERSION', value: "${tempest_image_version}"), |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 271 | string(name: 'TEMPEST_TARGET', value: "${tempest_target}"), |
Tatyana Leontovich | f371844 | 2018-10-31 13:36:13 +0200 | [diff] [blame] | 272 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 273 | ] |
| 274 | common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple") |
| 275 | common.prettyPrint(parameters) |
| 276 | build job: 'swarm-run-pytest', |
| 277 | parameters: parameters |
| 278 | } |
| 279 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 280 | def swarm_testrail_report(String passed_steps) { |
| 281 | // Run pytest tests |
| 282 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 283 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Tatyana Leontovich | f371844 | 2018-10-31 13:36:13 +0200 | [diff] [blame] | 284 | def tempest_test_suite_name = env.TEMPEST_TEST_SUITE_NAME |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 285 | def parameters = [ |
| 286 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 287 | string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"), |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 288 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
| 289 | string(name: 'PASSED_STEPS', value: passed_steps), |
| 290 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 291 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 292 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Tatyana Leontovich | f371844 | 2018-10-31 13:36:13 +0200 | [diff] [blame] | 293 | string(name: 'TEMPEST_TEST_SUITE_NAME', value: "${tempest_test_suite_name}"), |
Vladimir Jigulin | 151097d | 2019-03-21 18:39:47 +0400 | [diff] [blame] | 294 | string(name: 'TEST_PLAN_NAME_PREFIX', value: env.TESTRAIL_TEST_PLAN_NAME_PREFIX ?: ''), |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 295 | ] |
| 296 | common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple") |
| 297 | common.prettyPrint(parameters) |
| 298 | build job: 'swarm-testrail-report', |
| 299 | parameters: parameters |
| 300 | } |
| 301 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 302 | def generate_cookied_model() { |
| 303 | def common = new com.mirantis.mk.Common() |
| 304 | // do not fail if environment doesn't exists |
| 305 | def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last() |
| 306 | def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last() |
| 307 | def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last() |
| 308 | def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last() |
| 309 | println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN) |
| 310 | println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL) |
| 311 | println("IPV4_NET_TENANT=" + IPV4_NET_TENANT) |
| 312 | println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL) |
| 313 | |
Dennis Dmitriev | e388465 | 2019-03-05 14:26:44 +0200 | [diff] [blame] | 314 | def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: "release/${env.MCP_VERSION}" |
| 315 | def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: "release/${env.MCP_VERSION}" |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 316 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
| 317 | def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: '' |
| 318 | def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: '' |
sgudz | b795338 | 2019-02-18 17:59:30 +0200 | [diff] [blame] | 319 | def update_repo_custom_tag = env.UPDATE_REPO_CUSTOM_TAG ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 320 | |
| 321 | def parameters = [ |
| 322 | string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"), |
| 323 | string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"), |
| 324 | string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"), |
| 325 | string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"), |
| 326 | string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"), |
| 327 | string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 328 | string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"), |
| 329 | string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"), |
| 330 | string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 331 | string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN), |
| 332 | string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL), |
| 333 | string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT), |
| 334 | string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL), |
sgudz | c97385a | 2018-11-29 17:01:53 +0200 | [diff] [blame] | 335 | string(name: 'IPMI_USER', value: env.IPMI_USER), |
| 336 | string(name: 'IPMI_PASS', value: env.IPMI_PASS), |
sgudz | b795338 | 2019-02-18 17:59:30 +0200 | [diff] [blame] | 337 | string(name: 'UPDATE_REPO_CUSTOM_TAG', value: "${update_repo_custom_tag}"), |
sgudz | c97385a | 2018-11-29 17:01:53 +0200 | [diff] [blame] | 338 | string(name: 'IMAGE_PATH_CFG01_DAY01', value: env.IMAGE_PATH_CFG01_DAY01), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 339 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 340 | |
| 341 | build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml") |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | def generate_configdrive_iso() { |
| 345 | def common = new com.mirantis.mk.Common() |
| 346 | def SALT_MASTER_IP=run_cmd_stdout("""\ |
| 347 | export ENV_NAME=${ENV_NAME} |
| 348 | . ./tcp_tests/utils/env_salt |
| 349 | echo \$SALT_MASTER_IP |
| 350 | """).trim().split().last() |
| 351 | println("SALT_MASTER_IP=" + SALT_MASTER_IP) |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 352 | |
Dennis Dmitriev | f220d97 | 2018-10-10 15:19:14 +0300 | [diff] [blame] | 353 | def dhcp_ranges_json=run_cmd_stdout("""\ |
| 354 | fgrep dhcp_ranges ${ENV_NAME}_hardware.ini | |
| 355 | fgrep "admin-pool01"| |
| 356 | cut -d"=" -f2 |
| 357 | """).trim().split("\n").last() |
| 358 | def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json) |
| 359 | def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway'] |
| 360 | println("ADMIN_NETWORK_GW=" + ADMIN_NETWORK_GW) |
| 361 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 362 | def mk_pipelines_ref = env.MK_PIPELINES_REF ?: '' |
| 363 | def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: '' |
Dennis Dmitriev | f220d97 | 2018-10-10 15:19:14 +0300 | [diff] [blame] | 364 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 365 | def mcp_salt_repo_url = env.MCP_SALT_REPO_URL ?: '' |
| 366 | def mcp_salt_repo_key = env.MCP_SALT_REPO_KEY ?: '' |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 367 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 368 | def parameters = [ |
| 369 | string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"), |
| 370 | string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"), |
| 371 | string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"), |
| 372 | booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true), |
| 373 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
Dennis Dmitriev | e388465 | 2019-03-05 14:26:44 +0200 | [diff] [blame] | 374 | string(name: 'COMMON_SCRIPTS_COMMIT', value: "release/${env.MCP_VERSION}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 375 | string(name: 'NODE_NAME', value: "${NODE_NAME}"), |
| 376 | string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"), |
| 377 | string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP), |
Dennis Dmitriev | f220d97 | 2018-10-10 15:19:14 +0300 | [diff] [blame] | 378 | string(name: 'DEPLOY_NETWORK_GW', value: "${ADMIN_NETWORK_GW}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 379 | string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"), |
| 380 | booleanParam(name: 'PIPELINES_FROM_ISO', value: true), |
Dennis Dmitriev | d9168b5 | 2018-12-19 18:53:52 +0200 | [diff] [blame] | 381 | string(name: 'MCP_SALT_REPO_URL', value: "${mcp_salt_repo_url}"), |
| 382 | string(name: 'MCP_SALT_REPO_KEY', value: "${mcp_salt_repo_key}"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 383 | string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"), |
| 384 | string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"), |
Dennis Dmitriev | f220d97 | 2018-10-10 15:19:14 +0300 | [diff] [blame] | 385 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 386 | ] |
Dennis Dmitriev | f220d97 | 2018-10-10 15:19:14 +0300 | [diff] [blame] | 387 | build_pipeline_job('swarm-create-cfg-config-drive', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 388 | } |
| 389 | |
Dennis Dmitriev | 13e804b | 2018-10-09 19:25:14 +0300 | [diff] [blame] | 390 | def run_job_on_day01_node(stack_to_install, timeout=2400) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 391 | // stack_to_install="core,cicd" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 392 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 393 | def stack = "${stack_to_install}" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 394 | common.printMsg("Deploy DriveTrain CICD components: ${stack_to_install}", "blue") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 395 | try { |
| 396 | run_cmd("""\ |
| 397 | export ENV_NAME=${ENV_NAME} |
| 398 | . ./tcp_tests/utils/env_salt |
| 399 | . ./tcp_tests/utils/env_jenkins_day01 |
| 400 | export JENKINS_BUILD_TIMEOUT=${timeout} |
| 401 | JOB_PARAMETERS=\"{ |
| 402 | \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\", |
| 403 | \\\"STACK_INSTALL\\\": \\\"${stack}\\\" |
| 404 | }\" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 405 | JOB_PREFIX="[ ${ENV_NAME}/{build_number}:drivetrain {time} ] " |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 406 | python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX" |
| 407 | """) |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 408 | // Wait for IO calm down on cluster nodes |
| 409 | sleep(60) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 410 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 411 | common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 412 | def workflow_details=run_cmd_stdout("""\ |
| 413 | . ./tcp_tests/utils/env_salt |
| 414 | . ./tcp_tests/utils/env_jenkins_day01 |
| 415 | export JOB_NAME=deploy_openstack |
| 416 | export BUILD_NUMBER=lastBuild |
| 417 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 418 | """) |
| 419 | throw new Exception(workflow_details) |
| 420 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 421 | } |
| 422 | |
Dennis Dmitriev | 13e804b | 2018-10-09 19:25:14 +0300 | [diff] [blame] | 423 | def run_job_on_cicd_nodes(stack_to_install, timeout=2400) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 424 | // stack_to_install="k8s,calico,stacklight" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 425 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 426 | def stack = "${stack_to_install}" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 427 | common.printMsg("Deploy Platform components: ${stack_to_install}", "blue") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 428 | try { |
| 429 | run_cmd("""\ |
| 430 | export ENV_NAME=${ENV_NAME} |
| 431 | . ./tcp_tests/utils/env_salt |
| 432 | . ./tcp_tests/utils/env_jenkins_cicd |
| 433 | export JENKINS_BUILD_TIMEOUT=${timeout} |
| 434 | JOB_PARAMETERS=\"{ |
| 435 | \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\", |
| 436 | \\\"STACK_INSTALL\\\": \\\"${stack}\\\" |
| 437 | }\" |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 438 | JOB_PREFIX="[ ${ENV_NAME}/{build_number}:platform {time} ] " |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 439 | python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX" |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 440 | """) |
Dennis Dmitriev | 44f6db2 | 2018-10-31 16:07:56 +0200 | [diff] [blame] | 441 | // Wait for IO calm down on cluster nodes |
| 442 | sleep(60) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 443 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 444 | common.printMsg("Product job 'deploy_openstack' failed, getting details", "purple") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 445 | def workflow_details=run_cmd_stdout("""\ |
| 446 | . ./tcp_tests/utils/env_salt |
| 447 | . ./tcp_tests/utils/env_jenkins_cicd |
| 448 | export JOB_NAME=deploy_openstack |
| 449 | export BUILD_NUMBER=lastBuild |
| 450 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 451 | """) |
| 452 | throw new Exception(workflow_details) |
| 453 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | def sanity_check_component(stack) { |
| 457 | // Run sanity check for the component ${stack}. |
| 458 | // Result will be stored in JUnit XML file deploy_${stack}.xml |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 459 | try { |
| 460 | run_cmd("""\ |
| 461 | py.test --junit-xml=deploy_${stack}.xml -m check_${stack} |
| 462 | """) |
| 463 | } catch (e) { |
| 464 | def String junit_report_xml = readFile("deploy_${stack}.xml") |
| 465 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
| 466 | def String msg = "Sanity check for '${stack}' failed, JUnit report:\n" |
| 467 | throw new Exception(msg + junit_report_xml_pretty) |
| 468 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 469 | } |
| 470 | |
Dennis Dmitriev | efe5c0b | 2018-10-24 20:35:26 +0300 | [diff] [blame] | 471 | def download_logs(archive_name_prefix) { |
| 472 | // Archive and download logs and debug info from salt nodes in the lab |
| 473 | // Do not fail in case of error to not lose the original error from the parent exception. |
| 474 | def common = new com.mirantis.mk.Common() |
| 475 | common.printMsg("Downloading nodes logs by ${archive_name_prefix}", "blue") |
| 476 | run_cmd("""\ |
| 477 | export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini |
| 478 | ./tcp_tests/utils/get_logs.py --archive-name-prefix ${archive_name_prefix} || true |
| 479 | """) |
| 480 | } |
| 481 | |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 482 | def devops_snapshot_info(snapshot_name) { |
| 483 | // Print helper message after snapshot |
| 484 | def common = new com.mirantis.mk.Common() |
| 485 | |
| 486 | def SALT_MASTER_IP=run_cmd_stdout("""\ |
| 487 | . ./tcp_tests/utils/env_salt |
| 488 | echo \$SALT_MASTER_IP |
| 489 | """).trim().split().last() |
| 490 | def login = "root" // set fixed 'root' login for now |
| 491 | def password = "r00tme" // set fixed 'root' login for now |
| 492 | def key_file = "${env.WORKSPACE}/id_rsa" // set fixed path in the WORKSPACE |
| 493 | def VENV_PATH='/home/jenkins/fuel-devops30' |
| 494 | |
| 495 | common.printMsg("""\ |
| 496 | ######################### |
| 497 | # To revert the snapshot: |
| 498 | ######################### |
| 499 | . ${VENV_PATH}/bin/activate; |
| 500 | dos.py revert ${ENV_NAME} ${snapshot_name}; |
| 501 | dos.py resume ${ENV_NAME}; |
| 502 | # dos.py time-sync ${ENV_NAME}; # Optional\n |
| 503 | ssh -i ${key_file} ${login}@${SALT_MASTER_IP} # Optional password: ${password} |
| 504 | """, "cyan") |
| 505 | } |
| 506 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 507 | def devops_snapshot(stack) { |
| 508 | // Make the snapshot with name "${stack}_deployed" |
| 509 | // for all VMs in the environment. |
| 510 | // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists, |
| 511 | // then make a copy for the created snapshot to allow the system |
| 512 | // tests to revert this snapshot along with the metadata from the INI file. |
| 513 | run_cmd("""\ |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 514 | set -ex |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 515 | dos.py suspend ${ENV_NAME} |
| 516 | dos.py snapshot ${ENV_NAME} ${stack}_deployed |
| 517 | dos.py resume ${ENV_NAME} |
Dennis Dmitriev | 1fed666 | 2018-07-27 18:22:13 +0300 | [diff] [blame] | 518 | sleep 20 # Wait for I/O on the host calms down |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 519 | |
| 520 | CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1) |
| 521 | dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME} |
| 522 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 523 | if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then |
| 524 | cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini |
| 525 | fi |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 526 | """) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 527 | devops_snapshot_info("${stack}_deployed") |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 528 | } |
| 529 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 530 | def get_steps_list(steps) { |
| 531 | // Make a list from comma separated string |
| 532 | return steps.split(',').collect { it.split(':')[0] } |
| 533 | } |
| 534 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 535 | def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') { |
| 536 | // <filename> is name of the XML report file that will be created |
| 537 | // <status> is one of the 'success', 'skipped', 'failure' or 'error' |
| 538 | // 'error' status is assumed as 'Blocker' in TestRail reporter |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 539 | |
| 540 | // Replace '<' and '>' to '<' and '>' to avoid conflicts between xml tags in the message and JUnit report |
| 541 | def String text_filtered = text.replaceAll("<","<").replaceAll(">", ">") |
| 542 | |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 543 | def script = """\ |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 544 | <?xml version=\"1.0\" encoding=\"utf-8\"?> |
| 545 | <testsuite> |
| 546 | <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\"> |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 547 | <${status} message=\"${status_message}\">${text_filtered}</${status}> |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 548 | <system-out>${stdout}</system-out> |
| 549 | <system-err>${stderr}</system-err> |
| 550 | </testcase> |
| 551 | </testsuite> |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 552 | """ |
| 553 | writeFile(file: filename, text: script, encoding: "UTF-8") |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 554 | } |
| 555 | |
Vladimir Jigulin | 151097d | 2019-03-21 18:39:47 +0400 | [diff] [blame] | 556 | def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[], testPlanNamePrefix=null) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 557 | def venvPath = '/home/jenkins/venv_testrail_reporter' |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 558 | def testPlanDesc = env.LAB_CONFIG_NAME |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 559 | def testrailURL = "https://mirantis.testrail.com" |
| 560 | def testrailProject = "Mirantis Cloud Platform" |
Vladimir Jigulin | 151097d | 2019-03-21 18:39:47 +0400 | [diff] [blame] | 561 | if (!testPlanNamePrefix) { |
| 562 | testPlanNamePrefix = "[MCP-Q2]System" |
| 563 | } |
| 564 | def testPlanName = "${testPlanNamePrefix}-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 565 | def testrailMilestone = "MCP1.1" |
Dennis Dmitriev | 707b215 | 2018-10-23 19:12:48 +0300 | [diff] [blame] | 566 | def testrailCaseMaxNameLenght = 250 |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 567 | def jobURL = env.BUILD_URL |
| 568 | |
| 569 | def reporterOptions = [ |
| 570 | "--verbose", |
| 571 | "--env-description \"${testPlanDesc}\"", |
| 572 | "--testrail-run-update", |
| 573 | "--testrail-url \"${testrailURL}\"", |
| 574 | "--testrail-user \"\${TESTRAIL_USER}\"", |
| 575 | "--testrail-password \"\${TESTRAIL_PASSWORD}\"", |
| 576 | "--testrail-project \"${testrailProject}\"", |
| 577 | "--testrail-plan-name \"${testPlanName}\"", |
| 578 | "--testrail-milestone \"${testrailMilestone}\"", |
| 579 | "--testrail-suite \"${testSuiteName}\"", |
| 580 | "--xunit-name-template \"${methodname}\"", |
| 581 | "--testrail-name-template \"${testrail_name_template}\"", |
| 582 | "--test-results-link \"${jobURL}\"", |
Dennis Dmitriev | 707b215 | 2018-10-23 19:12:48 +0300 | [diff] [blame] | 583 | "--testrail-case-max-name-lenght ${testrailCaseMaxNameLenght}", |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 584 | ] + reporter_extra_options |
| 585 | |
| 586 | def script = """ |
| 587 | . ${venvPath}/bin/activate |
| 588 | set -ex |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 589 | report ${reporterOptions.join(' ')} '${report_name}' |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 590 | """ |
| 591 | |
| 592 | def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests' |
| 593 | |
| 594 | withCredentials([ |
| 595 | [$class : 'UsernamePasswordMultiBinding', |
| 596 | credentialsId : testrail_cred_id, |
| 597 | passwordVariable: 'TESTRAIL_PASSWORD', |
| 598 | usernameVariable: 'TESTRAIL_USER'] |
| 599 | ]) { |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 600 | return run_cmd_stdout(script) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | |
| 605 | def create_deploy_result_report(deploy_expected_stacks, result, text) { |
| 606 | def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error'] |
| 607 | def classname = "Deploy" |
| 608 | def name = "deployment_${ENV_NAME}" |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 609 | def filename = "${name}.xml" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 610 | def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch |
| 611 | create_xml_report(filename, classname, name, status, "Deploy components: ${deploy_expected_stacks}", text, '', '') |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 612 | } |