blob: de92a251e3c245d4f39f2b39403abc505d1919f7 [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}"
10 make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
11} else if (env_manager == 'heat') {
12 jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
13 make_snapshot_stages = false
14}
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030015
Dennis Dmitriev27007322019-05-03 19:21:44 +030016currentBuild.description = "${NODE_NAME}:${ENV_NAME}<br>"
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030017
Dennis Dmitriev02447412019-04-17 18:02:46 +030018def deploy(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030019 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030020 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030021
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030022 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030023 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030024 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030025
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030026 stage("Create environment, generate model, bootstrap the salt-cluster") {
27 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030028 if (env_manager == 'devops') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030029 shared.swarm_bootstrap_salt_cluster_devops()
30 } else if (env_manager == 'heat') {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030031 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
32 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030033 shared.swarm_bootstrap_salt_cluster_heat(jenkins_slave_node_name)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030034 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
Dennis Dmitriev02447412019-04-17 18:02:46 +030035 // disable dos.py snapshots for 'heat' manager
Dennis Dmitriev4c383472019-04-12 13:58:06 +030036 } else {
37 throw new Exception("Unknow env_manager: '${env_manager}'")
38 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030039 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030040
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030041 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030042 if (env.DRIVETRAIN_STACK_INSTALL) {
43 // steps: env.DRIVETRAIN_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030044 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 +030045 } else {
46 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
47 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030048 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030049
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030050 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030051 if (env.PLATFORM_STACK_INSTALL) {
52 // steps: env.PLATFORM_STACK_INSTALL
Dennis Dmitriev02447412019-04-17 18:02:46 +030053 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 +030054 } else {
55 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
56 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030057 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030058
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030059 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030060
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030061 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030062 common.printMsg("Deploy is failed: " + e.message , "purple")
63 report_text = e.message
Dennis Dmitriev02447412019-04-17 18:02:46 +030064 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030065 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030066 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030067 dos.py suspend ${ENV_NAME} || true
68 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030069 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030070 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
71 shared.run_cmd("""\
72 dos.py resume ${ENV_NAME} || true
73 """)
74 }
75 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030076 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030077 throw e
78 } finally {
79 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
80 }
81}
82
Dennis Dmitriev02447412019-04-17 18:02:46 +030083def test(shared, common, steps, env_manager) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030084 try {
85 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030086 if (env.RUN_TEST_OPTS) {
Dennis Dmitriev02447412019-04-17 18:02:46 +030087 shared.swarm_run_pytest(steps, jenkins_slave_node_name, make_snapshot_stages)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030088 } else {
89 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
90 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030091 }
92
93 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030094 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev02447412019-04-17 18:02:46 +030095 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030096 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030097 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030098 dos.py suspend ${ENV_NAME} || true
99 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300100 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300101 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
102 shared.run_cmd("""\
103 dos.py resume ${ENV_NAME} || true
104 """)
105 }
106 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300107 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300108 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300109 }
110}
111
112// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200113// Temporary disable throttle to check how it will run
114//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300115 node ("${NODE_NAME}") {
116 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300117 // run deploy stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300118 deploy(shared, common, steps, env_manager)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300119 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300120 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300121 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300122 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300123 throw e
124 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300125 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300126 // shutdown the environment if required
127 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
128 shared.run_cmd("""\
129 dos.py destroy ${ENV_NAME} || true
130 """)
131 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300132 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300133
Dennis Dmitriev27007322019-05-03 19:21:44 +0300134 if (fileExists("jenkins_agent_description.txt")) {
135 def String jenkins_agent_description = readFile("jenkins_agent_description.txt")
136 currentBuild.description += "${jenkins_agent_description}"
137
138 // if there is a separated foundation node on $jenkins_slave_node_name,
139 // then archive artifacts also on that node
140 if (jenkins_slave_node_name != env.NODE_NAME) {
141 node ("${jenkins_slave_node_name}") {
142 stage("Archive all xml reports from node ${}") {
143 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
144 }
145 }
146 }
147 }
148
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300149 stage("Archive all xml reports") {
150 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
151 }
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400152 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400153 stage("report results to testrail") {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300154 shared.swarm_testrail_report(steps)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400155 }
156 stage("Store TestRail reports to job description") {
157 def String description = readFile("description.txt")
Dennis Dmitriev27007322019-05-03 19:21:44 +0300158 currentBuild.description += "${description}"
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400159 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300160 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300161 } // try
162 } // node
163
164
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200165//}