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