Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 1 | @Library('tcp-qa')_ |
| 2 | |
| 3 | def common = new com.mirantis.mk.Common() |
| 4 | def shared = new com.mirantis.system_qa.SharedPipeline() |
| 5 | 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] | 6 | def env_manager = env.ENV_MANAGER ?: 'devops' |
Hanna Arhipova | 6f49352 | 2019-12-25 04:23:28 +0200 | [diff] [blame] | 7 | def batch_size = env.BATCH_SIZE ?: '' |
Dmitriy Kruglov | 28b68d6 | 2020-02-12 02:27:25 +0100 | [diff] [blame] | 8 | def dist_upgrade_nodes = "${env.DIST_UPGRADE_NODES}" != "false" ? true : false |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 9 | def upgrade_saltstack = "${env.UPGRADE_SALTSTACK}" != "false" ? true : false |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 10 | |
| 11 | if (env_manager == 'devops') { |
| 12 | jenkins_slave_node_name = "${NODE_NAME}" |
Tatyana Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 13 | node_with_reports = "${NODE_NAME}" |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 14 | 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 Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 18 | node_with_reports = jenkins_slave_node_name |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 19 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 20 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 21 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>" |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 22 | |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 23 | 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] | 24 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 25 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 26 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 27 | stage("Clean the environment and clone tcp-qa") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 28 | shared.prepare_working_dir(env_manager) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 29 | } |
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("Create environment, generate model, bootstrap the salt-cluster") { |
| 32 | // steps: "hardware,create_model,salt" |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 33 | if (env_manager == 'devops') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 34 | shared.swarm_bootstrap_salt_cluster_devops() |
| 35 | } else if (env_manager == 'heat') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 36 | // If shared.swarm_bootstrap_salt_cluster_heat() failed, |
| 37 | // 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] | 38 | shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 39 | // 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] | 40 | // disable dos.py snapshots for 'heat' manager |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 41 | } else { |
| 42 | throw new Exception("Unknow env_manager: '${env_manager}'") |
| 43 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 44 | |
| 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 Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 49 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 50 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 51 | stage("Install core infrastructure and deploy CICD nodes") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 52 | if (env.DRIVETRAIN_STACK_INSTALL) { |
| 53 | // steps: env.DRIVETRAIN_STACK_INSTALL |
PGlazov | d4b70a0 | 2020-05-26 13:28:59 +0400 | [diff] [blame] | 54 | 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] | 55 | } else { |
| 56 | common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green") |
| 57 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 58 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 59 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 60 | stage("Deploy platform components") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 61 | if (env.PLATFORM_STACK_INSTALL) { |
| 62 | // steps: env.PLATFORM_STACK_INSTALL |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 63 | 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] | 64 | } else { |
| 65 | common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green") |
| 66 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 67 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 68 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 69 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 70 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 71 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 72 | common.printMsg("Deploy is failed: " + e.message , "purple") |
| 73 | report_text = e.message |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 74 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 75 | def snapshot_name = "deploy_failed" |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 76 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 77 | dos.py suspend ${ENV_NAME} || true |
| 78 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 79 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 80 | 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 Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 86 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 87 | throw e |
| 88 | } finally { |
| 89 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 90 | } |
| 91 | } |
| 92 | |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 93 | def test(shared, common, steps, env_manager) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 94 | try { |
| 95 | stage("Run tests") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 96 | if (env.RUN_TEST_OPTS) { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 97 | shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 98 | } else { |
| 99 | common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green") |
| 100 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 104 | common.printMsg("Tests are failed: " + e.message, "purple") |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 105 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 106 | def snapshot_name = "tests_failed" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 107 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 108 | dos.py suspend ${ENV_NAME} || true |
| 109 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 110 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 111 | 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 Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 117 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 118 | throw e |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 122 | |
Hanna Arhipova | 0b6df82 | 2020-08-07 21:50:28 +0300 | [diff] [blame^] | 123 | timeout(time: 23, unit: 'HOURS') { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 124 | // main |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 125 | // Temporary disable throttle to check how it will run |
| 126 | //throttle(['fuel_devops_environment']) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 127 | node ("${NODE_NAME}") { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 128 | env.slave_workdir = pwd() |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 129 | try { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 130 | |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 131 | // run deploy stages |
PGlazov | ed19b35 | 2020-05-21 16:42:27 +0400 | [diff] [blame] | 132 | 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] | 133 | // run test stages |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 134 | test(shared, common, steps, env_manager) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 135 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 136 | common.printMsg("Job is failed: " + e.message, "purple") |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 137 | throw e |
| 138 | } finally { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 139 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 140 | // 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 Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 146 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 147 | |
| 148 | stage("Archive all xml reports") { |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 149 | dir("${env.slave_workdir }") { |
| 150 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 151 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 152 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 153 | |
Vladimir Jigulin | 91bb7c9 | 2019-04-04 18:15:45 +0400 | [diff] [blame] | 154 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
Tatyana Leontovich | 4385497 | 2019-05-24 23:02:22 +0300 | [diff] [blame] | 155 | 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 Arhipova | 1109212 | 2020-01-28 20:07:49 +0200 | [diff] [blame] | 161 | . /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] | 162 | shared.swarm_testrail_report(steps, env.NODE_NAME) |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 163 | } |
| 164 | stage("Store TestRail reports to job description") { |
Dennis Dmitriev | 239db4e | 2019-05-27 16:13:31 +0300 | [diff] [blame] | 165 | if (fileExists("description.txt")) { |
| 166 | def String description = readFile("description.txt") |
| 167 | currentBuild.description += "${description}" |
Tatyana Leontovich | 6cce9d6 | 2019-05-24 19:43:07 +0300 | [diff] [blame] | 168 | } |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 169 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 170 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 171 | |
| 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 Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 177 | 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 Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 180 | } |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 181 | 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 Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 191 | } |
| 192 | } |
Hanna Arhipova | 4d49362 | 2020-02-06 18:14:46 +0200 | [diff] [blame] | 193 | } //dir |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 194 | } // node |
| 195 | } |
| 196 | } |
| 197 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 198 | } // try |
| 199 | } // node |
| 200 | |
| 201 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 202 | //} |
| 203 | } // timeout |