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