blob: 769d5767ea24f7de977aea152a4cc25fbb0f5548 [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') {
Anna Arhipova76b1f932022-08-05 10:07:32 +020020 jenkins_slave_node_name = "openstack_slave_${env.ENV_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030021 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 Arhipova50bd7722021-05-14 14:13:46 +030035 if (env.IPMI_CREDS) {
36 withCredentials([
37 [$class : 'UsernamePasswordMultiBinding',
38 credentialsId : "${IPMI_CREDS}",
39 passwordVariable: 'IPMI_PASS',
40 usernameVariable: 'IPMI_USER']
41 ]) {
42 env.IPMI_PASS = IPMI_PASS
43 env.IPMI_USER = IPMI_USER
44 shared.reboot_hardware_nodes("${IPMI_CREDS}")
45 }
46 }
47
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030048 stage("Create environment, generate model, bootstrap the salt-cluster") {
49 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030050 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030051 shared.swarm_bootstrap_salt_cluster_devops()
52 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030053 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
54 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030055 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030056 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030057 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030058 } else {
59 throw new Exception("Unknow env_manager: '${env_manager}'")
60 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030061
62 if (fileExists("jenkins_agent_description.txt")) {
63 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
64 currentBuild.description += "${jenkins_agent_description}"
65 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030066 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030067
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030068 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030069 if (env.DRIVETRAIN_STACK_INSTALL) {
70 // steps: env.DRIVETRAIN_STACK_INSTALL
PGlazovd4b70a02020-05-26 13:28:59 +040071 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 +030072 } else {
73 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
74 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030075 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030076
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030077 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030078 if (env.PLATFORM_STACK_INSTALL) {
79 // steps: env.PLATFORM_STACK_INSTALL
PGlazoved19b352020-05-21 16:42:27 +040080 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 +030081 } else {
82 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
83 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030084 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030085
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030086 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030087
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030088 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030089 common.printMsg("Deploy is failed: " + e.message , "purple")
90 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030091 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030092 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030093 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030094 dos.py suspend ${ENV_NAME} || true
95 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030096 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030097 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
98 shared.run_cmd("""\
99 dos.py resume ${ENV_NAME} || true
100 """)
101 }
102 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +0300103 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300104 throw e
105 } finally {
106 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
107 }
108}
109
Dennis Dmitriev02447412019-04-17 18:02:46 +0300110def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300111 try {
112 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300113 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300114 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300115 } else {
116 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
117 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300118 }
119
120 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300121 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300122 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300123 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300124 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300125 dos.py suspend ${ENV_NAME} || true
126 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300127 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300128 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
129 shared.run_cmd("""\
130 dos.py resume ${ENV_NAME} || true
131 """)
132 }
133 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300134 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300135 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300136 }
137}
138
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300139
Hanna Arhipova0b6df822020-08-07 21:50:28 +0300140timeout(time: 23, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300141// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200142// Temporary disable throttle to check how it will run
143//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300144 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200145 env.slave_workdir = pwd()
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300146 try {
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 }
dtsapikovd81c7ae2022-01-18 16:16:02 +0400169 // delete directory with artifacts from swarm-run-pytest pipeline
170 // for excluding xml duplicates
171 if (fileExists("tmp")) {
172 shared.run_cmd("""\
173 rm -rf tmp/
174 """)
175 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300176
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400177 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300178 stage("report results to testrail from jenkins master") {
179 common.printMsg("Running on: " + node_with_reports, "blue")
180 common.printMsg("Running on: " + env.NODE_NAME, "blue")
Tatyana Leontovich43854972019-05-24 23:02:22 +0300181 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400182 }
183 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300184 if (fileExists("description.txt")) {
185 def String description = readFile("description.txt")
186 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300187 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400188 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300189 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300190
191 if (fileExists("jenkins_agent_description.txt")) {
192 // if there is a separated foundation node on $jenkins_slave_node_name,
193 // then archive artifacts also on that node
194 if (jenkins_slave_node_name != env.NODE_NAME) {
195 node ("${jenkins_slave_node_name}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200196 dir("${env.slave_workdir }") {
197 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
198 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300199 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200200 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
201 stage("report results to testrail") {
202 common.printMsg("Running on: " + node_with_reports, "blue")
203 shared.swarm_testrail_report(steps, node_with_reports)
204 }
205 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
206 if (fileExists("description.txt")) {
207 def String description = readFile("description.txt")
208 currentBuild.description += "${description}"
209 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300210 }
211 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200212 } //dir
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300213 } // node
214 }
215 }
PGlazov94c26b92021-08-09 16:33:58 +0400216 //run upgrade env to proposed
PGlazov560be2c2021-10-18 20:43:58 +0400217 if (env.RUN_UPGRADE_AFTER_JOB == "true" && currentBuild.result == 'SUCCESS') {
PGlazov94c26b92021-08-09 16:33:58 +0400218 network_backend = env.PLATFORM_STACK_INSTALL.contains("contrail") ? 'contrail' : 'dvr'
219 upgrade_job = "mcp-update-${env.TEMPEST_IMAGE_VERSION}-${network_backend}-sl"
Anna Arhipova5d936b82022-08-05 10:07:32 +0200220 upgrade_to_tag = ''
221 contrail_upgrade_line = ''
222 if(env.UPGRADE_TO_TAG == "true") {
223 upgrade_to_tag = '--update-to-tag ${env.UPGRADE_VERSION_TAG} '
224 }
Pavel Glazovf9a4b552022-08-10 12:20:06 +0400225 if(env.PLATFORM_STACK_INSTALL.contains("contrail")) {
Anna Arhipova5d936b82022-08-05 10:07:32 +0200226 contrail_upgrade_line = "tcp_tests/tests/system/test_upgrade_contrail.py::TestUpdateContrail "
227 }
228 run_test_opts = """--keep-duplicates --maxfail=1 \
229 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_drivetrain ${upgrade_to_tag} \
230 ${contrail_upgrade_line}\
231 tcp_tests/tests/system/test_mcp_update.py::TestOpenstackUpdate \
232 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_galera --update-mysql-version 5.7 \
233 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_rabbit \
234 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_stacklight \
235 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_ceph \
236 \
237 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_tempest \
238 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_func_sanity \
239 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_stacklight
240 """
PGlazov3a9f3332021-11-23 15:40:00 +0400241 if (env.IPMI_CREDS) {
242 upgrade_job = "mcp-update-bm-b300-queens-ovs-maas"
243 }
244 def deploy = build job: "${upgrade_job}",
245 parameters: [
Anna Arhipova76b1f932022-08-05 10:07:32 +0200246 string(name: 'PARENT_NODE_NAME', value: "openstack_slave_${env.ENV_NAME}"),
PGlazov3a9f3332021-11-23 15:40:00 +0400247 string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS),
248 string(name: 'PASSED_STEPS', value: steps),
249 string(name: 'TEMPEST_TEST_SUITE_NAME', value: env.TEMPEST_TEST_SUITE_NAME),
Pavel Glazovf9a4b552022-08-10 12:20:06 +0400250 string(name: 'NODE', value: "openstack_slave_${env.ENV_NAME}"),
Anna Arhipova5d936b82022-08-05 10:07:32 +0200251 string(name: 'RUN_TEST_OPTS', value: run_test_opts)
PGlazov3a9f3332021-11-23 15:40:00 +0400252 ],
253 wait: false,
254 propagate: false
PGlazov94c26b92021-08-09 16:33:58 +0400255 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300256 } // try
257 } // node
258
259
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300260//}
261} // timeout