blob: 1e35c9e25d95d159475711e059786661f4ec3a55 [file] [log] [blame]
Hanna Arhipova31cb1d82021-01-27 09:41:11 +02001/*
2* DEPLOY_EMPTY_NODE Add extra node to heat stack. Node without a role and with salt-minion
3*/
4
Dennis Dmitrievfde667f2018-07-23 16:26:50 +03005@Library('tcp-qa')_
6
7def common = new com.mirantis.mk.Common()
8def shared = new com.mirantis.system_qa.SharedPipeline()
9def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL
Dennis Dmitriev4c383472019-04-12 13:58:06 +030010def env_manager = env.ENV_MANAGER ?: 'devops'
Hanna Arhipova6f493522019-12-25 04:23:28 +020011def batch_size = env.BATCH_SIZE ?: ''
Dmitriy Kruglov28b68d62020-02-12 02:27:25 +010012def dist_upgrade_nodes = "${env.DIST_UPGRADE_NODES}" != "false" ? true : false
PGlazoved19b352020-05-21 16:42:27 +040013def upgrade_saltstack = "${env.UPGRADE_SALTSTACK}" != "false" ? true : false
Dennis Dmitriev02447412019-04-17 18:02:46 +030014
15if (env_manager == 'devops') {
16 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030017 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030018 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
19} else if (env_manager == 'heat') {
20 jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
21 make_snapshot_stages = false
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030022 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030023}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030024
Dennis Dmitriev27007322019-05-03 19:21:44 +030025currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030026
PGlazoved19b352020-05-21 16:42:27 +040027def deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030028 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030029 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030030
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030031 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030032 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030033 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030034
Hanna Arhipova3be50622021-01-11 13:11:45 +020035 // Reboot Hardware before the BM deployments
36 if ("$ENV_NAME".contains("bm-")){
37 reboot_hw_nodes = env.REBOOT_HW_NODES ?: false
38 stage("Reboot HW nodes") {
39 if (reboot_hw_nodes) {
40 shared.reboot_hardware_nodes()
41 } else {
42 common.printMsg("REBOOT_HW_NODES is disabled. Skipping this stage...", "blue")
43 }
44 }
45 }
46
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030047 stage("Create environment, generate model, bootstrap the salt-cluster") {
48 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030049 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030050 shared.swarm_bootstrap_salt_cluster_devops()
51 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030052 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
53 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030054 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030055 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030056 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030057 } else {
58 throw new Exception("Unknow env_manager: '${env_manager}'")
59 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030060
61 if (fileExists("jenkins_agent_description.txt")) {
62 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
63 currentBuild.description += "${jenkins_agent_description}"
64 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030065 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030066
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030067 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030068 if (env.DRIVETRAIN_STACK_INSTALL) {
69 // steps: env.DRIVETRAIN_STACK_INSTALL
PGlazovd4b70a02020-05-26 13:28:59 +040070 shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size, dist_upgrade_nodes, upgrade_saltstack)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030071 } else {
72 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
73 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030074 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030075
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030076 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030077 if (env.PLATFORM_STACK_INSTALL) {
78 // steps: env.PLATFORM_STACK_INSTALL
PGlazoved19b352020-05-21 16:42:27 +040079 shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size, dist_upgrade_nodes, upgrade_saltstack)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030080 } else {
81 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
82 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030083 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030084
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030085 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030086
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030087 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030088 common.printMsg("Deploy is failed: " + e.message , "purple")
89 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030090 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030091 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030092 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030093 dos.py suspend ${ENV_NAME} || true
94 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030095 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030096 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
97 shared.run_cmd("""\
98 dos.py resume ${ENV_NAME} || true
99 """)
100 }
101 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +0300102 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300103 throw e
104 } finally {
105 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
106 }
107}
108
Dennis Dmitriev02447412019-04-17 18:02:46 +0300109def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300110 try {
111 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300112 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300113 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300114 } else {
115 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
116 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300117 }
118
119 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300120 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300121 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300122 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300123 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300124 dos.py suspend ${ENV_NAME} || true
125 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300126 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300127 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
128 shared.run_cmd("""\
129 dos.py resume ${ENV_NAME} || true
130 """)
131 }
132 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300133 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300134 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300135 }
136}
137
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300138
Hanna Arhipova0b6df822020-08-07 21:50:28 +0300139timeout(time: 23, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300140// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200141// Temporary disable throttle to check how it will run
142//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300143 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200144 env.slave_workdir = pwd()
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300145 try {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200146
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300147 // run deploy stages
PGlazoved19b352020-05-21 16:42:27 +0400148 deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300149 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300150 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300151 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300152 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300153 throw e
154 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300155 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300156 // shutdown the environment if required
157 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
158 shared.run_cmd("""\
159 dos.py destroy ${ENV_NAME} || true
160 """)
161 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300162 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300163
164 stage("Archive all xml reports") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200165 dir("${env.slave_workdir }") {
166 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
167 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300168 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300169
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400170 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300171 stage("report results to testrail from jenkins master") {
172 common.printMsg("Running on: " + node_with_reports, "blue")
173 common.printMsg("Running on: " + env.NODE_NAME, "blue")
174 shared.verbose_sh("""\
Hanna Arhipova01bd0322020-12-21 15:48:07 +0200175 [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv --python=python3.7 /home/jenkins/venv_testrail_reporter""", true, false, true)
Tatyana Leontovich43854972019-05-24 23:02:22 +0300176 shared.run_cmd("""\
Hanna Arhipova11092122020-01-28 20:07:49 +0200177 . /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 +0300178 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400179 }
180 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300181 if (fileExists("description.txt")) {
182 def String description = readFile("description.txt")
183 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300184 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400185 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300186 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300187
188 if (fileExists("jenkins_agent_description.txt")) {
189 // if there is a separated foundation node on $jenkins_slave_node_name,
190 // then archive artifacts also on that node
191 if (jenkins_slave_node_name != env.NODE_NAME) {
192 node ("${jenkins_slave_node_name}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200193 dir("${env.slave_workdir }") {
194 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
195 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300196 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200197 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
198 stage("report results to testrail") {
199 common.printMsg("Running on: " + node_with_reports, "blue")
200 shared.swarm_testrail_report(steps, node_with_reports)
201 }
202 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
203 if (fileExists("description.txt")) {
204 def String description = readFile("description.txt")
205 currentBuild.description += "${description}"
206 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300207 }
208 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200209 } //dir
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300210 } // node
211 }
212 }
213
Dennis Dmitriev27007322019-05-03 19:21:44 +0300214 } // try
215 } // node
216
217
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300218//}
219} // timeout