blob: 56a2d9b71bded9324337dbd9e42ea56ab3c57ad5 [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
Dennis Dmitriev02447412019-04-17 18:02:46 +03009
10if (env_manager == 'devops') {
11 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030012 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030013 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
14} else if (env_manager == 'heat') {
15 jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
16 make_snapshot_stages = false
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030017 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030018}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030019
Dennis Dmitriev27007322019-05-03 19:21:44 +030020currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030021
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +010022def deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030023 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030024 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030025
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030026 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030027 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030028 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030029
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030030 stage("Create environment, generate model, bootstrap the salt-cluster") {
31 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030032 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030033 shared.swarm_bootstrap_salt_cluster_devops()
34 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030035 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
36 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030037 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030038 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030039 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030040 } else {
41 throw new Exception("Unknow env_manager: '${env_manager}'")
42 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030043
44 if (fileExists("jenkins_agent_description.txt")) {
45 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
46 currentBuild.description += "${jenkins_agent_description}"
47 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030048 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030049
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030050 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030051 if (env.DRIVETRAIN_STACK_INSTALL) {
52 // steps: env.DRIVETRAIN_STACK_INSTALL
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +010053 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)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030054 } else {
55 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
56 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030057 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030058
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030059 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030060 if (env.PLATFORM_STACK_INSTALL) {
61 // steps: env.PLATFORM_STACK_INSTALL
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +010062 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)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030063 } else {
64 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
65 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030066 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030067
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030068 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030069
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030070 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030071 common.printMsg("Deploy is failed: " + e.message , "purple")
72 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030073 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030074 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030075 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030076 dos.py suspend ${ENV_NAME} || true
77 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030078 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030079 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
80 shared.run_cmd("""\
81 dos.py resume ${ENV_NAME} || true
82 """)
83 }
84 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030085 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030086 throw e
87 } finally {
88 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
89 }
90}
91
Dennis Dmitriev02447412019-04-17 18:02:46 +030092def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030093 try {
94 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030095 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030096 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030097 } else {
98 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
99 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300100 }
101
102 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300103 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300104 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300105 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300106 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300107 dos.py suspend ${ENV_NAME} || true
108 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300109 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300110 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
111 shared.run_cmd("""\
112 dos.py resume ${ENV_NAME} || true
113 """)
114 }
115 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300116 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300117 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300118 }
119}
120
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300121
122timeout(time: 15, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300123// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200124// Temporary disable throttle to check how it will run
125//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300126 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200127 env.slave_workdir = pwd()
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300128 try {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200129
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300130 // run deploy stages
Dmitriy Kruglov758f99c2020-02-04 12:04:31 +0100131 deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300132 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300133 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300134 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300135 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300136 throw e
137 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300138 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300139 // shutdown the environment if required
140 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
141 shared.run_cmd("""\
142 dos.py destroy ${ENV_NAME} || true
143 """)
144 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300145 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300146
147 stage("Archive all xml reports") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200148 dir("${env.slave_workdir }") {
149 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
150 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300151 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300152
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400153 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300154 stage("report results to testrail from jenkins master") {
155 common.printMsg("Running on: " + node_with_reports, "blue")
156 common.printMsg("Running on: " + env.NODE_NAME, "blue")
157 shared.verbose_sh("""\
158 [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter""", true, false, true)
159 shared.run_cmd("""\
Hanna Arhipova11092122020-01-28 20:07:49 +0200160 . /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 +0300161 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400162 }
163 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300164 if (fileExists("description.txt")) {
165 def String description = readFile("description.txt")
166 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300167 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400168 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300169 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300170
171 if (fileExists("jenkins_agent_description.txt")) {
172 // if there is a separated foundation node on $jenkins_slave_node_name,
173 // then archive artifacts also on that node
174 if (jenkins_slave_node_name != env.NODE_NAME) {
175 node ("${jenkins_slave_node_name}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200176 dir("${env.slave_workdir }") {
177 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
178 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300179 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200180 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
181 stage("report results to testrail") {
182 common.printMsg("Running on: " + node_with_reports, "blue")
183 shared.swarm_testrail_report(steps, node_with_reports)
184 }
185 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
186 if (fileExists("description.txt")) {
187 def String description = readFile("description.txt")
188 currentBuild.description += "${description}"
189 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300190 }
191 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200192 } //dir
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300193 } // node
194 }
195 }
196
Dennis Dmitriev27007322019-05-03 19:21:44 +0300197 } // try
198 } // node
199
200
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300201//}
202} // timeout