blob: 7262caab394a4d424202fa162b209c3657a3473e [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
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030031 stage("Create environment, generate model, bootstrap the salt-cluster") {
32 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030033 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030034 shared.swarm_bootstrap_salt_cluster_devops()
35 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030036 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
37 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030038 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030039 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030040 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030041 } else {
42 throw new Exception("Unknow env_manager: '${env_manager}'")
43 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030044
45 if (fileExists("jenkins_agent_description.txt")) {
46 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
47 currentBuild.description += "${jenkins_agent_description}"
48 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030049 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030050
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030051 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030052 if (env.DRIVETRAIN_STACK_INSTALL) {
53 // steps: env.DRIVETRAIN_STACK_INSTALL
PGlazovd4b70a02020-05-26 13:28:59 +040054 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 +030055 } else {
56 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
57 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030058 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030059
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030060 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030061 if (env.PLATFORM_STACK_INSTALL) {
62 // steps: env.PLATFORM_STACK_INSTALL
PGlazoved19b352020-05-21 16:42:27 +040063 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 +030064 } else {
65 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
66 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030067 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030068
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030069 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030070
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030071 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030072 common.printMsg("Deploy is failed: " + e.message , "purple")
73 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030074 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030075 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030076 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030077 dos.py suspend ${ENV_NAME} || true
78 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030079 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030080 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
81 shared.run_cmd("""\
82 dos.py resume ${ENV_NAME} || true
83 """)
84 }
85 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030086 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030087 throw e
88 } finally {
89 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
90 }
91}
92
Dennis Dmitriev02447412019-04-17 18:02:46 +030093def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030094 try {
95 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030096 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030097 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030098 } else {
99 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
100 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300101 }
102
103 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300104 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300105 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300106 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300107 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300108 dos.py suspend ${ENV_NAME} || true
109 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300110 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300111 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
112 shared.run_cmd("""\
113 dos.py resume ${ENV_NAME} || true
114 """)
115 }
116 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300117 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300118 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300119 }
120}
121
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300122
Hanna Arhipova0b6df822020-08-07 21:50:28 +0300123timeout(time: 23, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300124// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200125// Temporary disable throttle to check how it will run
126//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300127 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200128 env.slave_workdir = pwd()
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300129 try {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200130
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300131 // run deploy stages
PGlazoved19b352020-05-21 16:42:27 +0400132 deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300133 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300134 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300135 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300136 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300137 throw e
138 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300139 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300140 // shutdown the environment if required
141 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
142 shared.run_cmd("""\
143 dos.py destroy ${ENV_NAME} || true
144 """)
145 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300146 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300147
148 stage("Archive all xml reports") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200149 dir("${env.slave_workdir }") {
150 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
151 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300152 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300153
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400154 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300155 stage("report results to testrail from jenkins master") {
156 common.printMsg("Running on: " + node_with_reports, "blue")
157 common.printMsg("Running on: " + env.NODE_NAME, "blue")
158 shared.verbose_sh("""\
159 [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter""", true, false, true)
160 shared.run_cmd("""\
Hanna Arhipova11092122020-01-28 20:07:49 +0200161 . /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 +0300162 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400163 }
164 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300165 if (fileExists("description.txt")) {
166 def String description = readFile("description.txt")
167 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300168 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400169 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300170 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300171
172 if (fileExists("jenkins_agent_description.txt")) {
173 // if there is a separated foundation node on $jenkins_slave_node_name,
174 // then archive artifacts also on that node
175 if (jenkins_slave_node_name != env.NODE_NAME) {
176 node ("${jenkins_slave_node_name}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200177 dir("${env.slave_workdir }") {
178 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
179 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300180 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200181 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
182 stage("report results to testrail") {
183 common.printMsg("Running on: " + node_with_reports, "blue")
184 shared.swarm_testrail_report(steps, node_with_reports)
185 }
186 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
187 if (fileExists("description.txt")) {
188 def String description = readFile("description.txt")
189 currentBuild.description += "${description}"
190 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300191 }
192 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200193 } //dir
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300194 } // node
195 }
196 }
197
Dennis Dmitriev27007322019-05-03 19:21:44 +0300198 } // try
199 } // node
200
201
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300202//}
203} // timeout