blob: 002c4217b64afe4f5ae9b736e742ba121354c214 [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
Pavel Glazov40cfda32023-03-22 02:54:47 +040014def upgrade_version_tag = "${env.UPGRADE_VERSION_TAG}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030015
16if (env_manager == 'devops') {
17 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030018 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030019 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
20} else if (env_manager == 'heat') {
Anna Arhipova76b1f932022-08-05 10:07:32 +020021 jenkins_slave_node_name = "openstack_slave_${env.ENV_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030022 make_snapshot_stages = false
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030023 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030024}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030025
Dennis Dmitriev27007322019-05-03 19:21:44 +030026currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030027
PGlazoved19b352020-05-21 16:42:27 +040028def deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030029 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030030 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030031
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030032 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030033 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030034 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030035
Hanna Arhipova50bd7722021-05-14 14:13:46 +030036 if (env.IPMI_CREDS) {
37 withCredentials([
38 [$class : 'UsernamePasswordMultiBinding',
39 credentialsId : "${IPMI_CREDS}",
40 passwordVariable: 'IPMI_PASS',
41 usernameVariable: 'IPMI_USER']
42 ]) {
43 env.IPMI_PASS = IPMI_PASS
44 env.IPMI_USER = IPMI_USER
45 shared.reboot_hardware_nodes("${IPMI_CREDS}")
46 }
47 }
48
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030049 stage("Create environment, generate model, bootstrap the salt-cluster") {
50 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030051 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030052 shared.swarm_bootstrap_salt_cluster_devops()
53 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030054 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
55 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030056 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030057 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030058 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030059 } else {
60 throw new Exception("Unknow env_manager: '${env_manager}'")
61 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030062
63 if (fileExists("jenkins_agent_description.txt")) {
64 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
65 currentBuild.description += "${jenkins_agent_description}"
66 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030067 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030068
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030069 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030070 if (env.DRIVETRAIN_STACK_INSTALL) {
71 // steps: env.DRIVETRAIN_STACK_INSTALL
PGlazovd4b70a02020-05-26 13:28:59 +040072 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 +030073 } else {
74 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
75 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030076 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030077
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030078 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030079 if (env.PLATFORM_STACK_INSTALL) {
80 // steps: env.PLATFORM_STACK_INSTALL
PGlazoved19b352020-05-21 16:42:27 +040081 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 +030082 } else {
83 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
84 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030085 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030086
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030087 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030088
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030089 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030090 common.printMsg("Deploy is failed: " + e.message , "purple")
91 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030092 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030093 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030094 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030095 dos.py suspend ${ENV_NAME} || true
96 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030097 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030098 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
99 shared.run_cmd("""\
100 dos.py resume ${ENV_NAME} || true
101 """)
102 }
103 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +0300104 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300105 throw e
106 } finally {
107 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
108 }
109}
110
Dennis Dmitriev02447412019-04-17 18:02:46 +0300111def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300112 try {
113 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300114 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300115 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300116 } else {
117 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
118 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300119 }
120
121 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300122 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300123 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300124 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300125 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300126 dos.py suspend ${ENV_NAME} || true
127 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300128 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300129 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
130 shared.run_cmd("""\
131 dos.py resume ${ENV_NAME} || true
132 """)
133 }
134 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300135 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300136 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300137 }
138}
139
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300140
Hanna Arhipova0b6df822020-08-07 21:50:28 +0300141timeout(time: 23, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300142// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200143// Temporary disable throttle to check how it will run
144//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300145 node ("${NODE_NAME}") {
Hanna Arhipova4d493622020-02-06 18:14:46 +0200146 env.slave_workdir = pwd()
dtsapikov60679892022-11-16 17:01:16 +0400147 def extra_vars = EXTRA_VARS ?: ''
148 if (extra_vars != '') {
149 extra_vars = extra_vars.split('\n').collect{it as String}
150 }
151 else {
152 extra_vars = []
153 }
154 withEnv(extra_vars) {
155 try {
156 // run deploy stages
157 deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack)
158 // run test stages
159 test(shared, common, steps, env_manager)
160 } catch (e) {
161 common.printMsg("Job is failed: " + e.message, "purple")
162 throw e
163 } finally {
164 if (make_snapshot_stages) {
165 // shutdown the environment if required
166 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
167 shared.run_cmd("""\
168 dos.py destroy ${ENV_NAME} || true
169 """)
170 }
171 }
172
173 stage("Archive all xml reports") {
174 dir("${env.slave_workdir }") {
175 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
176 }
177 }
178 // delete directory with artifacts from swarm-run-pytest pipeline
179 // for excluding xml duplicates
180 if (fileExists("tmp")) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300181 shared.run_cmd("""\
dtsapikov60679892022-11-16 17:01:16 +0400182 rm -rf tmp/
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300183 """)
184 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300185
dtsapikov60679892022-11-16 17:01:16 +0400186 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
187 stage("report results to testrail from jenkins master") {
188 common.printMsg("Running on: " + node_with_reports, "blue")
189 common.printMsg("Running on: " + env.NODE_NAME, "blue")
190 shared.swarm_testrail_report(steps, env.NODE_NAME)
Hanna Arhipova4d493622020-02-06 18:14:46 +0200191 }
dtsapikov60679892022-11-16 17:01:16 +0400192 stage("Store TestRail reports to job description") {
193 if (fileExists("description.txt")) {
194 def String description = readFile("description.txt")
195 currentBuild.description += "${description}"
196 }
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300197 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400198 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300199
dtsapikov60679892022-11-16 17:01:16 +0400200 if (fileExists("jenkins_agent_description.txt")) {
201 // if there is a separated foundation node on $jenkins_slave_node_name,
202 // then archive artifacts also on that node
203 if (jenkins_slave_node_name != env.NODE_NAME) {
204 node ("${jenkins_slave_node_name}") {
205 dir("${env.slave_workdir }") {
206 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
207 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true
Hanna Arhipova4d493622020-02-06 18:14:46 +0200208 }
dtsapikov60679892022-11-16 17:01:16 +0400209 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
210 stage("report results to testrail") {
211 common.printMsg("Running on: " + node_with_reports, "blue")
212 shared.swarm_testrail_report(steps, node_with_reports)
213 }
214 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
215 if (fileExists("description.txt")) {
216 def String description = readFile("description.txt")
217 currentBuild.description += "${description}"
218 }
Hanna Arhipova4d493622020-02-06 18:14:46 +0200219 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300220 }
dtsapikov60679892022-11-16 17:01:16 +0400221 } //dir
222 } // node
223 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300224 }
Pavel Glazovaf7d1992023-03-23 14:58:01 +0400225 //run upgrade pike to queens only for pike proposed
226 if (env.AUTO_UPGRADE_TO_QUEENS == "true" && currentBuild.result == 'SUCCESS') {
227 def deploy = build job: "os-update-pike-to-queens",
228 parameters: [
229 string(name: 'PARENT_NODE_NAME', value: "openstack_slave_${env.ENV_NAME}"),
230 string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS),
231 string(name: 'PASSED_STEPS', value: steps),
232 string(name: 'TEMPEST_TEST_SUITE_NAME', value: env.TEMPEST_TEST_SUITE_NAME),
233 string(name: 'NODE', value: "openstack_slave_${env.ENV_NAME}"),
234 string(name: 'RUN_TEST_OPTS', value: '-k TestUpdatePikeToQueens')
235 ],
236 wait: false,
237 propagate: false
238 }
dtsapikov60679892022-11-16 17:01:16 +0400239 //run upgrade env to proposed
240 if (env.RUN_UPGRADE_AFTER_JOB == "true" && currentBuild.result == 'SUCCESS') {
241 network_backend = env.PLATFORM_STACK_INSTALL.contains("contrail") ? 'contrail' : 'dvr'
242 upgrade_job = "mcp-update-${env.TEMPEST_IMAGE_VERSION}-${network_backend}-sl"
243 upgrade_to_tag = ''
244 contrail_upgrade_line = ''
245 if(env.UPGRADE_TO_TAG == "true") {
Pavel Glazov40cfda32023-03-22 02:54:47 +0400246 upgrade_to_tag = "--update-to-tag ${upgrade_version_tag} "
dtsapikov60679892022-11-16 17:01:16 +0400247 }
248 if(env.PLATFORM_STACK_INSTALL.contains("contrail")) {
249 contrail_upgrade_line = "tcp_tests/tests/system/test_upgrade_contrail.py::TestUpdateContrail "
250 }
251 run_test_opts = """--keep-duplicates --maxfail=1 \
252 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_drivetrain ${upgrade_to_tag} \
253 ${contrail_upgrade_line}\
254 tcp_tests/tests/system/test_mcp_update.py::TestOpenstackUpdate \
255 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_galera --update-mysql-version 5.7 \
256 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_rabbit \
257 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_stacklight \
258 tcp_tests/tests/system/test_mcp_update.py::TestUpdateMcpCluster::test_update_ceph \
259 \
260 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_tempest \
261 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_func_sanity \
262 tcp_tests/tests/system/test_cvp_pipelines.py::TestCvpPipelines::test_run_cvp_stacklight
263 """
264 if (env.IPMI_CREDS) {
Pavel Glazovb4b7c532024-05-22 15:13:48 +0400265 if (env.ENV_NAME == "released-bm-b300-cicd-queens-ovs-maas") {
266 upgrade_job = "mcp-update-bm-b300-queens-ovs-maas"
267 }
268 if (env.ENV_NAME == "released-bm-cicd-queens-ovs-cl-maas") {
269 upgrade_job = "mcp-update-bm-queens-ovs-cl-maas"
270 }
dtsapikov60679892022-11-16 17:01:16 +0400271 }
272 def deploy = build job: "${upgrade_job}",
273 parameters: [
274 string(name: 'PARENT_NODE_NAME', value: "openstack_slave_${env.ENV_NAME}"),
275 string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS),
276 string(name: 'PASSED_STEPS', value: steps),
277 string(name: 'TEMPEST_TEST_SUITE_NAME', value: env.TEMPEST_TEST_SUITE_NAME),
278 string(name: 'NODE', value: "openstack_slave_${env.ENV_NAME}"),
279 string(name: 'RUN_TEST_OPTS', value: run_test_opts)
280 ],
281 wait: false,
282 propagate: false
Anna Arhipova5d936b82022-08-05 10:07:32 +0200283 }
dtsapikov60679892022-11-16 17:01:16 +0400284 } // try
285 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300286 } // node
287
288
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300289//}
290} // timeout