blob: 07684cf2779e88c1200f435e8092e04035c2227c [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 ?: ''
Dmitriy Kruglov28b68d62020-02-12 02:27:25 +01008def dist_upgrade_nodes = "${env.DIST_UPGRADE_NODES}" != "false" ? true : false
PGlazoved19b352020-05-21 16:42:27 +04009def upgrade_saltstack = "${env.UPGRADE_SALTSTACK}" != "false" ? true : false
Dennis Dmitriev02447412019-04-17 18:02:46 +030010
11if (env_manager == 'devops') {
12 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030013 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030014 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
15} else if (env_manager == 'heat') {
16 jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
17 make_snapshot_stages = false
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030018 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030019}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030020
Dennis Dmitriev27007322019-05-03 19:21:44 +030021currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030022
PGlazoved19b352020-05-21 16:42:27 +040023def deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030024 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030025 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030026
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030027 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030028 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030029 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030030
Hanna Arhipova3be50622021-01-11 13:11:45 +020031 // Reboot Hardware before the BM deployments
32 if ("$ENV_NAME".contains("bm-")){
33 reboot_hw_nodes = env.REBOOT_HW_NODES ?: false
34 stage("Reboot HW nodes") {
35 if (reboot_hw_nodes) {
36 shared.reboot_hardware_nodes()
37 } else {
38 common.printMsg("REBOOT_HW_NODES is disabled. Skipping this stage...", "blue")
39 }
40 }
41 }
42
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030043 stage("Create environment, generate model, bootstrap the salt-cluster") {
44 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030045 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030046 shared.swarm_bootstrap_salt_cluster_devops()
47 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030048 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
49 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030050 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030051 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030052 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030053 } else {
54 throw new Exception("Unknow env_manager: '${env_manager}'")
55 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030056
57 if (fileExists("jenkins_agent_description.txt")) {
58 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
59 currentBuild.description += "${jenkins_agent_description}"
60 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030061 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030062
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030063 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030064 if (env.DRIVETRAIN_STACK_INSTALL) {
65 // steps: env.DRIVETRAIN_STACK_INSTALL
PGlazovd4b70a02020-05-26 13:28:59 +040066 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 +030067 } else {
68 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
69 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030070 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030071
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030072 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030073 if (env.PLATFORM_STACK_INSTALL) {
74 // steps: env.PLATFORM_STACK_INSTALL
PGlazoved19b352020-05-21 16:42:27 +040075 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 +030076 } else {
77 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
78 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030079 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030080
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030081 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030082
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030083 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030084 common.printMsg("Deploy is failed: " + e.message , "purple")
85 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030086 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030087 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030088 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030089 dos.py suspend ${ENV_NAME} || true
90 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030091 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030092 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
93 shared.run_cmd("""\
94 dos.py resume ${ENV_NAME} || true
95 """)
96 }
97 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030098 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030099 throw e
100 } finally {
101 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
102 }
103}
104
Dennis Dmitriev02447412019-04-17 18:02:46 +0300105def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300106 try {
107 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300108 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300109 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300110 } else {
111 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
112 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300113 }
114
115 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300116 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300117 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300118 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300119 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300120 dos.py suspend ${ENV_NAME} || true
121 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300122 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300123 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
124 shared.run_cmd("""\
125 dos.py resume ${ENV_NAME} || true
126 """)
127 }
128 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300129 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300130 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300131 }
132}
133
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300134
Hanna Arhipova0b6df822020-08-07 21:50:28 +0300135timeout(time: 23, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300136// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200137// Temporary disable throttle to check how it will run
138//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300139 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200140 env.slave_workdir = pwd()
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300141 try {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200142
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300143 // run deploy stages
PGlazoved19b352020-05-21 16:42:27 +0400144 deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300145 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300146 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300147 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300148 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300149 throw e
150 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300151 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300152 // shutdown the environment if required
153 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
154 shared.run_cmd("""\
155 dos.py destroy ${ENV_NAME} || true
156 """)
157 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300158 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300159
160 stage("Archive all xml reports") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200161 dir("${env.slave_workdir }") {
162 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
163 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300164 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300165
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400166 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300167 stage("report results to testrail from jenkins master") {
168 common.printMsg("Running on: " + node_with_reports, "blue")
169 common.printMsg("Running on: " + env.NODE_NAME, "blue")
170 shared.verbose_sh("""\
Hanna Arhipova01bd0322020-12-21 15:48:07 +0200171 [ -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 +0300172 shared.run_cmd("""\
Hanna Arhipova11092122020-01-28 20:07:49 +0200173 . /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 +0300174 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400175 }
176 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300177 if (fileExists("description.txt")) {
178 def String description = readFile("description.txt")
179 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300180 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400181 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300182 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300183
184 if (fileExists("jenkins_agent_description.txt")) {
185 // if there is a separated foundation node on $jenkins_slave_node_name,
186 // then archive artifacts also on that node
187 if (jenkins_slave_node_name != env.NODE_NAME) {
188 node ("${jenkins_slave_node_name}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200189 dir("${env.slave_workdir }") {
190 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
191 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300192 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200193 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
194 stage("report results to testrail") {
195 common.printMsg("Running on: " + node_with_reports, "blue")
196 shared.swarm_testrail_report(steps, node_with_reports)
197 }
198 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
199 if (fileExists("description.txt")) {
200 def String description = readFile("description.txt")
201 currentBuild.description += "${description}"
202 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300203 }
204 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200205 } //dir
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300206 } // node
207 }
208 }
209
Dennis Dmitriev27007322019-05-03 19:21:44 +0300210 } // try
211 } // node
212
213
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300214//}
215} // timeout