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