Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 1 | @Library('tcp-qa')_ |
| 2 | |
| 3 | def common = new com.mirantis.mk.Common() |
| 4 | def shared = new com.mirantis.system_qa.SharedPipeline() |
| 5 | def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL |
| 6 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 7 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}" |
| 8 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame^] | 9 | def deploy(shared, common, steps) { |
| 10 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 11 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 12 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 13 | stage("Clean the environment and clone tcp-qa") { |
| 14 | shared.prepare_working_dir() |
| 15 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 16 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 17 | stage("Create environment, generate model, bootstrap the salt-cluster") { |
| 18 | // steps: "hardware,create_model,salt" |
| 19 | shared.swarm_bootstrap_salt_cluster_devops() |
| 20 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 21 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 22 | 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 Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 26 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 27 | 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 Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 31 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame^] | 32 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 33 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 34 | } catch (e) { |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame^] | 35 | common.printMsg("Deploy is failed: " + e.message , "red") |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 36 | shared.run_cmd("""\ |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 37 | dos.py suspend ${ENV_NAME} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame^] | 38 | dos.py snapshot ${ENV_NAME} deploy_failed || true |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 39 | """) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 40 | 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 Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame^] | 51 | report_text = e.message |
| 52 | throw e |
| 53 | } finally { |
| 54 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | def 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 |
| 87 | throttle(['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 Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 97 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 98 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 99 | } |