Hanna Arhipova | 31cb1d8 | 2021-01-27 09:41:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * DEPLOY_EMPTY_NODE Add extra node to heat stack. Node without a role and with salt-minion |
| 3 | */ |
| 4 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 5 | @Library('tcp-qa')_ |
| 6 | |
| 7 | def common = new com.mirantis.mk.Common() |
| 8 | def shared = new com.mirantis.system_qa.SharedPipeline() |
| 9 | def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 10 | def env_manager = env.ENV_MANAGER ?: 'devops' |
Hanna Arhipova | 6f49352 | 2019-12-25 04:23:28 +0200 | [diff] [blame] | 11 | def batch_size = env.BATCH_SIZE ?: '' |
Dmitriy Kruglov | 28b68d6 | 2020-02-12 02:27:25 +0100 | [diff] [blame] | 12 | def dist_upgrade_nodes = "${env.DIST_UPGRADE_NODES}" != "false" ? true : false |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 13 | def upgrade_saltstack = "${env.UPGRADE_SALTSTACK}" != "false" ? true : false |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 14 | |
| 15 | if (env_manager == 'devops') { |
| 16 | jenkins_slave_node_name = "${NODE_NAME}" |
Tatyana Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 17 | node_with_reports = "${NODE_NAME}" |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 18 | make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false |
| 19 | } else if (env_manager == 'heat') { |
| 20 | jenkins_slave_node_name = "openstack_slave_${JOB_NAME}" |
| 21 | make_snapshot_stages = false |
Tatyana Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 22 | node_with_reports = jenkins_slave_node_name |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 23 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 24 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 25 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>" |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 26 | |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 27 | def deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 28 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 29 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 30 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 31 | stage("Clean the environment and clone tcp-qa") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 32 | shared.prepare_working_dir(env_manager) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 33 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 34 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 35 | stage("Create environment, generate model, bootstrap the salt-cluster") { |
| 36 | // steps: "hardware,create_model,salt" |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 37 | if (env_manager == 'devops') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 38 | shared.swarm_bootstrap_salt_cluster_devops() |
| 39 | } else if (env_manager == 'heat') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 40 | // If shared.swarm_bootstrap_salt_cluster_heat() failed, |
| 41 | // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 42 | shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 43 | // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 44 | // disable dos.py snapshots for 'heat' manager |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 45 | } else { |
| 46 | throw new Exception("Unknow env_manager: '${env_manager}'") |
| 47 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 48 | |
| 49 | if (fileExists("jenkins_agent_description.txt")) { |
| 50 | def String jenkins_agent_description = readFile("jenkins_agent_description.txt") |
| 51 | currentBuild.description += "${jenkins_agent_description}" |
| 52 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 53 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 54 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 55 | stage("Install core infrastructure and deploy CICD nodes") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 56 | if (env.DRIVETRAIN_STACK_INSTALL) { |
| 57 | // steps: env.DRIVETRAIN_STACK_INSTALL |
PGlazov | d4b70a0 | 2020-05-26 13:28:59 +0400 | [diff] [blame] | 58 | 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 Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 59 | } else { |
| 60 | common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green") |
| 61 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 62 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 63 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 64 | stage("Deploy platform components") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 65 | if (env.PLATFORM_STACK_INSTALL) { |
| 66 | // steps: env.PLATFORM_STACK_INSTALL |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 67 | 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 Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 68 | } else { |
| 69 | common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green") |
| 70 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 71 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 72 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 73 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 74 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 75 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 76 | common.printMsg("Deploy is failed: " + e.message , "purple") |
| 77 | report_text = e.message |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 78 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 79 | def snapshot_name = "deploy_failed" |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 80 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 81 | dos.py suspend ${ENV_NAME} || true |
| 82 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 83 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 84 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 85 | shared.run_cmd("""\ |
| 86 | dos.py resume ${ENV_NAME} || true |
| 87 | """) |
| 88 | } |
| 89 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 90 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 91 | throw e |
| 92 | } finally { |
| 93 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 94 | } |
| 95 | } |
| 96 | |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 97 | def test(shared, common, steps, env_manager) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 98 | try { |
| 99 | stage("Run tests") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 100 | if (env.RUN_TEST_OPTS) { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 101 | shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 102 | } else { |
| 103 | common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green") |
| 104 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 108 | common.printMsg("Tests are failed: " + e.message, "purple") |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 109 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 110 | def snapshot_name = "tests_failed" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 111 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 112 | dos.py suspend ${ENV_NAME} || true |
| 113 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 114 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 115 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 116 | shared.run_cmd("""\ |
| 117 | dos.py resume ${ENV_NAME} || true |
| 118 | """) |
| 119 | } |
| 120 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 121 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 122 | throw e |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 126 | |
Hanna Arhipova | 0b6df82 | 2020-08-07 21:50:28 +0300 | [diff] [blame] | 127 | timeout(time: 23, unit: 'HOURS') { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 128 | // main |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 129 | // Temporary disable throttle to check how it will run |
| 130 | //throttle(['fuel_devops_environment']) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 131 | node ("${NODE_NAME}") { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 132 | env.slave_workdir = pwd() |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 133 | try { |
Hanna Arhipova | cd1bcdb | 2021-04-23 18:47:48 +0300 | [diff] [blame^] | 134 | if (env.IPMI_CREDS) { |
| 135 | withCredentials([ |
| 136 | [$class : 'UsernamePasswordMultiBinding', |
| 137 | credentialsId : "${IPMI_CREDS}", |
| 138 | passwordVariable: 'IPMI_PASS', |
| 139 | usernameVariable: 'IPMI_USER'] |
| 140 | ]) { |
| 141 | env.IPMI_PASS = IPMI_PASS |
| 142 | env.IPMI_USER = IPMI_USER |
| 143 | shared.reboot_hardware_nodes("${IPMI_CREDS}") |
| 144 | } |
| 145 | } |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 146 | |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 147 | // run deploy stages |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 148 | deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 149 | // run test stages |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 150 | test(shared, common, steps, env_manager) |
Hanna Arhipova | cd1bcdb | 2021-04-23 18:47:48 +0300 | [diff] [blame^] | 151 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 152 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 153 | common.printMsg("Job is failed: " + e.message, "purple") |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 154 | throw e |
| 155 | } finally { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 156 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 157 | // shutdown the environment if required |
| 158 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 159 | shared.run_cmd("""\ |
| 160 | dos.py destroy ${ENV_NAME} || true |
| 161 | """) |
| 162 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 163 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 164 | |
| 165 | stage("Archive all xml reports") { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 166 | dir("${env.slave_workdir }") { |
| 167 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 168 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 169 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 170 | |
Vladimir Jigulin | 91bb7c9 | 2019-04-04 18:15:45 +0400 | [diff] [blame] | 171 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
Tatyana Leontovich | 4385497 | 2019-05-24 23:02:22 +0300 | [diff] [blame] | 172 | stage("report results to testrail from jenkins master") { |
| 173 | common.printMsg("Running on: " + node_with_reports, "blue") |
| 174 | common.printMsg("Running on: " + env.NODE_NAME, "blue") |
| 175 | shared.verbose_sh("""\ |
Hanna Arhipova | 01bd032 | 2020-12-21 15:48:07 +0200 | [diff] [blame] | 176 | [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv --python=python3.7 /home/jenkins/venv_testrail_reporter""", true, false, true) |
Tatyana Leontovich | 4385497 | 2019-05-24 23:02:22 +0300 | [diff] [blame] | 177 | shared.run_cmd("""\ |
Hanna Arhipova | 1109212 | 2020-01-28 20:07:49 +0200 | [diff] [blame] | 178 | . /home/jenkins/venv_testrail_reporter/bin/activate; pip install git+https://github.com/dis-xcom/testrail_reporter -U""") |
Tatyana Leontovich | 4385497 | 2019-05-24 23:02:22 +0300 | [diff] [blame] | 179 | shared.swarm_testrail_report(steps, env.NODE_NAME) |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 180 | } |
| 181 | stage("Store TestRail reports to job description") { |
Dennis Dmitriev | 239db4e | 2019-05-27 16:13:31 +0300 | [diff] [blame] | 182 | if (fileExists("description.txt")) { |
| 183 | def String description = readFile("description.txt") |
| 184 | currentBuild.description += "${description}" |
Tatyana Leontovich | 6cce9d6 | 2019-05-24 19:43:07 +0300 | [diff] [blame] | 185 | } |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 186 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 187 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 188 | |
| 189 | if (fileExists("jenkins_agent_description.txt")) { |
| 190 | // if there is a separated foundation node on $jenkins_slave_node_name, |
| 191 | // then archive artifacts also on that node |
| 192 | if (jenkins_slave_node_name != env.NODE_NAME) { |
| 193 | node ("${jenkins_slave_node_name}") { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 194 | dir("${env.slave_workdir }") { |
| 195 | stage("Archive all xml reports from node ${jenkins_slave_node_name}") { |
| 196 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz,*.xml,*.ini,*.log,*.tar.gz", allowEmptyArchive: true |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 197 | } |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 198 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
| 199 | stage("report results to testrail") { |
| 200 | common.printMsg("Running on: " + node_with_reports, "blue") |
| 201 | shared.swarm_testrail_report(steps, node_with_reports) |
| 202 | } |
| 203 | stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") { |
| 204 | if (fileExists("description.txt")) { |
| 205 | def String description = readFile("description.txt") |
| 206 | currentBuild.description += "${description}" |
| 207 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 208 | } |
| 209 | } |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 210 | } //dir |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 211 | } // node |
| 212 | } |
| 213 | } |
| 214 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 215 | } // try |
| 216 | } // node |
| 217 | |
| 218 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 219 | //} |
| 220 | } // timeout |