blob: 27dbfd7a0ba1a4f3e9b10b975479df071faf5f60 [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 Dmitriev6f8b0d02018-07-30 21:27:08 +030027 stage("Install core infrastructure and deploy CICD nodes") {
28 // 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 Dmitrieve4b831b2018-08-15 17:16:10 +030035 common.printMsg("Deploy is failed: " + e.message , "red")
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030036 shared.run_cmd("""\
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030037 dos.py suspend ${ENV_NAME} || true
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030038 dos.py snapshot ${ENV_NAME} deploy_failed || true
Dennis Dmitrievfde667f2018-07-23 16:26:50 +030039 """)
Dennis Dmitriev6f8b0d02018-07-30 21:27:08 +030040 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
41 shared.run_cmd("""\
42 dos.py resume ${ENV_NAME} || true
43 sleep 20 # Wait for I/O on the host calms down
44 dos.py time-sync ${ENV_NAME} || true
45 """)
46 } else {
47 shared.run_cmd("""\
48 dos.py destroy ${ENV_NAME} || true
49 """)
50 }
Dennis Dmitrieve4b831b2018-08-15 17:16:10 +030051 report_text = e.message
52 throw e
53 } finally {
54 shared.create_deploy_result_report(steps, currentBuild.result, report_text)
55 }
56}
57
58def test(shared, common, steps) {
59 try {
60 stage("Run tests") {
61 shared.swarm_run_pytest(steps)
62 }
63
64 } catch (e) {
65 common.printMsg("Tests are failed: " + e.message, "red")
66 shared.run_cmd("""\
67 dos.py suspend ${ENV_NAME} || true
68 dos.py snapshot ${ENV_NAME} tests_failed || true
69 """)
70 throw e
71 } finally {
72 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") {
73 shared.run_cmd("""\
74 dos.py resume ${ENV_NAME} || true
75 sleep 20 # Wait for I/O on the host calms down
76 dos.py time-sync ${ENV_NAME} || true
77 """)
78 } else {
79 shared.run_cmd("""\
80 dos.py destroy ${ENV_NAME} || true
81 """)
82 }
83 }
84}
85
86// main
87throttle(['fuel_devops_environment']) {
88 node ("${NODE_NAME}") {
89 try {
90 deploy(shared, common, steps)
91 test(shared, common, steps)
92 } catch (e) {
93 common.printMsg("Job is failed: " + e.message, "red")
94 throw e
95 } finally {
96 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}