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 | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 5 | def run_cmd(String cmd, Boolean returnStdout=false) { |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 6 | def common = new com.mirantis.mk.Common() |
| 7 | common.printMsg("Run shell command:\n" + cmd, "blue") |
| 8 | def VENV_PATH='/home/jenkins/fuel-devops30' |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 9 | def stderr_path = "/tmp/${JOB_NAME}_${BUILD_NUMBER}_stderr.log" |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 10 | script = """\ |
| 11 | set +x; |
| 12 | echo 'activate python virtualenv ${VENV_PATH}'; |
| 13 | . ${VENV_PATH}/bin/activate; |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 14 | bash -c 'set -ex; set -ex; ${cmd.stripIndent()}' 2>${stderr_path} |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 15 | """ |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 16 | def result |
| 17 | try { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 18 | return sh(script: script, returnStdout: returnStdout) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 19 | } catch (e) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 20 | def stderr = readFile("${stderr_path}") |
| 21 | def error_message = e.message + "\n<<<<<< STDERR: >>>>>>\n" + stderr |
| 22 | throw new Exception(error_message) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 23 | } finally { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 24 | sh(script: "rm ${stderr_path} || true") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 25 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | def run_cmd_stdout(cmd) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 29 | return run_cmd(cmd, true) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 30 | } |
| 31 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 32 | def build_pipeline_job(job_name, parameters) { |
| 33 | //Build a job, grab the results if failed and use the results in exception |
| 34 | def common = new com.mirantis.mk.Common() |
| 35 | common.printMsg("Start building job '${job_name}' with parameters:", "purple") |
| 36 | common.prettyPrint(parameters) |
| 37 | |
| 38 | def job_info = build job: "${job_name}", |
| 39 | parameters: parameters, |
| 40 | propagate: false |
| 41 | |
| 42 | if (job_info.getResult() != "SUCCESS") { |
| 43 | currentBuild.result = job_info.getResult() |
| 44 | def build_number = job_info.getNumber() |
| 45 | common.printMsg("Job '${job_name}' failed, getting details", "red") |
| 46 | def workflow_details=run_cmd_stdout("""\ |
| 47 | export JOB_NAME=${job_name} |
| 48 | export BUILD_NUMBER=${build_number} |
| 49 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 50 | """) |
| 51 | throw new Exception(workflow_details) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | def build_shell_job(job_name, parameters, junit_report_filename=null, junit_report_source_dir='**/') { |
| 56 | //Build a job, grab the results if failed and use the results in exception |
| 57 | //junit_report_filename: if not null, try to copy this JUnit report first from remote job |
| 58 | def common = new com.mirantis.mk.Common() |
| 59 | common.printMsg("Start building job '${job_name}' with parameters:", "purple") |
| 60 | common.prettyPrint(parameters) |
| 61 | |
| 62 | def job_info = build job: "${job_name}", |
| 63 | parameters: parameters, |
| 64 | propagate: false |
| 65 | |
| 66 | if (job_info.getResult() != "SUCCESS") { |
| 67 | def build_status = job_info.getResult() |
| 68 | def build_number = job_info.getNumber() |
| 69 | def build_url = job_info.getAbsoluteUrl() |
| 70 | def job_url = "${build_url}" |
| 71 | currentBuild.result = build_status |
| 72 | if (junit_report_filename) { |
| 73 | common.printMsg("Job '${job_url}' failed with status ${build_status}, getting details", "red") |
| 74 | step($class: 'hudson.plugins.copyartifact.CopyArtifact', |
| 75 | projectName: job_name, |
| 76 | selector: specific("${build_number}"), |
| 77 | filter: "${junit_report_source_dir}/${junit_report_filename}", |
| 78 | target: '.', |
| 79 | flatten: true, |
| 80 | fingerprintArtifacts: true) |
| 81 | |
| 82 | def String junit_report_xml = readFile("${junit_report_filename}") |
| 83 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
Dennis Dmitriev | 3f9329c | 2018-08-30 18:17:49 +0300 | [diff] [blame] | 84 | // Replace '<' and '>' to '<' and '>' to avoid conflicts between xml tags in the message and JUnit report |
| 85 | def String junit_report_xml_filtered = junit_report_xml_pretty.replaceAll("<","<").replaceAll(">", ">") |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 86 | def String msg = "Job '${job_url}' failed with status ${build_status}, JUnit report:\n" |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 87 | throw new Exception(msg + junit_report_xml_filtered) |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 88 | } else { |
| 89 | throw new Exception("Job '${job_url}' failed with status ${build_status}, please check the console output.") |
| 90 | } |
| 91 | } |
| 92 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 93 | |
| 94 | def prepare_working_dir() { |
| 95 | println "Clean the working directory ${env.WORKSPACE}" |
| 96 | deleteDir() |
| 97 | |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 98 | // do not fail if environment doesn't exists |
| 99 | println "Remove environment ${ENV_NAME}" |
| 100 | run_cmd("""\ |
| 101 | dos.py erase ${ENV_NAME} || true |
| 102 | """) |
| 103 | println "Remove config drive ISO" |
| 104 | run_cmd("""\ |
| 105 | rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true |
| 106 | """) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 107 | |
| 108 | run_cmd("""\ |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 109 | git clone https://github.com/Mirantis/tcp-qa.git ${env.WORKSPACE} |
| 110 | if [ -n "$TCP_QA_REFS" ]; then |
| 111 | set -e |
| 112 | git fetch https://review.gerrithub.io/Mirantis/tcp-qa $TCP_QA_REFS && git checkout FETCH_HEAD || exit \$? |
| 113 | fi |
| 114 | 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] | 115 | """) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | def swarm_bootstrap_salt_cluster_devops() { |
| 119 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 120 | def cookiecutter_template_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION |
| 121 | def salt_models_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION |
| 122 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
| 123 | def mk_pipelines_ref = env.MK_PIPELINES_REF ?: '' |
| 124 | def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: '' |
| 125 | def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: '' |
| 126 | def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 127 | def parameters = [ |
| 128 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 129 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 130 | string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"), |
| 131 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 132 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
| 133 | string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"), |
| 134 | string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"), |
| 135 | string(name: 'CFG01_CONFIG_IMAGE_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 136 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
| 137 | string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"), |
| 138 | string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"), |
| 139 | string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecutter_template_commit}"), |
| 140 | string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${salt_models_system_commit}"), |
| 141 | string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"), |
| 142 | string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 143 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 144 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 145 | |
| 146 | build_pipeline_job('swarm-bootstrap-salt-cluster-devops', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | def swarm_deploy_cicd(String stack_to_install='core,cicd') { |
| 150 | // Run openstack_deploy job on cfg01 Jenkins for specified stacks |
| 151 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 152 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 153 | def parameters = [ |
| 154 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 155 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
| 156 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 157 | string(name: 'STACK_INSTALL', value: stack_to_install), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 158 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 159 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 160 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 161 | build_pipeline_job('swarm-deploy-cicd', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | def swarm_deploy_platform(String stack_to_install) { |
| 165 | // Run openstack_deploy job on CICD Jenkins for specified stacks |
| 166 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 167 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
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: 'ENV_NAME', value: "${ENV_NAME}"), |
| 172 | string(name: 'STACK_INSTALL', value: stack_to_install), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 173 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 174 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 175 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 176 | build_pipeline_job('swarm-deploy-platform', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 177 | } |
| 178 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 179 | def swarm_run_pytest(String passed_steps) { |
| 180 | // Run pytest tests |
| 181 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 182 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 183 | def parameters = [ |
| 184 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 185 | string(name: 'PASSED_STEPS', value: passed_steps), |
| 186 | string(name: 'RUN_TEST_OPTS', value: "${RUN_TEST_OPTS}"), |
| 187 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 188 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 189 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 190 | booleanParam(name: 'SHUTDOWN_ENV_ON_TEARDOWN', value: false), |
| 191 | string(name: 'LAB_CONFIG_NAME', value: "${LAB_CONFIG_NAME}"), |
| 192 | string(name: 'REPOSITORY_SUITE', value: "${MCP_VERSION}"), |
| 193 | string(name: 'MCP_IMAGE_PATH1604', value: "${MCP_IMAGE_PATH1604}"), |
| 194 | string(name: 'IMAGE_PATH_CFG01_DAY01', value: "${IMAGE_PATH_CFG01_DAY01}"), |
| 195 | ] |
| 196 | common.printMsg("Start building job 'swarm-run-pytest' with parameters:", "purple") |
| 197 | common.prettyPrint(parameters) |
| 198 | build job: 'swarm-run-pytest', |
| 199 | parameters: parameters |
| 200 | } |
| 201 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 202 | def swarm_testrail_report(String passed_steps) { |
| 203 | // Run pytest tests |
| 204 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 205 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 206 | def parameters = [ |
| 207 | string(name: 'ENV_NAME', value: "${ENV_NAME}"), |
| 208 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
| 209 | string(name: 'PASSED_STEPS', value: passed_steps), |
| 210 | string(name: 'PARENT_NODE_NAME', value: "${NODE_NAME}"), |
| 211 | string(name: 'PARENT_WORKSPACE', value: pwd()), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 212 | string(name: 'TCP_QA_REFS', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 213 | ] |
| 214 | common.printMsg("Start building job 'swarm-testrail-report' with parameters:", "purple") |
| 215 | common.prettyPrint(parameters) |
| 216 | build job: 'swarm-testrail-report', |
| 217 | parameters: parameters |
| 218 | } |
| 219 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 220 | def generate_cookied_model() { |
| 221 | def common = new com.mirantis.mk.Common() |
| 222 | // do not fail if environment doesn't exists |
| 223 | def IPV4_NET_ADMIN=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last() |
| 224 | def IPV4_NET_CONTROL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last() |
| 225 | def IPV4_NET_TENANT=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last() |
| 226 | def IPV4_NET_EXTERNAL=run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last() |
| 227 | println("IPV4_NET_ADMIN=" + IPV4_NET_ADMIN) |
| 228 | println("IPV4_NET_CONTROL=" + IPV4_NET_CONTROL) |
| 229 | println("IPV4_NET_TENANT=" + IPV4_NET_TENANT) |
| 230 | println("IPV4_NET_EXTERNAL=" + IPV4_NET_EXTERNAL) |
| 231 | |
| 232 | def cookiecuttertemplate_commit = env.COOKIECUTTER_TEMPLATE_COMMIT ?: env.MCP_VERSION |
| 233 | def saltmodels_system_commit = env.SALT_MODELS_SYSTEM_COMMIT ?: env.MCP_VERSION |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 234 | def tcp_qa_refs = env.TCP_QA_REFS ?: '' |
| 235 | def environment_template_ref_change = env.ENVIRONMENT_TEMPLATE_REF_CHANGE ?: '' |
| 236 | def cookiecutter_ref_change = env.COOKIECUTTER_REF_CHANGE ?: '' |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 237 | |
| 238 | def parameters = [ |
| 239 | string(name: 'LAB_CONTEXT_NAME', value: "${LAB_CONFIG_NAME}"), |
| 240 | string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"), |
| 241 | string(name: 'DOMAIN_NAME', value: "${LAB_CONFIG_NAME}.local"), |
| 242 | string(name: 'REPOSITORY_SUITE', value: "${env.MCP_VERSION}"), |
| 243 | string(name: 'SALT_MODELS_SYSTEM_COMMIT', value: "${saltmodels_system_commit}"), |
| 244 | string(name: 'COOKIECUTTER_TEMPLATE_COMMIT', value: "${cookiecuttertemplate_commit}"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 245 | string(name: 'COOKIECUTTER_REF_CHANGE', value: "${cookiecutter_ref_change}"), |
| 246 | string(name: 'ENVIRONMENT_TEMPLATE_REF_CHANGE', value: "${environment_template_ref_change}"), |
| 247 | string(name: 'TCP_QA_REVIEW', value: "${tcp_qa_refs}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 248 | string(name: 'IPV4_NET_ADMIN', value: IPV4_NET_ADMIN), |
| 249 | string(name: 'IPV4_NET_CONTROL', value: IPV4_NET_CONTROL), |
| 250 | string(name: 'IPV4_NET_TENANT', value: IPV4_NET_TENANT), |
| 251 | string(name: 'IPV4_NET_EXTERNAL', value: IPV4_NET_EXTERNAL), |
| 252 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 253 | |
| 254 | build_shell_job('swarm-cookied-model-generator', parameters, "deploy_generate_model.xml") |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | def generate_configdrive_iso() { |
| 258 | def common = new com.mirantis.mk.Common() |
| 259 | def SALT_MASTER_IP=run_cmd_stdout("""\ |
| 260 | export ENV_NAME=${ENV_NAME} |
| 261 | . ./tcp_tests/utils/env_salt |
| 262 | echo \$SALT_MASTER_IP |
| 263 | """).trim().split().last() |
| 264 | println("SALT_MASTER_IP=" + SALT_MASTER_IP) |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 265 | |
| 266 | def mk_pipelines_ref = env.MK_PIPELINES_REF ?: '' |
| 267 | def pipeline_library_ref = env.PIPELINE_LIBRARY_REF ?: '' |
| 268 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 269 | def parameters = [ |
| 270 | string(name: 'CLUSTER_NAME', value: "${LAB_CONFIG_NAME}"), |
| 271 | string(name: 'MODEL_URL', value: "http://cz8133.bud.mirantis.net:8098/${LAB_CONFIG_NAME}.git"), |
| 272 | string(name: 'MODEL_URL_OBJECT_TYPE', value: "git"), |
| 273 | booleanParam(name: 'DOWNLOAD_CONFIG_DRIVE', value: true), |
| 274 | string(name: 'MCP_VERSION', value: "${MCP_VERSION}"), |
| 275 | string(name: 'COMMON_SCRIPTS_COMMIT', value: "${MCP_VERSION}"), |
| 276 | string(name: 'NODE_NAME', value: "${NODE_NAME}"), |
| 277 | string(name: 'CONFIG_DRIVE_ISO_NAME', value: "${CFG01_CONFIG_IMAGE_NAME}"), |
| 278 | string(name: 'SALT_MASTER_DEPLOY_IP', value: SALT_MASTER_IP), |
| 279 | string(name: 'PIPELINE_REPO_URL', value: "https://github.com/Mirantis"), |
| 280 | booleanParam(name: 'PIPELINES_FROM_ISO', value: true), |
| 281 | string(name: 'MCP_SALT_REPO_URL', value: "http://apt.mirantis.com/xenial"), |
| 282 | string(name: 'MCP_SALT_REPO_KEY', value: "http://apt.mirantis.com/public.gpg"), |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 283 | string(name: 'PIPELINE_LIBRARY_REF', value: "${pipeline_library_ref}"), |
| 284 | string(name: 'MK_PIPELINES_REF', value: "${mk_pipelines_ref}"), |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 285 | ] |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 286 | build_pipeline_job('create-cfg-config-drive', parameters) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | def run_job_on_day01_node(stack_to_install, timeout=1800) { |
| 290 | // stack_to_install="core,cicd" |
| 291 | def stack = "${stack_to_install}" |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 292 | try { |
| 293 | run_cmd("""\ |
| 294 | export ENV_NAME=${ENV_NAME} |
| 295 | . ./tcp_tests/utils/env_salt |
| 296 | . ./tcp_tests/utils/env_jenkins_day01 |
| 297 | export JENKINS_BUILD_TIMEOUT=${timeout} |
| 298 | JOB_PARAMETERS=\"{ |
| 299 | \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\", |
| 300 | \\\"STACK_INSTALL\\\": \\\"${stack}\\\" |
| 301 | }\" |
| 302 | JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] " |
| 303 | python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX" |
| 304 | """) |
| 305 | } catch (e) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 306 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 307 | common.printMsg("Product job 'deploy_openstack' failed, getting details", "red") |
| 308 | def workflow_details=run_cmd_stdout("""\ |
| 309 | . ./tcp_tests/utils/env_salt |
| 310 | . ./tcp_tests/utils/env_jenkins_day01 |
| 311 | export JOB_NAME=deploy_openstack |
| 312 | export BUILD_NUMBER=lastBuild |
| 313 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 314 | """) |
| 315 | throw new Exception(workflow_details) |
| 316 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | def run_job_on_cicd_nodes(stack_to_install, timeout=1800) { |
| 320 | // stack_to_install="k8s,calico,stacklight" |
| 321 | def stack = "${stack_to_install}" |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 322 | try { |
| 323 | run_cmd("""\ |
| 324 | export ENV_NAME=${ENV_NAME} |
| 325 | . ./tcp_tests/utils/env_salt |
| 326 | . ./tcp_tests/utils/env_jenkins_cicd |
| 327 | export JENKINS_BUILD_TIMEOUT=${timeout} |
| 328 | JOB_PARAMETERS=\"{ |
| 329 | \\\"SALT_MASTER_URL\\\": \\\"\${SALTAPI_URL}\\\", |
| 330 | \\\"STACK_INSTALL\\\": \\\"${stack}\\\" |
| 331 | }\" |
| 332 | JOB_PREFIX="[ ${ENV_NAME}/{build_number}:${stack} {time} ] " |
| 333 | python ./tcp_tests/utils/run_jenkins_job.py --verbose --job-name=deploy_openstack --job-parameters="\$JOB_PARAMETERS" --job-output-prefix="\$JOB_PREFIX" |
| 334 | sleep 60 # Wait for IO calm down on cluster nodes |
| 335 | """) |
| 336 | } catch (e) { |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 337 | def common = new com.mirantis.mk.Common() |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 338 | common.printMsg("Product job 'deploy_openstack' failed, getting details", "red") |
| 339 | def workflow_details=run_cmd_stdout("""\ |
| 340 | . ./tcp_tests/utils/env_salt |
| 341 | . ./tcp_tests/utils/env_jenkins_cicd |
| 342 | export JOB_NAME=deploy_openstack |
| 343 | export BUILD_NUMBER=lastBuild |
| 344 | python ./tcp_tests/utils/get_jenkins_job_stages.py |
| 345 | """) |
| 346 | throw new Exception(workflow_details) |
| 347 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | def sanity_check_component(stack) { |
| 351 | // Run sanity check for the component ${stack}. |
| 352 | // Result will be stored in JUnit XML file deploy_${stack}.xml |
Dennis Dmitriev | 27a9679 | 2018-07-30 07:52:03 +0300 | [diff] [blame] | 353 | try { |
| 354 | run_cmd("""\ |
| 355 | py.test --junit-xml=deploy_${stack}.xml -m check_${stack} |
| 356 | """) |
| 357 | } catch (e) { |
| 358 | def String junit_report_xml = readFile("deploy_${stack}.xml") |
| 359 | def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml) |
| 360 | def String msg = "Sanity check for '${stack}' failed, JUnit report:\n" |
| 361 | throw new Exception(msg + junit_report_xml_pretty) |
| 362 | } |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | def devops_snapshot(stack) { |
| 366 | // Make the snapshot with name "${stack}_deployed" |
| 367 | // for all VMs in the environment. |
| 368 | // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists, |
| 369 | // then make a copy for the created snapshot to allow the system |
| 370 | // tests to revert this snapshot along with the metadata from the INI file. |
| 371 | run_cmd("""\ |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 372 | set -ex |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 373 | dos.py suspend ${ENV_NAME} |
| 374 | dos.py snapshot ${ENV_NAME} ${stack}_deployed |
| 375 | dos.py resume ${ENV_NAME} |
Dennis Dmitriev | 1fed666 | 2018-07-27 18:22:13 +0300 | [diff] [blame] | 376 | sleep 20 # Wait for I/O on the host calms down |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 377 | |
| 378 | CFG01_NAME=\$(dos.py show-resources ${ENV_NAME} | grep ^cfg01 | cut -d" " -f1) |
| 379 | dos.py time-sync ${ENV_NAME} --skip-sync \${CFG01_NAME} |
| 380 | |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 381 | if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then |
| 382 | cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini |
| 383 | fi |
Dennis Dmitriev | 8df3544 | 2018-07-31 08:40:20 +0300 | [diff] [blame] | 384 | """) |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 385 | } |
| 386 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 387 | def get_steps_list(steps) { |
| 388 | // Make a list from comma separated string |
| 389 | return steps.split(',').collect { it.split(':')[0] } |
| 390 | } |
| 391 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 392 | def create_xml_report(String filename, String classname, String name, String status='success', String status_message='', String text='', String stdout='', String stderr='') { |
| 393 | // <filename> is name of the XML report file that will be created |
| 394 | // <status> is one of the 'success', 'skipped', 'failure' or 'error' |
| 395 | // 'error' status is assumed as 'Blocker' in TestRail reporter |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 396 | def script = """\ |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 397 | <?xml version=\"1.0\" encoding=\"utf-8\"?> |
| 398 | <testsuite> |
| 399 | <testcase classname=\"${classname}\" name=\"${name}\" time=\"0\"> |
| 400 | <${status} message=\"${status_message}\">${text}</${status}> |
| 401 | <system-out>${stdout}</system-out> |
| 402 | <system-err>${stderr}</system-err> |
| 403 | </testcase> |
| 404 | </testsuite> |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 405 | """ |
| 406 | writeFile(file: filename, text: script, encoding: "UTF-8") |
Dennis Dmitriev | b3b3749 | 2018-07-08 21:23:00 +0300 | [diff] [blame] | 407 | } |
| 408 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 409 | def upload_results_to_testrail(report_name, testSuiteName, methodname, testrail_name_template, reporter_extra_options=[]) { |
| 410 | def venvPath = '/home/jenkins/venv_testrail_reporter' |
| 411 | def testPlanDesc = env.ENV_NAME |
| 412 | def testrailURL = "https://mirantis.testrail.com" |
| 413 | def testrailProject = "Mirantis Cloud Platform" |
| 414 | def testPlanName = "[MCP-Q2]System-${MCP_VERSION}-${new Date().format('yyyy-MM-dd')}" |
| 415 | def testrailMilestone = "MCP1.1" |
| 416 | def jobURL = env.BUILD_URL |
| 417 | |
| 418 | def reporterOptions = [ |
| 419 | "--verbose", |
| 420 | "--env-description \"${testPlanDesc}\"", |
| 421 | "--testrail-run-update", |
| 422 | "--testrail-url \"${testrailURL}\"", |
| 423 | "--testrail-user \"\${TESTRAIL_USER}\"", |
| 424 | "--testrail-password \"\${TESTRAIL_PASSWORD}\"", |
| 425 | "--testrail-project \"${testrailProject}\"", |
| 426 | "--testrail-plan-name \"${testPlanName}\"", |
| 427 | "--testrail-milestone \"${testrailMilestone}\"", |
| 428 | "--testrail-suite \"${testSuiteName}\"", |
| 429 | "--xunit-name-template \"${methodname}\"", |
| 430 | "--testrail-name-template \"${testrail_name_template}\"", |
| 431 | "--test-results-link \"${jobURL}\"", |
| 432 | ] + reporter_extra_options |
| 433 | |
| 434 | def script = """ |
| 435 | . ${venvPath}/bin/activate |
| 436 | set -ex |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame^] | 437 | report ${reporterOptions.join(' ')} ${report_name} |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 438 | """ |
| 439 | |
| 440 | def testrail_cred_id = params.TESTRAIL_CRED ?: 'testrail_system_tests' |
| 441 | |
| 442 | withCredentials([ |
| 443 | [$class : 'UsernamePasswordMultiBinding', |
| 444 | credentialsId : testrail_cred_id, |
| 445 | passwordVariable: 'TESTRAIL_PASSWORD', |
| 446 | usernameVariable: 'TESTRAIL_USER'] |
| 447 | ]) { |
| 448 | return run_cmd(script) |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | |
| 453 | def create_deploy_result_report(deploy_expected_stacks, result, text) { |
| 454 | def STATUS_MAP = ['SUCCESS': 'success', 'FAILURE': 'failure', 'UNSTABLE': 'failure', 'ABORTED': 'error'] |
| 455 | def classname = "Deploy" |
| 456 | def name = "deployment_${ENV_NAME}" |
Dennis Dmitriev | 3966608 | 2018-08-29 15:30:45 +0300 | [diff] [blame] | 457 | def filename = "${name}.xml" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 458 | def status = STATUS_MAP[result ?: 'FAILURE'] // currentBuild.result *must* be set at the finish of the try/catch |
| 459 | 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] | 460 | } |