blob: 567ddc62afd7b7c052e42bb0380be9697ea9e0f8 [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
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300114
115timeout(time: 15, unit: 'HOURS') {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300116// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200117// Temporary disable throttle to check how it will run
118//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300119 node ("${NODE_NAME}") {
120 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300121 // run deploy stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300122 deploy(shared, common, steps, env_manager)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300123 // run test stages
Dennis Dmitriev02447412019-04-17 18:02:46 +0300124 test(shared, common, steps, env_manager)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300125 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300126 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300127 throw e
128 } finally {
Dennis Dmitriev02447412019-04-17 18:02:46 +0300129 if (make_snapshot_stages) {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300130 // 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 Dmitrievb08c0772018-10-17 15:10:26 +0300136 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300137
Dennis Dmitriev27007322019-05-03 19:21:44 +0300138 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 Leontovichc18c8142019-05-16 15:20:33 +0300146 stage("Archive all xml reports from node ${jenkins_slave_node_name}") {
Dennis Dmitriev27007322019-05-03 19:21:44 +0300147 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
148 }
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300149 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300150 stage("report results to testrail") {
151 common.printMsg("Running on: " + node_with_reports, "blue")
152 shared.swarm_testrail_report(steps, node_with_reports)
Tatyana Leontovichc18c8142019-05-16 15:20:33 +0300153 }
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300154 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 Leontovichc18c8142019-05-16 15:20:33 +0300160 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300161 }
162 }
163 }
164
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300165 stage("Archive all xml reports") {
166 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
167 }
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400168 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Tatyana Leontovich43854972019-05-24 23:02:22 +0300169 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 Jigulinb02dcc52019-04-02 15:57:53 +0400177 }
178 stage("Store TestRail reports to job description") {
Dennis Dmitriev239db4e2019-05-27 16:13:31 +0300179 if (fileExists("description.txt")) {
180 def String description = readFile("description.txt")
181 currentBuild.description += "${description}"
Tatyana Leontovich6cce9d62019-05-24 19:43:07 +0300182 }
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400183 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300184 }
Dennis Dmitriev27007322019-05-03 19:21:44 +0300185 } // try
186 } // node
187
188
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300189//}
190} // timeout