blob: 6014b9e4f9dcf438e1a7bfe46ff572bfe016582e [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001/**
2 *
3 * Deploy CICD cluster using Jenkins master on cfg01 node
4 *
5 * Expected parameters:
6
7 * PARENT_NODE_NAME Name of the jenkins slave to create the environment
8 * PARENT_WORKSPACE Path to the workspace of the parent job to use tcp-qa repo
9 * ENV_NAME Fuel-devops environment name
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020010 * STACK_INSTALL Stacks to install using Jenkins on cfg01 node: "core,cicd"
11 * STACK_INSTALL_TIMEOUT Stacks installation timeout
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030012 * TCP_QA_REFS Reference to the tcp-qa change on review.gerrithub.io, like refs/changes/46/418546/41
13 * SHUTDOWN_ENV_ON_TEARDOWN optional, shutdown fuel-devops environment at the end of the job
Dennis Dmitriev02447412019-04-17 18:02:46 +030014 * MAKE_SNAPSHOT_STAGES optional, use "dos.py snapshot" to snapshot stages
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030015 *
16 */
17
18@Library('tcp-qa')_
19
20common = new com.mirantis.mk.Common()
21shared = new com.mirantis.system_qa.SharedPipeline()
Dennis Dmitriev02447412019-04-17 18:02:46 +030022make_snapshot_stages = "${env.MAKE_SNAPSHOT_STAGES}" != "false" ? true : false
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030023
24if (! env.PARENT_NODE_NAME) {
25 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
26}
27
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030028currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
29
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020030def install_timeout = env.STACK_INSTALL_TIMEOUT.toInteger()
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030031
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020032timeout(time: install_timeout + 600, unit: 'SECONDS') {
33
34 node ("${PARENT_NODE_NAME}") {
35 if (! fileExists("${PARENT_WORKSPACE}")) {
36 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030037 }
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020038 dir("${PARENT_WORKSPACE}") {
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030039
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020040 if (! env.STACK_INSTALL) {
41 error "'STACK_INSTALL' must contain one or more comma separated stack names for [deploy_openstack] pipeline"
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030042 }
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030043
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020044 if (env.TCP_QA_REFS) {
45 stage("Update working dir to patch ${TCP_QA_REFS}") {
46 shared.update_working_dir()
47 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030048 }
49
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030050 try {
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020051 // Install core and cicd
Dennis Dmitriev44f6db22018-10-31 16:07:56 +020052 stage("Run Jenkins job on salt-master [deploy_openstack:${env.STACK_INSTALL}]") {
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020053 shared.run_job_on_day01_node(env.STACK_INSTALL, install_timeout)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030054 }
Oleksii Butenko3b3bab12019-05-23 17:30:15 +030055 stage("Create env_jenkins_cicd and env_k8s files") {
56 shared.run_cmd("""\
57 export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
58 python ./tcp_tests/utils/create_env_jenkins_cicd.py
59 """)
60 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030061
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020062 for (stack in "${env.STACK_INSTALL}".split(",")) {
63 stage("Sanity check the deployed component [${stack}]") {
64 shared.sanity_check_component(stack)
Dennis Dmitriev02447412019-04-17 18:02:46 +030065
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +030066 // If oslo_config INI file ${ENV_NAME}_salt_deployed.ini exists,
67 // then make a copy for the created snapshot to allow the system
68 // tests to revert this snapshot along with the metadata from the INI file.
69 shared.run_cmd("""\
70 if [ -f \$(pwd)/${ENV_NAME}_salt_deployed.ini ]; then
71 cp \$(pwd)/${ENV_NAME}_salt_deployed.ini \$(pwd)/${ENV_NAME}_${stack}_deployed.ini
72 fi
73 """)
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +020074 }
75 } // for
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030076
Dennis Dmitriev2bacadf2019-05-03 17:26:11 +030077 if (make_snapshot_stages) {
78 stage("Make environment snapshots for [${env.STACK_INSTALL}]") {
79 shared.devops_snapshot(env.STACK_INSTALL)
80 }
81 }
82
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030083 } catch (e) {
84 common.printMsg("Job is failed", "purple")
Dennis Dmitriev9cd5c132018-12-12 17:10:47 +020085 shared.download_logs("deploy_drivetrain_${ENV_NAME}")
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030086 throw e
87 } finally {
88 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
89 // and report appropriate data to TestRail
90 // TODO(ddmitriev): add checks for cicd cluster
Dennis Dmitriev02447412019-04-17 18:02:46 +030091 if (make_snapshot_stages) {
92 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
93 shared.run_cmd("""\
94 dos.py destroy ${ENV_NAME}
95 """)
96 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030097 }
98 }
99
Dennis Dmitriev07d5b8a2018-10-29 19:43:00 +0200100 } // dir
101 } // node
Dennis Dmitriev1f08b0c2019-05-27 17:03:53 +0300102} // timeout