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 ?: '' |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 8 | |
| 9 | if (env_manager == 'devops') { |
| 10 | jenkins_slave_node_name = "${NODE_NAME}" |
Tatyana Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 11 | node_with_reports = "${NODE_NAME}" |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 12 | make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false |
| 13 | } else if (env_manager == 'heat') { |
| 14 | jenkins_slave_node_name = "openstack_slave_${JOB_NAME}" |
| 15 | make_snapshot_stages = false |
Tatyana Leontovich | c18c814 | 2019-05-16 15:20:33 +0300 | [diff] [blame] | 16 | node_with_reports = jenkins_slave_node_name |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 17 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 18 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 19 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>" |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 20 | |
Dmitriy Kruglov | 9d1cbb1 | 2020-01-07 10:42:41 +0100 | [diff] [blame] | 21 | def deploy(shared, common, steps, env_manager, batch_size) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 22 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 23 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 24 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 25 | stage("Clean the environment and clone tcp-qa") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 26 | shared.prepare_working_dir(env_manager) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 27 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 28 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 29 | stage("Create environment, generate model, bootstrap the salt-cluster") { |
| 30 | // steps: "hardware,create_model,salt" |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 31 | if (env_manager == 'devops') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 32 | shared.swarm_bootstrap_salt_cluster_devops() |
| 33 | } else if (env_manager == 'heat') { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 34 | // If shared.swarm_bootstrap_salt_cluster_heat() failed, |
| 35 | // 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] | 36 | shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 37 | // 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] | 38 | // disable dos.py snapshots for 'heat' manager |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 39 | } else { |
| 40 | throw new Exception("Unknow env_manager: '${env_manager}'") |
| 41 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 42 | |
| 43 | if (fileExists("jenkins_agent_description.txt")) { |
| 44 | def String jenkins_agent_description = readFile("jenkins_agent_description.txt") |
| 45 | currentBuild.description += "${jenkins_agent_description}" |
| 46 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 47 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 48 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 49 | stage("Install core infrastructure and deploy CICD nodes") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 50 | if (env.DRIVETRAIN_STACK_INSTALL) { |
| 51 | // steps: env.DRIVETRAIN_STACK_INSTALL |
Hanna Arhipova | 6f49352 | 2019-12-25 04:23:28 +0200 | [diff] [blame] | 52 | shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 53 | } else { |
| 54 | common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green") |
| 55 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 56 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 57 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 58 | stage("Deploy platform components") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 59 | if (env.PLATFORM_STACK_INSTALL) { |
| 60 | // steps: env.PLATFORM_STACK_INSTALL |
Hanna Arhipova | 6f49352 | 2019-12-25 04:23:28 +0200 | [diff] [blame] | 61 | shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages, batch_size) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 62 | } else { |
| 63 | common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green") |
| 64 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 65 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 66 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 67 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 68 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 69 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 70 | common.printMsg("Deploy is failed: " + e.message , "purple") |
| 71 | report_text = e.message |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 72 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 73 | def snapshot_name = "deploy_failed" |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 74 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 75 | dos.py suspend ${ENV_NAME} || true |
| 76 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 77 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 78 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 79 | shared.run_cmd("""\ |
| 80 | dos.py resume ${ENV_NAME} || true |
| 81 | """) |
| 82 | } |
| 83 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 84 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 85 | throw e |
| 86 | } finally { |
| 87 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 88 | } |
| 89 | } |
| 90 | |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 91 | def test(shared, common, steps, env_manager) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 92 | try { |
| 93 | stage("Run tests") { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 94 | if (env.RUN_TEST_OPTS) { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 95 | shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 96 | } else { |
| 97 | common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green") |
| 98 | } |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 102 | common.printMsg("Tests are failed: " + e.message, "purple") |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 103 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 104 | def snapshot_name = "tests_failed" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 105 | shared.run_cmd("""\ |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 106 | dos.py suspend ${ENV_NAME} || true |
| 107 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 108 | """) |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 109 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 110 | shared.run_cmd("""\ |
| 111 | dos.py resume ${ENV_NAME} || true |
| 112 | """) |
| 113 | } |
| 114 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 115 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 116 | throw e |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 120 | |
| 121 | timeout(time: 15, unit: 'HOURS') { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 122 | // main |
Tatyana Leontovich | bfbc483 | 2018-12-27 12:47:23 +0200 | [diff] [blame] | 123 | // Temporary disable throttle to check how it will run |
| 124 | //throttle(['fuel_devops_environment']) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 125 | node ("${NODE_NAME}") { |
| 126 | try { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 127 | // run deploy stages |
Dmitriy Kruglov | 9d1cbb1 | 2020-01-07 10:42:41 +0100 | [diff] [blame] | 128 | deploy(shared, common, steps, env_manager, batch_size) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 129 | // run test stages |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 130 | test(shared, common, steps, env_manager) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 131 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 132 | common.printMsg("Job is failed: " + e.message, "purple") |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 133 | throw e |
| 134 | } finally { |
Dennis Dmitriev | 0244741 | 2019-04-17 18:02:46 +0300 | [diff] [blame] | 135 | if (make_snapshot_stages) { |
Dennis Dmitriev | 4c38347 | 2019-04-12 13:58:06 +0300 | [diff] [blame] | 136 | // shutdown the environment if required |
| 137 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 138 | shared.run_cmd("""\ |
| 139 | dos.py destroy ${ENV_NAME} || true |
| 140 | """) |
| 141 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 142 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 143 | |
| 144 | stage("Archive all xml reports") { |
| 145 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 146 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 147 | |
Vladimir Jigulin | 91bb7c9 | 2019-04-04 18:15:45 +0400 | [diff] [blame] | 148 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
Tatyana Leontovich | 4385497 | 2019-05-24 23:02:22 +0300 | [diff] [blame] | 149 | stage("report results to testrail from jenkins master") { |
| 150 | common.printMsg("Running on: " + node_with_reports, "blue") |
| 151 | common.printMsg("Running on: " + env.NODE_NAME, "blue") |
| 152 | shared.verbose_sh("""\ |
| 153 | [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter""", true, false, true) |
| 154 | shared.run_cmd("""\ |
Hanna Arhipova | 1109212 | 2020-01-28 20:07:49 +0200 | [diff] [blame^] | 155 | . /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] | 156 | shared.swarm_testrail_report(steps, env.NODE_NAME) |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 157 | } |
| 158 | stage("Store TestRail reports to job description") { |
Dennis Dmitriev | 239db4e | 2019-05-27 16:13:31 +0300 | [diff] [blame] | 159 | if (fileExists("description.txt")) { |
| 160 | def String description = readFile("description.txt") |
| 161 | currentBuild.description += "${description}" |
Tatyana Leontovich | 6cce9d6 | 2019-05-24 19:43:07 +0300 | [diff] [blame] | 162 | } |
Vladimir Jigulin | b02dcc5 | 2019-04-02 15:57:53 +0400 | [diff] [blame] | 163 | } |
Sergey Galkin | da677fb | 2019-11-21 16:53:25 +0400 | [diff] [blame] | 164 | |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame] | 165 | } |
Dennis Dmitriev | fd0b78c | 2019-05-30 00:16:04 +0300 | [diff] [blame] | 166 | |
| 167 | if (fileExists("jenkins_agent_description.txt")) { |
| 168 | // if there is a separated foundation node on $jenkins_slave_node_name, |
| 169 | // then archive artifacts also on that node |
| 170 | if (jenkins_slave_node_name != env.NODE_NAME) { |
| 171 | node ("${jenkins_slave_node_name}") { |
| 172 | stage("Archive all xml reports from node ${jenkins_slave_node_name}") { |
Sergey Galkin | da677fb | 2019-11-21 16:53:25 +0400 | [diff] [blame] | 173 | 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] | 174 | } |
| 175 | if ("${env.REPORT_TO_TESTRAIL}" != "false") { |
| 176 | stage("report results to testrail") { |
| 177 | common.printMsg("Running on: " + node_with_reports, "blue") |
| 178 | shared.swarm_testrail_report(steps, node_with_reports) |
| 179 | } |
| 180 | stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") { |
| 181 | if (fileExists("description.txt")) { |
| 182 | def String description = readFile("description.txt") |
| 183 | currentBuild.description += "${description}" |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } // node |
| 188 | } |
| 189 | } |
| 190 | |
Dennis Dmitriev | 2700732 | 2019-05-03 19:21:44 +0300 | [diff] [blame] | 191 | } // try |
| 192 | } // node |
| 193 | |
| 194 | |
Dennis Dmitriev | 1f08b0c | 2019-05-27 17:03:53 +0300 | [diff] [blame] | 195 | //} |
| 196 | } // timeout |