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