blob: bf447eb644ce31dc9744c85171919db5c550405a [file] [log] [blame]
Dennis Dmitrievfde667f2018-07-23 16:26:50 +03001@Library('tcp-qa')_
2
3def common = new com.mirantis.mk.Common()
4def shared = new com.mirantis.system_qa.SharedPipeline()
5def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL
Dennis Dmitriev4c383472019-04-12 13:58:06 +03006def env_manager = env.ENV_MANAGER ?: 'devops'
Dennis Dmitriev02447412019-04-17 18:02:46 +03007
8if (env_manager == 'devops') {
9 jenkins_slave_node_name = "${NODE_NAME}"
Tatyana Leontovichc18c8142019-05-16 15:20:33 +030010 node_with_reports = "${NODE_NAME}"
Dennis Dmitriev02447412019-04-17 18:02:46 +030011 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 Leontovichc18c8142019-05-16 15:20:33 +030015 node_with_reports = jenkins_slave_node_name
Dennis Dmitriev02447412019-04-17 18:02:46 +030016}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030017
Dennis Dmitriev27007322019-05-03 19:21:44 +030018currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030019
Dennis Dmitriev02447412019-04-17 18:02:46 +030020def deploy(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030021 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030022 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030023
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030024 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030025 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030026 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030027
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030028 stage("Create environment, generate model, bootstrap the salt-cluster") {
29 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030030 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030031 shared.swarm_bootstrap_salt_cluster_devops()
32 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030033 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
34 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030035 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030036 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030037 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030038 } else {
39 throw new Exception("Unknow env_manager: '${env_manager}'")
40 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +030041
42 if (fileExists("jenkins_agent_description.txt")) {
43 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
44 currentBuild.description += "${jenkins_agent_description}"
45 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030046 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030047
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030048 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030049 if (env.DRIVETRAIN_STACK_INSTALL) {
50 // steps: env.DRIVETRAIN_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030051 shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030052 } else {
53 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
54 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030055 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030056
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030057 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030058 if (env.PLATFORM_STACK_INSTALL) {
59 // steps: env.PLATFORM_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030060 shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030061 } else {
62 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
63 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030064 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030065
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030066 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030067
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030068 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030069 common.printMsg("Deploy is failed: " + e.message , "purple")
70 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030071 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030072 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030073 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030074 dos.py suspend ${ENV_NAME} || true
75 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030076 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030077 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
78 shared.run_cmd("""\
79 dos.py resume ${ENV_NAME} || true
80 """)
81 }
82 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030083 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030084 throw e
85 } finally {
86 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
87 }
88}
89
Dennis Dmitriev02447412019-04-17 18:02:46 +030090def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030091 try {
92 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030093 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030094 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030095 } else {
96 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
97 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030098 }
99
100 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300101 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +0300102 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300103 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300104 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300105 dos.py suspend ${ENV_NAME} || true
106 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300107 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300108 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
109 shared.run_cmd("""\
110 dos.py resume ${ENV_NAME} || true
111 """)
112 }
113 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300114 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300115 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300116 }
117}
118
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300119
120timeout(time: 15, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300121// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200122// Temporary disable throttle to check how it will run
123//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300124 node ("${NODE_NAME}") {
125 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300126 // run deploy stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300127 deploy(shared, common, steps, env_manager)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300128 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300129 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300130 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300131 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300132 throw e
133 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300134 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300135 // shutdown the environment if required
136 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
137 shared.run_cmd("""\
138 dos.py destroy ${ENV_NAME} || true
139 """)
140 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300141 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300142
143 stage("Archive all xml reports") {
144 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
145 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300146
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400147 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300148 stage("report results to testrail from jenkins master") {
149 common.printMsg("Running on: " + node_with_reports, "blue")
150 common.printMsg("Running on: " + env.NODE_NAME, "blue")
151 shared.verbose_sh("""\
152 [ -d /home/jenkins/venv_testrail_reporter ] || virtualenv /home/jenkins/venv_testrail_reporter""", true, false, true)
153 shared.run_cmd("""\
154 . /home/jenkins/venv_testrail_reporter/bin/activate; pip install git+https://github.com/dis-xcom/testrail_reporter -U""")
155 shared.swarm_testrail_report(steps, env.NODE_NAME)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400156 }
157 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300158 if (fileExists("description.txt")) {
159 def String description = readFile("description.txt")
160 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300161 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400162 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300163 }
Dennis Dmitrievfd0b78c2019-05-30 00:16:04 +0300164
165 if (fileExists("jenkins_agent_description.txt")) {
166 // if there is a separated foundation node on $jenkins_slave_node_name,
167 // then archive artifacts also on that node
168 if (jenkins_slave_node_name != env.NODE_NAME) {
169 node ("${jenkins_slave_node_name}") {
170 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
171 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
172 }
173 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
174 stage("report results to testrail") {
175 common.printMsg("Running on: " + node_with_reports, "blue")
176 shared.swarm_testrail_report(steps, node_with_reports)
177 }
178 stage("Store TestRail reports to job description from ${jenkins_slave_node_name}") {
179 if (fileExists("description.txt")) {
180 def String description = readFile("description.txt")
181 currentBuild.description += "${description}"
182 }
183 }
184 }
185 } // node
186 }
187 }
188
Dennis Dmitriev27007322019-05-03 19:21:44 +0300189 } // try
190 } // node
191
192
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300193//}
194} // timeout