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