blob: 1af17d1141f181dd4ba2a5517b51285d9ba50b37 [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 Dmitriev6f8b0d02018-07-30 21:27:08 +030041 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030042
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030043 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030044 if (env.DRIVETRAIN_STACK_INSTALL) {
45 // steps: env.DRIVETRAIN_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030046 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 +030047 } else {
48 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
49 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030050 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030051
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030052 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030053 if (env.PLATFORM_STACK_INSTALL) {
54 // steps: env.PLATFORM_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030055 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 +030056 } else {
57 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
58 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030059 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030060
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030061 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030062
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030063 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030064 common.printMsg("Deploy is failed: " + e.message , "purple")
65 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030066 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030067 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030068 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030069 dos.py suspend ${ENV_NAME} || true
70 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030071 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030072 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 Dmitriev6f8b0d02018-07-30 21:27:08 +030078 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030079 throw e
80 } finally {
81 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
82 }
83}
84
Dennis Dmitriev02447412019-04-17 18:02:46 +030085def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030086 try {
87 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030088 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030089 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030090 } else {
91 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
92 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030093 }
94
95 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030096 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +030097 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030098 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030099 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300100 dos.py suspend ${ENV_NAME} || true
101 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300102 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300103 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 Dmitrieve4b831b2018-08-15 17:16:10 +0300109 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300110 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300111 }
112}
113
114// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200115// Temporary disable throttle to check how it will run
116//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300117 node ("${NODE_NAME}") {
118 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300119 // run deploy stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300120 deploy(shared, common, steps, env_manager)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300121 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300122 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300123 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300124 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300125 throw e
126 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300127 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300128 // shutdown the environment if required
129 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
130 shared.run_cmd("""\
131 dos.py destroy ${ENV_NAME} || true
132 """)
133 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300134 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300135
Dennis Dmitriev27007322019-05-03 19:21:44 +0300136 if (fileExists("jenkins_agent_description.txt")) {
137 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
138 currentBuild.description += "${jenkins_agent_description}"
139
140 // if there is a separated foundation node on $jenkins_slave_node_name,
141 // then archive artifacts also on that node
142 if (jenkins_slave_node_name != env.NODE_NAME) {
143 node ("${jenkins_slave_node_name}") {
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300144 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
Dennis Dmitriev27007322019-05-03 19:21:44 +0300145 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
146 }
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300147 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
148 stage("report results to testrail") {
149 shared.swarm_testrail_report(steps, node_with_reports)
150 }
151 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300152 }
153 }
154 }
155
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300156 stage("Archive all xml reports") {
157 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
158 }
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400159 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400160 stage("report results to testrail") {
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300161 shared.swarm_testrail_report(steps, node_with_reports)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400162 }
163 stage("Store TestRail reports to job description") {
164 def String description = readFile("description.txt")
Dennis Dmitriev27007322019-05-03 19:21:44 +0300165 currentBuild.description += "${description}"
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400166 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300167 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300168 } // try
169 } // node
170
171
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200172//}