blob: 55dda48fa275774a1cc91b44d89f0fbb6bea0e93 [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
6
Dennis Dmitriev201a35e2018-08-06 01:37:05 +03007currentBuild.description = "${NODE_NAME}:${ENV_NAME}"
8
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +03009def deploy(shared, common, steps) {
10 def report_text = ''
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030011 try {
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030012
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030013 stage("Clean the environment and clone tcp-qa") {
14 shared.prepare_working_dir()
15 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030016
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030017 stage("Create environment, generate model, bootstrap the salt-cluster") {
18 // steps: "hardware,create_model,salt"
19 shared.swarm_bootstrap_salt_cluster_devops()
20 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030021
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030022 stage("Install core infrastructure and deploy CICD nodes") {
23 // steps: env.DRIVETRAIN_STACK_INSTALL
24 shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL)
25 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030026
Dennis Dmitrievee5ef232018-08-31 13:53:18 +030027 stage("Deploy platform components") {
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030028 // steps: env.PLATFORM_STACK_INSTALL
29 shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL)
30 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030031
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030032 currentBuild.result = 'SUCCESS'
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030033
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030034 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030035 common.printMsg("Deploy is failed: " + e.message , "purple")
36 report_text = e.message
37 def snapshot_name = "deploy_failed"
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030038 shared.run_cmd("""\
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030039 dos.py suspend ${ENV_NAME} || true
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030040 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030041 """)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030042 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
43 shared.run_cmd("""\
44 dos.py resume ${ENV_NAME} || true
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030045 """)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030046 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030047 shared.devops_snapshot_info(snapshot_name)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030048 throw e
49 } finally {
50 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
51 }
52}
53
54def test(shared, common, steps) {
55 try {
56 stage("Run tests") {
57 shared.swarm_run_pytest(steps)
58 }
59
60 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030061 common.printMsg("Tests are failed: " + e.message, "purple")
62 def snapshot_name = "tests_failed"
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030063 shared.run_cmd("""\
64 dos.py suspend ${ENV_NAME} || true
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030065 dos.py snapshot ${ENV_NAME} ${snapshot_name} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030066 """)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030067 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
68 shared.run_cmd("""\
69 dos.py resume ${ENV_NAME} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030070 """)
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030071 }
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030072 shared.devops_snapshot_info(snapshot_name)
73 throw e
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030074 }
75}
76
77// main
78throttle(['fuel_devops_environment']) {
79 node ("${NODE_NAME}") {
80 try {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030081 // run deploy stages
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030082 deploy(shared, common, steps)
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030083 // run test stages
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030084 test(shared, common, steps)
85 } catch (e) {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030086 common.printMsg("Job is failed: " + e.message, "purple")
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030087 throw e
88 } finally {
Dennis Dmitrievb08c0772018-10-17 15:10:26 +030089 // shutdown the environment if required
90 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
91 shared.run_cmd("""\
92 dos.py destroy ${ENV_NAME} || true
93 """)
94 }
95 // report results to testrail
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030096 shared.swarm_testrail_report(steps)
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030097 }
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030098 }
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030099}