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