blob: 86b51223d19561cb35198cfb207bb781116d19b8 [file] [log] [blame]
Dennis Dmitrievb3b37492018-07-08 21:23:00 +03001/**
2 *
3 * Create fuel-devops environment, generate a model for it
4 * and bootstrap a salt cluster on the environment nodes
5 *
6 * Expected parameters:
7
8 * PARENT_NODE_NAME Name of the jenkins slave to create the environment
9 * PARENT_WORKSPACE Path to the workspace of the parent job to use tcp-qa repo
10 * LAB_CONFIG_NAME Name of the tcp-qa deployment template
11 * ENV_NAME Fuel-devops environment name
12 * MCP_VERSION MCP version, like 2018.4 or proposed
13 * MCP_IMAGE_PATH1604 Local path to the image http://ci.mcp.mirantis.net:8085/images/ubuntu-16-04-x64-mcpproposed.qcow2
14 * IMAGE_PATH_CFG01_DAY01 Local path to the image http://ci.mcp.mirantis.net:8085/images/cfg01-day01-proposed.qcow2
15 * CFG01_CONFIG_IMAGE_NAME Name for the creating config drive image, like cfg01.${LAB_CONFIG_NAME}-config-drive.iso
16 * TCP_QA_REFS Reference to the tcp-qa change on review.gerrithub.io, like refs/changes/46/418546/41
17 * PIPELINE_LIBRARY_REF Reference to the pipeline-library change
18 * MK_PIPELINES_REF Reference to the mk-pipelines change
19 * COOKIECUTTER_TEMPLATE_COMMIT Commit/tag/branch for cookiecutter-templates repository. If empty, then takes ${MCP_VERSION} value
20 * SALT_MODELS_SYSTEM_COMMIT Commit/tag/branch for reclass-system repository. If empty, then takes ${MCP_VERSION} value
21 * SHUTDOWN_ENV_ON_TEARDOWN optional, shutdown fuel-devops environment at the end of the job
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020022 * MCP_SALT_REPO_URL Base URL for MCP repositories required to bootstrap cfg01 node. Leave blank to use default
23 * (http://mirror.mirantis.com/ from mcp-common-scripts)
Tatyana Leontovich8ac26d72019-05-15 23:33:38 +030024 * JENKINS_PIPELINE_BRANCH Should be set in release/proposed/2019.2.0 when we test non-released version
Dennis Dmitrievd9168b52018-12-19 18:53:52 +020025 * MCP_SALT_REPO_KEY URL of the key file. Leave blank to use default
26 * (${MCP_SALT_REPO_URL}/${MCP_VERSION}/salt-formulas/xenial/archive-salt-formulas.key from mcp-common-scripts)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030027 *
28 */
29
30@Library('tcp-qa')_
31
Dennis Dmitriev47800162018-10-31 11:57:02 +020032import groovy.xml.XmlUtil
33
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030034common = new com.mirantis.mk.Common()
35shared = new com.mirantis.system_qa.SharedPipeline()
36
37if (! env.PARENT_NODE_NAME) {
38 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
39}
40
Dennis Dmitriev201a35e2018-08-06 01:37:05 +030041currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
42
Dennis Dmitrievb3b37492018-07-08 21:23:00 +030043node ("${PARENT_NODE_NAME}") {
44 if (! fileExists("${PARENT_WORKSPACE}")) {
45 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
46 }
47 dir("${PARENT_WORKSPACE}") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030048 if (env.TCP_QA_REFS) {
49 stage("Update working dir to patch ${TCP_QA_REFS}") {
50 shared.update_working_dir()
51 }
52 }
53
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030054 stage("Cleanup: erase ${ENV_NAME} and remove config drive") {
55 println "Remove environment ${ENV_NAME}"
56 shared.run_cmd("""\
57 dos.py erase ${ENV_NAME} || true
58 """)
59 println "Remove config drive ISO"
60 shared.run_cmd("""\
61 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
62 """)
63 }
64
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030065 stage("Create an environment ${ENV_NAME} in disabled state") {
66 // deploy_hardware.xml
67 shared.run_cmd("""\
68 export ENV_NAME=${ENV_NAME}
69 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
Dennis Dmitriev552454c2019-03-21 23:15:51 +020070 export ENV_MANAGER=devops
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030071 export PYTHONIOENCODING=UTF-8
72 export REPOSITORY_SUITE=${MCP_VERSION}
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +030073 export UPDATE_VERSION=${UPDATE_VERSION}
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030074 export TEST_GROUP=test_create_environment
Dennis Dmitriev27007322019-05-03 19:21:44 +030075 export LOG_NAME=swarm_test_create_environment.log
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030076 py.test -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_hardware.xml -k \${TEST_GROUP}
77 """)
78 }
79
80 stage("Generate the model") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030081 def IPV4_NET_ADMIN=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep admin-pool01").trim().split().last()
82 def IPV4_NET_CONTROL=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep private-pool01").trim().split().last()
83 def IPV4_NET_TENANT=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep tenant-pool01").trim().split().last()
84 def IPV4_NET_EXTERNAL=shared.run_cmd_stdout("dos.py net-list ${ENV_NAME} | grep external-pool01").trim().split().last()
85 shared.generate_cookied_model(IPV4_NET_ADMIN, IPV4_NET_CONTROL, IPV4_NET_TENANT, IPV4_NET_EXTERNAL)
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +030086 }
87
88 stage("Generate config drive ISO") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +030089 def SALT_MASTER_IP=shared.run_cmd_stdout("""\
90 SALT_MASTER_INFO=\$(for node in \$(dos.py slave-ip-list --address-pool-name admin-pool01 ${ENV_NAME}); do echo \$node; done|grep cfg01)
91 echo \$SALT_MASTER_INFO|cut -d',' -f2
92 """).trim().split("\n").last()
93 def dhcp_ranges_json=shared.run_cmd_stdout("""\
94 fgrep dhcp_ranges ${ENV_NAME}_hardware.ini |
95 fgrep "admin-pool01"|
96 cut -d"=" -f2
97 """).trim().split("\n").last()
98 def dhcp_ranges = new groovy.json.JsonSlurperClassic().parseText(dhcp_ranges_json)
99 def ADMIN_NETWORK_GW = dhcp_ranges['admin-pool01']['gateway']
100 shared.generate_configdrive_iso(SALT_MASTER_IP, ADMIN_NETWORK_GW)
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300101 }
102
103 stage("Upload generated config drive ISO into volume on cfg01 node") {
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300104 def SALT_MASTER_HOSTNAME=shared.run_cmd_stdout("""\
105 SALT_MASTER_INFO=\$(for node in \$(dos.py slave-ip-list --address-pool-name admin-pool01 ${ENV_NAME}); do echo \$node; done|grep cfg01)
106 echo \$SALT_MASTER_INFO|cut -d',' -f1
107 """).trim().split("\n").last()
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300108 shared.run_cmd("""\
109 # Get SALT_MASTER_HOSTNAME to determine the volume name
Dennis Dmitriev4c383472019-04-12 13:58:06 +0300110 virsh vol-upload ${ENV_NAME}_${SALT_MASTER_HOSTNAME}_config /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} --pool default
Dennis Dmitrievefe5c0b2018-10-24 20:35:26 +0300111 virsh pool-refresh --pool default
112 """)
113 }
114
Dennis Dmitriev47800162018-10-31 11:57:02 +0200115 stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") {
116 def xml_report_name = "deploy_salt.xml"
117 try {
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300118 // deploy_salt.xml
Dennis Dmitriev47800162018-10-31 11:57:02 +0200119 shared.run_sh("""\
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300120 export ENV_NAME=${ENV_NAME}
121 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
Dennis Dmitriev552454c2019-03-21 23:15:51 +0200122 export ENV_MANAGER=devops
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300123 export SHUTDOWN_ENV_ON_TEARDOWN=false
Dennis Dmitriev87c22d72018-11-09 17:18:00 +0200124 export BOOTSTRAP_TIMEOUT=1800
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300125 export PYTHONIOENCODING=UTF-8
126 export REPOSITORY_SUITE=${MCP_VERSION}
Tatyana Leontovich4718bdf2019-05-24 12:37:06 +0300127 export UPDATE_VERSION=${UPDATE_VERSION}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300128 export TEST_GROUP=test_bootstrap_salt
Dennis Dmitriev27007322019-05-03 19:21:44 +0300129 export LOG_NAME=swarm_test_bootstrap_salt.log
Dennis Dmitriev47800162018-10-31 11:57:02 +0200130 py.test -vvv -s -p no:django -p no:ipdb --junit-xml=${xml_report_name} -k \${TEST_GROUP}
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300131 """)
Dennis Dmitriev44f6db22018-10-31 16:07:56 +0200132 // Wait for jenkins to start and IO calm down
133 sleep(60)
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300134
Dennis Dmitriev47800162018-10-31 11:57:02 +0200135 } catch (e) {
136 common.printMsg("Saltstack cluster deploy is failed", "purple")
137 if (fileExists(xml_report_name)) {
Dennis Dmitriev9cd5c132018-12-12 17:10:47 +0200138 shared.download_logs("deploy_salt_${ENV_NAME}")
Dennis Dmitriev47800162018-10-31 11:57:02 +0200139 def String junit_report_xml = readFile(xml_report_name)
140 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
141 throw new Exception(junit_report_xml_pretty)
142 } else {
143 throw e
144 }
145 } finally {
146 // TODO(ddmitriev): analyze the "def currentResult = currentBuild.result ?: 'SUCCESS'"
147 // and report appropriate data to TestRail
148 // TODO(ddmitriev): add checks for salt cluster
149 if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") {
150 shared.run_cmd("""\
151 dos.py destroy ${ENV_NAME}
152 """)
153 }
Dennis Dmitrievb3b37492018-07-08 21:23:00 +0300154 }
155 }
156 }
157}