blob: fc129764266e4b19a7cd35174dabf8b9743ecf1e [file] [log] [blame]
Dennis Dmitriev4c383472019-04-12 13:58:06 +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
22 * 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)
24 * MCP_SALT_REPO_KEY URL of the key file. Leave blank to use default
25 * (${MCP_SALT_REPO_URL}/${MCP_VERSION}/salt-formulas/xenial/archive-salt-formulas.key from mcp-common-scripts)
26 * OS_AUTH_URL OpenStack keystone catalog URL
27 * OS_PROJECT_NAME OpenStack project (tenant) name
28 * OS_USER_DOMAIN_NAME OpenStack user domain name
29 * OS_CREDENTIALS OpenStack username and password credentials ID in Jenkins
30 * LAB_PARAM_DEFAULTS Filename placed in tcp_tests/templates/_heat_environments, with default parameters for the heat template
31 *
32 */
33
34@Library('tcp-qa')_
35
36import groovy.xml.XmlUtil
37
38common = new com.mirantis.mk.Common()
39shared = new com.mirantis.system_qa.SharedPipeline()
40
41if (! env.PARENT_NODE_NAME) {
42 error "'PARENT_NODE_NAME' must be set from the parent deployment job!"
43}
44
45currentBuild.description = "${PARENT_NODE_NAME}:${ENV_NAME}"
46def cfg01_day01_image_name = "cfg01-day01-${MCP_VERSION}"
47def ubuntu_vcp_image_name = "ubuntu-vcp-${MCP_VERSION}"
48def ubuntu_foundation_image_name = "ubuntu-16.04-foundation-${MCP_VERSION}"
49
50node ("${PARENT_NODE_NAME}") {
51 if (! fileExists("${PARENT_WORKSPACE}")) {
52 error "'PARENT_WORKSPACE' contains path to non-existing directory ${PARENT_WORKSPACE} on the node '${PARENT_NODE_NAME}'."
53 }
54 dir("${PARENT_WORKSPACE}") {
55
56 if (env.TCP_QA_REFS) {
57 stage("Update working dir to patch ${TCP_QA_REFS}") {
58 shared.update_working_dir()
59 }
60 }
61
62 withCredentials([
63 [$class : 'UsernamePasswordMultiBinding',
64 credentialsId : env.OS_CREDENTIALS,
65 passwordVariable: 'OS_PASSWORD',
66 usernameVariable: 'OS_USERNAME']
67 ]) {
68 env.OS_IDENTITY_API_VERSION = 3
69
70 stage("Cleanup: erase ${ENV_NAME} and remove config drive") {
71
72 // delete heat stack
73 println "Remove heat stack '${ENV_NAME}'"
74 shared.run_cmd("""\
75 # export OS_IDENTITY_API_VERSION=3
76 # export OS_AUTH_URL=${OS_AUTH_URL}
77 # export OS_USERNAME=${OS_USERNAME}
78 # export OS_PASSWORD=${OS_PASSWORD}
79 # export OS_PROJECT_NAME=${OS_PROJECT_NAME}
80 openstack --insecure stack delete -y ${ENV_NAME} || true
81 while openstack --insecure stack show ${ENV_NAME} -f value -c stack_status; do sleep 10; done
82 """)
83
84 println "Remove config drive ISO"
85 shared.run_cmd("""\
86 rm /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} || true
87 """)
88 }
89
90 stage("Generate the model") {
91 def IPV4_NET_ADMIN=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py management_subnet_cidr").trim().split().last()
92 def IPV4_NET_CONTROL=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py control_subnet_cidr").trim().split().last()
93 def IPV4_NET_TENANT=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py tenant_subnet_cidr").trim().split().last()
94 def IPV4_NET_EXTERNAL=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py external_subnet_cidr").trim().split().last()
95 shared.generate_cookied_model(IPV4_NET_ADMIN, IPV4_NET_CONTROL, IPV4_NET_TENANT, IPV4_NET_EXTERNAL)
96 }
97
98 stage("Generate config drive ISO") {
99 def SALT_MASTER_IP=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py management_subnet_cfg01_ip").trim().split().last()
100 def ADMIN_NETWORK_GW=shared.run_cmd_stdout("./tcp_tests/utils/get_param_heat_template.py management_subnet_gateway_ip").trim().split().last()
101 shared.generate_configdrive_iso(SALT_MASTER_IP, ADMIN_NETWORK_GW)
102 }
103
104 stage("Upload Ubuntu image for foundation node") {
105 shared.run_cmd("""\
106 if ! openstack --insecure image show ${ubuntu_foundation_image_name} -f value -c name; then
107 wget -O ./${ubuntu_foundation_image_name} https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img
108 openstack --insecure image create ${ubuntu_foundation_image_name} --file ./${ubuntu_foundation_image_name} --disk-format qcow2 --container-format bare
109 rm ./${ubuntu_foundation_image_name}
110 else
111 echo Image ${ubuntu_foundation_image_name} already exists
112 fi
113 """)
114 }
115
116 stage("Upload cfg01-day01 and VCP images") {
117 shared.run_cmd("""\
118 # export OS_IDENTITY_API_VERSION=3
119 # export OS_AUTH_URL=${OS_AUTH_URL}
120 # export OS_USERNAME=${OS_USERNAME}
121 # export OS_PASSWORD=${OS_PASSWORD}
122 # export OS_PROJECT_NAME=${OS_PROJECT_NAME}
123
124 openstack --insecure image show ${cfg01_day01_image_name} -f value -c name || openstack --insecure image create ${cfg01_day01_image_name} --file ${IMAGE_PATH_CFG01_DAY01} --disk-format qcow2 --container-format bare
125 openstack --insecure image show ${ubuntu_vcp_image_name} -f value -c name || openstack --insecure image create ${ubuntu_vcp_image_name} --file ${MCP_IMAGE_PATH1604} --disk-format qcow2 --container-format bare
126 """)
127 }
128
129 stage("Upload generated config drive ISO into volume on cfg01 node") {
130 shared.run_cmd("""\
131 # export OS_IDENTITY_API_VERSION=3
132 # export OS_AUTH_URL=${OS_AUTH_URL}
133 # export OS_USERNAME=${OS_USERNAME}
134 # export OS_PASSWORD=${OS_PASSWORD}
135 # export OS_PROJECT_NAME=${OS_PROJECT_NAME}
136
137 openstack --insecure image delete cfg01.${ENV_NAME}-config-drive.iso || true
138 sleep 3
139 openstack --insecure image create cfg01.${ENV_NAME}-config-drive.iso --file /home/jenkins/images/${CFG01_CONFIG_IMAGE_NAME} --disk-format iso --container-format bare
140 """)
141 }
142
143 stage("Create Heat stack '${ENV_NAME}'") {
144 // Create stack and wait for CREATE_COMPLETED status, manual analog:
145 // openstack --insecure stack create ${ENV_NAME} \
146 // --template ./tcp_tests/templates/${LAB_CONFIG_NAME}/underlay.hot \
147 // --environment ./tcp_tests/templates/_heat_environments/${LAB_PARAM_DEFAULTS} \
148 // --parameter env_name=${ENV_NAME} --parameter mcp_version=${MCP_VERSION}
149 shared.run_cmd("""\
150 export BOOTSTRAP_TIMEOUT=3600
151 export ENV_MANAGER=heat
152 export TEST_GROUP=test_create_environment
153 export SHUTDOWN_ENV_ON_TEARDOWN=false
154 export PYTHONIOENCODING=UTF-8
155 export REPOSITORY_SUITE=${MCP_VERSION}
156 export ENV_NAME=${ENV_NAME}
157 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
158 export LAB_PARAM_DEFAULTS=${LAB_PARAM_DEFAULTS}
159 py.test --cache-clear -vvv -s -p no:django -p no:ipdb --junit-xml=deploy_hardware.xml -k \${TEST_GROUP}
160 """)
161 }
162
163 stage("Add the Jenkins slave node") {
164 def jenkins_slave_ip_value_name = "foundation_floating"
165 def jenkins_slave_ip = shared.run_cmd_stdout("openstack --insecure stack output show ${ENV_NAME} ${jenkins_slave_ip_value_name} -f value -c output_value").trim().split().last()
166 def jenkins_slave_executors = 2
167 common.printMsg("JENKINS_SLAVE_NODE_NAME=${JENKINS_SLAVE_NODE_NAME}", "green")
168 common.printMsg("JENKINS_SLAVE_IP=${jenkins_slave_ip}", "green")
169
170 withCredentials([
171 [$class : 'UsernamePasswordMultiBinding',
172 credentialsId : "${CREATE_JENKINS_NODE_CREDENTIALS}",
173 passwordVariable: 'JENKINS_PASS',
174 usernameVariable: 'JENKINS_USER']
175 ]) {
176
177 script_delete_agent = ("""\
178 CRUMB=\$(curl --fail -0 -u \"\${JENKINS_USER}:\${JENKINS_PASS}\" \${JENKINS_URL}\'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)\' 2>/dev/null)
179 curl -w '%{http_code}' -o /dev/null \
180 -u \"\${JENKINS_USER}:\${JENKINS_PASS}\" \
181 -H \"Content-Type:application/x-www-form-urlencoded\" \
182 -H \"\$CRUMB\" \
183 \"\${JENKINS_URL}/computer/\${JENKINS_SLAVE_NODE_NAME}/doDelete\" \
184 --request \'POST\' --data \'\'
185 sleep 10
186 """)
187
188 script_create_agent = ("""\
189 CRUMB=\$(curl --fail -0 -u \"\${JENKINS_USER}:\${JENKINS_PASS}\" \${JENKINS_URL}\'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)\' 2>/dev/null)
190
191 curl -L -sS -w '%{http_code}' -o /dev/null \
192 -u \"\${JENKINS_USER}:\${JENKINS_PASS}\" \
193 -H \"Content-Type:application/x-www-form-urlencoded\" \
194 -H \"\$CRUMB\" \
195 -X POST -d 'json={\
196 \"name\": \"'\"\$JENKINS_SLAVE_NODE_NAME\"'\", \
197 \"nodeDescription\": \"'\"\$ENV_NAME\"'\", \
198 \"numExecutors\": \"'\"${jenkins_slave_executors}\"'\", \
199 \"remoteFS\": \"'\"/home/jenkins/workspace\"'\", \
200 \"labelString\": \"'\"\$ENV_NAME\"'\", \
201 \"mode\": \"EXCLUSIVE\", \
202 \"\": [\"hudson.plugins.sshslaves.SSHLauncher\", \"hudson.slaves.RetentionStrategy\$Always\"], \
203 \"launcher\": {\
204 \"stapler-class\": \"hudson.plugins.sshslaves.SSHLauncher\", \
205 \"\$class\": \"hudson.plugins.sshslaves.SSHLauncher\", \
206 \"host\": \"'\"${jenkins_slave_ip}\"'\", \
207 \"credentialsId\": \"'\"\$ACCESS_JENKINS_NODE_CREDENTIALS\"'\", \
208 \"port\": \"'\"22\"'\", \
209 \"javaPath\": \"\", \
210 \"jvmOptions\": \"\", \
211 \"prefixStartSlaveCmd\": \"\", \
212 \"suffixStartSlaveCmd\": \"\", \
213 \"launchTimeoutSeconds\": \"\", \
214 \"maxNumRetries\": \"\", \
215 \"retryWaitTime\": \"\", \
216 \"sshHostKeyVerificationStrategy\": {\
217 \"\$class\": \"hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy\" \
218 }, \
219 \"tcpNoDelay\": \"true\"\
220 }, \
221 \"retentionStrategy\": {\
222 \"stapler-class\": \"hudson.slaves.RetentionStrategy\$Always\", \
223 \"\$class\": \"hudson.slaves.RetentionStrategy\$Always\"\
224 }, \
225 \"nodeProperties\": {\
226 \"stapler-class-bag\": \"true\"\
227 }, \
228 \"type\": \"hudson.slaves.DumbSlave\", \
229 \"crumb\": \"'\"\$CRUMB\"'\"}' \
230 \"\${JENKINS_URL}/computer/doCreateItem?name=\${JENKINS_SLAVE_NODE_NAME}&type=hudson.slaves.DumbSlave\"
231 """)
232 shared.verbose_sh(script_delete_agent, true, false, true)
233 shared.verbose_sh(script_create_agent, true, false, true)
234
235 } // withCredentials
236
237 }// stage
238
239 } // withCredentials
240 } // dir
241} // node
242
243
244node ("${JENKINS_SLAVE_NODE_NAME}") {
245 dir("${PARENT_WORKSPACE}") {
246
247 stage("Clean the environment and clone tcp-qa") {
248 deleteDir()
249 shared.run_cmd("""\
250 git clone https://github.com/Mirantis/tcp-qa.git ${PARENT_WORKSPACE}
251 """)
252 shared.update_working_dir()
253 }
254
255 withCredentials([
256 [$class : 'UsernamePasswordMultiBinding',
257 credentialsId : env.OS_CREDENTIALS,
258 passwordVariable: 'OS_PASSWORD',
259 usernameVariable: 'OS_USERNAME']
260 ]) {
261
262
263 stage("Run the 'underlay' and 'salt-deployed' fixtures to bootstrap salt cluster") {
264 def xml_report_name = "deploy_salt.xml"
265 try {
266 // deploy_salt.xml
267 shared.run_sh("""\
268 export ENV_NAME=${ENV_NAME}
269 export LAB_CONFIG_NAME=${LAB_CONFIG_NAME}
270 export LAB_PARAM_DEFAULTS=${LAB_PARAM_DEFAULTS}
271 export ENV_MANAGER=heat
272 export SHUTDOWN_ENV_ON_TEARDOWN=false
273 export BOOTSTRAP_TIMEOUT=3600
274 export PYTHONIOENCODING=UTF-8
275 export REPOSITORY_SUITE=${MCP_VERSION}
276 export TEST_GROUP=test_bootstrap_salt
277 py.test -vvv -s -p no:django -p no:ipdb --junit-xml=${xml_report_name} -k \${TEST_GROUP}
278 """)
279 // Wait for jenkins to start and IO calm down
280 sleep(60)
281
282 } catch (e) {
283 common.printMsg("Saltstack cluster deploy is failed", "purple")
284 if (fileExists(xml_report_name)) {
285 shared.download_logs("deploy_salt_${ENV_NAME}")
286 def String junit_report_xml = readFile(xml_report_name)
287 def String junit_report_xml_pretty = new XmlUtil().serialize(junit_report_xml)
288 throw new Exception(junit_report_xml_pretty)
289 } else {
290 throw e
291 }
292 } finally {
293 // TODO(ddmitriev): add checks for salt cluster
294 }
295 } // stage
296 } // withCredentials
297 } // dir
298} // node