blob: e0e43ab4a73ff5fb276740e32f01654c9e8fbe6d [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'
7def jenkins_slave_node_name = "${NODE_NAME}"
Dennis Dmitrievfde667f2018-07-23 16:26:50 +03008
Dennis Dmitriev201a35e2018-08-06 01:37:05 +03009currentBuild.description = "${NODE_NAME}:${ENV_NAME}"
10
Dennis Dmitriev4c383472019-04-12 13:58:06 +030011def deploy(shared, common, steps, env_manager, jenkins_slave_node_name) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030012 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030013 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030014
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030015 stage("Clean the environment and clone tcp-qa") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030016 shared.prepare_working_dir(env_manager)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030017 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030018
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030019 stage("Create environment, generate model, bootstrap the salt-cluster") {
20 // steps: "hardware,create_model,salt"
Dennis Dmitriev4c383472019-04-12 13:58:06 +030021 if (env_manager == 'devops') {
22 jenkins_slave_node_name = "${NODE_NAME}"
23 shared.swarm_bootstrap_salt_cluster_devops()
24 } else if (env_manager == 'heat') {
25 def new_jenkins_slave_node_name = "openstack_slave_${JOB_NAME}"
26 // If shared.swarm_bootstrap_salt_cluster_heat() failed,
27 // do not schedule shared.swarm_testrail_report() on the non existing Jenkins slave
28 shared.swarm_bootstrap_salt_cluster_heat(new_jenkins_slave_node_name)
29 // When the Heat stack created, set jenkins_slave_node_name to the new Jenkins slave
30 jenkins_slave_node_name = new_jenkins_slave_node_name
31 } else {
32 throw new Exception("Unknow env_manager: '${env_manager}'")
33 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030034 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030035
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030036 stage("Install core infrastructure and deploy CICD nodes") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030037 if (env.DRIVETRAIN_STACK_INSTALL) {
38 // steps: env.DRIVETRAIN_STACK_INSTALL
39 shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL, env.DRIVETRAIN_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name)
40 } else {
41 common.printMsg("DRIVETRAIN_STACK_INSTALL is empty, skipping 'swarm-deploy-cicd' job", "green")
42 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030043 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030044
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030045 stage("Deploy platform components") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030046 if (env.PLATFORM_STACK_INSTALL) {
47 // steps: env.PLATFORM_STACK_INSTALL
48 shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL, env.PLATFORM_STACK_INSTALL_TIMEOUT, jenkins_slave_node_name)
49 } else {
50 common.printMsg("PLATFORM_STACK_INSTALL is empty, skipping 'swarm-deploy-platform' job", "green")
51 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030052 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030053
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030054 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030055
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030056 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030057 common.printMsg("Deploy is failed: " + e.message , "purple")
58 report_text = e.message
Dennis Dmitriev4c383472019-04-12 13:58:06 +030059 if (env_manager == 'devops') {
60 def snapshot_name = "deploy_failed"
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030061 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030062 dos.py suspend ${ENV_NAME} || true
63 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030064 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030065 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
66 shared.run_cmd("""\
67 dos.py resume ${ENV_NAME} || true
68 """)
69 }
70 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030071 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030072 throw e
73 } finally {
74 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
75 }
76}
77
Dennis Dmitriev4c383472019-04-12 13:58:06 +030078def test(shared, common, steps, env_manager, jenkins_slave_node_name) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030079 try {
80 stage("Run tests") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030081 if (env.RUN_TEST_OPTS) {
82 shared.swarm_run_pytest(steps, jenkins_slave_node_name)
83 } else {
84 common.printMsg("RUN_TEST_OPTS is empty, skipping 'swarm-run-pytest' job", "green")
85 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030086 }
87
88 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030089 common.printMsg("Tests are failed: " + e.message, "purple")
Dennis Dmitriev4c383472019-04-12 13:58:06 +030090 if (env_manager == 'devops') {
91 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030092 shared.run_cmd("""\
Dennis Dmitriev4c383472019-04-12 13:58:06 +030093 dos.py suspend ${ENV_NAME} || true
94 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030095 """)
Dennis Dmitriev4c383472019-04-12 13:58:06 +030096 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
97 shared.run_cmd("""\
98 dos.py resume ${ENV_NAME} || true
99 """)
100 }
101 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300102 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300103 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300104 }
105}
106
107// main
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200108// Temporary disable throttle to check how it will run
109//throttle(['fuel_devops_environment']) {
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300110 node ("${NODE_NAME}") {
111 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300112 // run deploy stages
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300113 deploy(shared, common, steps, env_manager, jenkins_slave_node_name)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300114 // run test stages
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300115 test(shared, common, steps, env_manager, jenkins_slave_node_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300116 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300117 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +0300118 throw e
119 } finally {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300120 if (env_manager == 'devops') {
121 // shutdown the environment if required
122 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
123 shared.run_cmd("""\
124 dos.py destroy ${ENV_NAME} || true
125 """)
126 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +0300127 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300128
129 stage("Archive all xml reports") {
130 archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz"
131 }
Vladimir Jigulin91bb7c92019-04-04 18:15:45 +0400132 if ("${env.REPORT_TO_TESTRAIL}" != "false") {
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400133 stage("report results to testrail") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300134 shared.swarm_testrail_report(steps, jenkins_slave_node_name)
Vladimir Jigulinb02dcc52019-04-02 15:57:53 +0400135 }
136 stage("Store TestRail reports to job description") {
137 def String description = readFile("description.txt")
138 currentBuild.description += "\n${description}"
139 }
Dennis Dmitrievfbf42272018-10-23 00:19:50 +0300140 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300141 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +0300142 }
Tatyana Leontovichbfbc4832018-12-27 12:47:23 +0200143//}