blob: 27764a7df29c014ed970565cbf1fe9dde3ff28ee [file] [log] [blame]
Dennis Dmitrievfde667f2018-07-23 16:26:50 +03001@Library('tcp-qa')_
2
3def common = new com.mirantis.mk.Common()
4def shared = new com.mirantis.system_qa.SharedPipeline()
5def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL
Dennis Dmitriev4c383472019-04-12 13:58:06 +03006def env_manager = env.ENV_MANAGER ?: 'devops'
Hanna Arhipova6f493522019-12-25 04:23:28 +02007def batch_size = env.BATCH_SIZE ?: ''
Dennis Dmitriev02447412019-04-17 18:02:46 +03008
9if (env_manager == 'devops') {
10 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030011 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030012 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
13} else if (env_manager == 'heat') {
14 jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
15 make_snapshot_stages = false
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030016 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030017}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030018
Dennis Dmitriev27007322019-05-03 19:21:44 +030019currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030020
Dmitriy Kruglov9d1cbb12020-01-07 10:42:41 +010021def deploy(shared, common, steps, env_manager, batch_size) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030022 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030023 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030024
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030025 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030026 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030027 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030028
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030029 stage("Create environment, generate model, bootstrap the salt-cluster") {
30 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030031 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030032 shared.swarm_bootstrap_salt_cluster_devops()
33 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030034 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
35 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030036 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030037 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030038 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030039 } else {
40 throw new Exception("Unknow env_manager: '${env_manager}'")
41 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030042
43 if (fileExists("jenkins_agent_description.txt")) {
44 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
45 currentBuild.description += "${jenkins_agent_description}"
46 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030047 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030048
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030049 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030050 if (env.DRIVETRAIN_STACK_INSTALL) {
51 // steps: env.DRIVETRAIN_STACK_INSTALL
Hanna Arhipova6f493522019-12-25 04:23:28 +020052 shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030053 } else {
54 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
55 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030056 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030057
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030058 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030059 if (env.PLATFORM_STACK_INSTALL) {
60 // steps: env.PLATFORM_STACK_INSTALL
Hanna Arhipova6f493522019-12-25 04:23:28 +020061 shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030062 } else {
63 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
64 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030065 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030066
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030067 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030068
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030069 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030070 common.printMsg("Deploy is failed: " + e.message , "purple")
71 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030072 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030073 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030074 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030075 dos.py suspend ${ENV_NAME} || true
76 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030077 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030078 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
79 shared.run_cmd("""\
80 dos.py resume ${ENV_NAME} || true
81 """)
82 }
83 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030084 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030085 throw e
86 } finally {
87 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
88 }
89}
90
Dennis Dmitriev02447412019-04-17 18:02:46 +030091def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030092 try {
93 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030094 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030095 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030096 } else {
97 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
98 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030099 }
100
101 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300102 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300103 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300104 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300105 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300106 dos.py suspend ${ENV_NAME} || true
107 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300108 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300109 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
110 shared.run_cmd("""\
111 dos.py resume ${ENV_NAME} || true
112 """)
113 }
114 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300115 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300116 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300117 }
118}
119
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300120
121timeout(time: 15, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300122// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200123// Temporary disable throttle to check how it will run
124//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300125 node ("${NODE_NAME}") {
126 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300127 // run deploy stages
Dmitriy Kruglov9d1cbb12020-01-07 10:42:41 +0100128 deploy(shared, common, steps, env_manager, batch_size)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300129 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300130 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300131 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300132 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300133 throw e
134 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300135 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300136 // shutdown the environment if required
137 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
138 shared.run_cmd("""\
139 dos.py destroy ${ENV_NAME} || true
140 """)
141 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300142 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300143
144 stage("Archive all xml reports") {
145 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
146 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300147
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400148 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300149 stage("report results to testrail from jenkins master") {
150 common.printMsg("Running on: " + node_with_reports, "blue")
151 common.printMsg("Running on: " + env.NODE_NAME, "blue")
152 shared.verbose_sh("""\
153 [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter""", true, false, true)
154 shared.run_cmd("""\
Hanna Arhipova11092122020-01-28 20:07:49 +0200155 . /home/jenkins/venv_testrail_reporter/bin/activate; pip install git+https://github.com/dis-xcom/testrail_reporter -U""")
Tatyana Leontovich43854972019-05-24 23:02:22 +0300156 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400157 }
158 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300159 if (fileExists("description.txt")) {
160 def String description = readFile("description.txt")
161 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300162 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400163 }
Sergey Galkinda677fb2019-11-21 16:53:25 +0400164
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300165 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300166
167 if (fileExists("jenkins_agent_description.txt")) {
168 // if there is a separated foundation node on $jenkins_slave_node_name,
169 // then archive artifacts also on that node
170 if (jenkins_slave_node_name != env.NODE_NAME) {
171 node ("${jenkins_slave_node_name}") {
172 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
Sergey Galkinda677fb2019-11-21 16:53:25 +0400173 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300174 }
175 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
176 stage("report results to testrail") {
177 common.printMsg("Running on: " + node_with_reports, "blue")
178 shared.swarm_testrail_report(steps, node_with_reports)
179 }
180 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
181 if (fileExists("description.txt")) {
182 def String description = readFile("description.txt")
183 currentBuild.description += "${description}"
184 }
185 }
186 }
187 } // node
188 }
189 }
190
Dennis Dmitriev27007322019-05-03 19:21:44 +0300191 } // try
192 } // node
193
194
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300195//}
196} // timeout