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