blob: 7281677299c0ecf8a67b7242b93462a980d3b51e [file] [log] [blame]
Ales Komarek24097402017-05-22 16:28:10 +02001/**
2 *
Tomáš Kukrál0d00dd22017-07-27 14:28:36 +02003 * Launch stack and work with it
Ales Komarek24097402017-05-22 16:28:10 +02004 *
5 * Expected parameters:
6 * STACK_NAME Infrastructure stack name
Tomáš Kukrál4691f682017-07-27 16:36:12 +02007 * STACK_TEMPLATE File with stack template
8 * STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started
Ales Komarek24097402017-05-22 16:28:10 +02009 *
10 * STACK_TEMPLATE_URL URL to git repo with stack templates
11 * STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo
12 * STACK_TEMPLATE_BRANCH Stack templates repo branch
13 *
14 * STACK_DELETE Delete stack when finished (bool)
Tomáš Kukrál4691f682017-07-27 16:36:12 +020015 * STACK_REUSE Reuse existing stack (don't create one, only read outputs)
Ales Komarek24097402017-05-22 16:28:10 +020016 * STACK_INSTALL What should be installed (k8s, openstack, ...)
17 * STACK_TEST Run tests (bool)
18 * STACK_CLEANUP_JOB Name of job for deleting stack
19 *
Tomáš Kukrál74f92862017-06-05 19:18:43 +020020 * STACK_COMPUTE_COUNT Number of compute nodes to launch
Vasyl Saienkoa81e9312018-03-06 01:28:35 +020021 * STACK_CLUSTER_NAME The name of cluster model to use
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010022 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020023 *
Ales Komarek24097402017-05-22 16:28:10 +020024 * AWS_STACK_REGION CloudFormation AWS region
25 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020026 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020027 *
28 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
29 * HEAT_STACK_ZONE Heat stack availability zone
30 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
31 * OPENSTACK_API_URL OpenStack API address
32 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
33 * OPENSTACK_API_PROJECT OpenStack project to connect to
34 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
35 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030036 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020037
Ales Komarek24097402017-05-22 16:28:10 +020038 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020039 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020040 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020041
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020042 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
43 * which have to be added during bootstrap.
44 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
45
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020046 * Test settings:
47 * TEST_K8S_API_SERVER Kubernetes API address
48 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020049 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020050 * TEST_DOCKER_INSTALL Install docker on the target if true
51 * TEST_TEMPEST_IMAGE Tempest image link
52 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
53 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040054 * TESTRAIL_REPORT Whether upload results to testrail or not
55 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
56 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
57 * TESTRAIL_MILESTONE Product version for tests
58 * TESTRAIL_PLAN Testrail test plan
59 * TESTRAIL_GROUP Testrail test group
60 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020061 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020062 * optional parameters for overwriting soft params
63 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020064 *
65 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020066
Ales Komarek24097402017-05-22 16:28:10 +020067common = new com.mirantis.mk.Common()
68git = new com.mirantis.mk.Git()
69openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020070aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020071orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030072python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020073salt = new com.mirantis.mk.Salt()
74test = new com.mirantis.mk.Test()
75
76_MAX_PERMITTED_STACKS = 2
77overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
78
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020080def venv
chnyda597fb032017-10-06 13:42:48 +020081def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020082def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020083
chnydae14058a2017-08-29 15:07:48 +020084def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
85
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020086if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020087 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020088} else if (STACK_TYPE == 'heat') {
89 def envParams
90 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020091}
92
Oleh Hryhorov9630a762017-10-24 14:33:25 +030093def slave_node = 'python'
94
Oleh Hryhorov54460512017-10-26 18:45:36 +030095if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030096 slave_node = SLAVE_NODE
97}
Jakub Josefa63f9862018-01-11 17:58:38 +010098timeout(time: 12, unit: 'HOURS') {
99 node(slave_node) {
100 try {
101 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100102 def workspace = common.getWorkspace()
103 venv = "${workspace}/venv"
104 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100105 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
106 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
107 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100108 //
109 // Prepare machines
110 //
111 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200112
Jakub Josefa63f9862018-01-11 17:58:38 +0100113 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 if (STACK_TYPE == 'heat') {
116 // value defaults
117 envParams = [
118 'cluster_zone': HEAT_STACK_ZONE,
119 'cluster_public_net': HEAT_STACK_PUBLIC_NET
120 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
123 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400124 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200125
Jakub Josefa63f9862018-01-11 17:58:38 +0100126 if (STACK_REUSE.toBoolean() == false) {
127 // Don't allow to set custom heat stack name
128 wrap([$class: 'BuildUser']) {
129 if (env.BUILD_USER_ID) {
130 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
131 } else {
132 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
133 }
134 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200135 }
136 }
137
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400138 // no underscore in STACK_NAME
139 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200141
Jakub Josefa63f9862018-01-11 17:58:38 +0100142 // set description
143 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400144
Ales Komarek24097402017-05-22 16:28:10 +0200145 // get templates
146 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
147
Jakub Josefa63f9862018-01-11 17:58:38 +0100148 // create openstack env
149 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100150 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100151 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
152 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
153 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
154 OPENSTACK_API_VERSION)
155 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200156
Jakub Josefa63f9862018-01-11 17:58:38 +0100157 //
158 // Verify possibility of create stack for given user and stack type
159 //
160 wrap([$class: 'BuildUser']) {
161 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
162 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
163 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
164 STACK_DELETE = "false"
165 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
166 }
167 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200168 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100169 // launch stack
170 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400171
Jakub Josefa63f9862018-01-11 17:58:38 +0100172 // set reclass repo in heat env
173 try {
174 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
175 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
176 } catch (MissingPropertyException e) {
177 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100178 }
179
Jakub Josefa63f9862018-01-11 17:58:38 +0100180 // put formulas revision - stable, testing or nightly
181 if (common.validInputParam('FORMULA_PKG_REVISION')) {
182 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
183 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
184 }
185
186 // put extra repo definitions
187 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
188 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
189 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
190 }
191
192 // put extra salt-formulas
193 if (common.validInputParam('EXTRA_FORMULAS')) {
194 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
195 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
196 }
197
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200198 // add cluster name if specified
199 if (common.validInputParam('STACK_CLUSTER_NAME')) {
200 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
201 envParams.put('cluster_name', STACK_CLUSTER_NAME)
202 }
203
Jakub Josefa63f9862018-01-11 17:58:38 +0100204 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
205 }
206
207 // get SALT_MASTER_URL
208 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
209 // check that saltMasterHost is valid
210 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
211 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
212 throw new Exception("saltMasterHost is not a valid ip")
213 }
214
215 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
216
217 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
218
219 } else if (STACK_TYPE == 'aws') {
220
221 // setup environment
222 aws.setupVirtualEnv(venv)
223
224 // set aws_env_vars
225 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
226
227 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
228 error("If you want to reuse existing stack you need to provide it's name")
229 }
230
231 if (STACK_REUSE.toBoolean() == false) {
232 // Don't allow to set custom stack name
233 wrap([$class: 'BuildUser']) {
234 if (env.BUILD_USER_ID) {
235 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
236 } else {
237 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
238 }
239 }
240
241 // no underscore in STACK_NAME
242 STACK_NAME = STACK_NAME.replaceAll('_', '-')
243 }
244
245 // set description
246 currentBuild.description = STACK_NAME
247 outputs.put('stack_name', STACK_NAME)
248
249 if (STACK_REUSE.toBoolean() == false) {
250 // get templates
251 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
252
253 // start stack
254 def stack_params = [
255 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
256 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
257 ]
258 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
259 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
260 }
261
262 // wait for stack to be ready
263 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
264
265 // get outputs
266 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
267
268 // check that saltMasterHost is valid
269 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
270 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
271 throw new Exception("saltMasterHost is not a valid ip")
272 }
273
274 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
275 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
276
277 } else if (STACK_TYPE != 'physical') {
278 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
279 }
280
281 outputs.put('salt_api', SALT_MASTER_URL)
282
283 // Setup virtualenv for pepper
284 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
285 }
286
287
288 // Set up override params
289 if (common.validInputParam('SALT_OVERRIDES')) {
290 stage('Set Salt overrides') {
291 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
292 }
293 }
294
295 //
296 // Install
297 //
298
299 if (common.checkContains('STACK_INSTALL', 'core')) {
300 stage('Install core infrastructure') {
301 def staticMgmtNetwork = false
302 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
303 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
304 }
305 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
306
307 if (common.checkContains('STACK_INSTALL', 'kvm')) {
308 orchestrate.installInfraKvm(venvPepper)
309 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
310 }
311
312 orchestrate.validateFoundationInfra(venvPepper)
313 }
314 }
315
316 // install k8s
317 if (common.checkContains('STACK_INSTALL', 'k8s')) {
318
319 stage('Install Kubernetes infra') {
320 if (STACK_TYPE == 'aws') {
321 // configure kubernetes_control_address - save loadbalancer
322 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
323 common.prettyPrint(awsOutputs)
324 if (awsOutputs.containsKey('ControlLoadBalancer')) {
325 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
326 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
327 }
328 }
329
330 // ensure certificates are generated properly
331 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
332 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
333
334 orchestrate.installKubernetesInfra(venvPepper)
335 }
336
337 if (common.checkContains('STACK_INSTALL', 'contrail')) {
338 stage('Install Contrail for Kubernetes') {
339 orchestrate.installContrailNetwork(venvPepper)
340 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200341 }
Ales Komarek24097402017-05-22 16:28:10 +0200342 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100343
Jakub Josefa63f9862018-01-11 17:58:38 +0100344 stage('Install Kubernetes control') {
345 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400346
Jakub Josefa63f9862018-01-11 17:58:38 +0100347 // collect artifacts (kubeconfig)
348 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
349 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400350 }
351
Jakub Josefa63f9862018-01-11 17:58:38 +0100352 stage('Install Kubernetes computes') {
353 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
354 if (STACK_COMPUTE_COUNT > 0) {
355 if (STACK_TYPE == 'aws') {
356 // get stack info
357 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
358
359 //update autoscaling group
360 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
361
362 // wait for computes to boot up
363 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
364 sleep(60)
365
366 } else if (STACK_TYPE == 'heat') {
367 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
368
369 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
370 sleep(60)
371 }
372
373 }
374 }
375
376 orchestrate.installKubernetesCompute(venvPepper)
377 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400378 }
Ales Komarek24097402017-05-22 16:28:10 +0200379
Jakub Josefa63f9862018-01-11 17:58:38 +0100380 // install openstack
381 if (common.checkContains('STACK_INSTALL', 'openstack')) {
382 // install Infra and control, tests, ...
383
384 stage('Install OpenStack infra') {
385 orchestrate.installOpenstackInfra(venvPepper)
386 }
387
388 stage('Install OpenStack control') {
389 orchestrate.installOpenstackControl(venvPepper)
390 }
391
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200392 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
393 // More details: https://mirantis.jira.com/browse/PROD-17765
394 salt.runSaltProcessStep(venvPepper, 'I@keystone:client', 'service.restart', ['salt-minion'])
395 salt.minionsReachable(venvPepper, 'I@salt:master and *01*', 'I@keystone:client', null, 10, 6)
396
Jakub Josefa63f9862018-01-11 17:58:38 +0100397 stage('Install OpenStack network') {
398
399 if (common.checkContains('STACK_INSTALL', 'contrail')) {
400 orchestrate.installContrailNetwork(venvPepper)
401 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
402 orchestrate.installOpenstackNetwork(venvPepper)
403 }
404
Oleh Hryhorov89da0502018-02-13 16:57:46 +0200405 salt.cmdRun(venvPepper, 'I@keystone:server', '. /root/keystonercv3; openstack network list')
Jakub Josefa63f9862018-01-11 17:58:38 +0100406 }
407
408 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
409 stage('Install OpenStack Ironic conductor') {
410 orchestrate.installIronicConductor(venvPepper)
411 }
412 }
413
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200414 if (salt.testTarget(venvPepper, 'I@manila:share')){
415 stage('Install OpenStack Manila data and share') {
416 orchestrate.installManilaShare(venvPepper)
417 }
418 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100419
420 stage('Install OpenStack compute') {
421 orchestrate.installOpenstackCompute(venvPepper)
422
423 if (common.checkContains('STACK_INSTALL', 'contrail')) {
424 orchestrate.installContrailCompute(venvPepper)
425 }
426 }
427
428 }
429
430 // install ceph
431 if (common.checkContains('STACK_INSTALL', 'ceph')) {
432 stage('Install Ceph MONs') {
433 orchestrate.installCephMon(venvPepper)
434 }
435
436 stage('Install Ceph OSDs') {
437 orchestrate.installCephOsd(venvPepper)
438 }
439
440
441 stage('Install Ceph clients') {
442 orchestrate.installCephClient(venvPepper)
443 }
444
445 stage('Connect Ceph') {
446 orchestrate.connectCeph(venvPepper)
447 }
448 }
449
450 if (common.checkContains('STACK_INSTALL', 'oss')) {
451 stage('Install Oss infra') {
452 orchestrate.installOssInfra(venvPepper)
453 }
454 }
455
456 if (common.checkContains('STACK_INSTALL', 'cicd')) {
457 stage('Install Cicd') {
458 orchestrate.installInfra(venvPepper)
459 orchestrate.installDockerSwarm(venvPepper)
460 orchestrate.installCicd(venvPepper)
461 }
462 }
463
464 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
465 stage('Install StackLight v1') {
466 orchestrate.installStacklightv1Control(venvPepper)
467 orchestrate.installStacklightv1Client(venvPepper)
468 }
469 }
470
471 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
472 stage('Install StackLight') {
473 orchestrate.installDockerSwarm(venvPepper)
474 orchestrate.installStacklight(venvPepper)
475 }
476 }
477
478 if (common.checkContains('STACK_INSTALL', 'oss')) {
479 stage('Install OSS') {
480 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
481 // In case if StackLightv2 enabled containers already started
482 orchestrate.installDockerSwarm(venvPepper)
483 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
484 }
485 orchestrate.installOss(venvPepper)
486 }
487 }
488
489 //
490 // Test
491 //
492 def artifacts_dir = '_artifacts/'
493
494 if (common.checkContains('STACK_TEST', 'k8s')) {
495 stage('Run k8s conformance e2e tests') {
496 def image = TEST_K8S_CONFORMANCE_IMAGE
497 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400498 def target = 'ctl01*'
499 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100500
501 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400502 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100503
504 // collect output
505 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400506 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100507 writeFile file: "${artifacts_dir}${output_file}", text: file_content
508 sh "cat ${artifacts_dir}${output_file}"
509
510 // collect artifacts
511 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400512
513 // Copy test results
514 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100515 }
516 }
517
518 if (common.checkContains('STACK_TEST', 'openstack')) {
519 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
520 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
521 }
522 stage('Run OpenStack tests') {
523 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
524 }
525
526 stage('Copy Tempest results to config node') {
527 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
528 }
529
530 stage('Archive rally artifacts') {
531 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200532 }
ibumarskov637a2152018-01-16 10:39:57 +0400533
534 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
535 stage('Upload test results to TestRail') {
536 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
537 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
538 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
539
540 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
541 test.uploadResultsTestrail("/root/rally_reports/report.xml",
542 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
543 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
544 }
545 }
Ales Komarek24097402017-05-22 16:28:10 +0200546 }
547
Ales Komarek24097402017-05-22 16:28:10 +0200548
Jakub Josefa63f9862018-01-11 17:58:38 +0100549 if (common.checkContains('STACK_TEST', 'ceph')) {
550 stage('Run infra tests') {
551 sleep(120)
552 def cmd = "apt-get install -y python-pip && pip install -r /usr/share/salt-formulas/env/ceph/files/testinfra/requirements.txt && python -m pytest --junitxml=/root/report.xml /usr/share/salt-formulas/env/ceph/files/testinfra/"
553 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
554 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
555 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200556 }
557 }
558
Jakub Josefa63f9862018-01-11 17:58:38 +0100559 if (common.checkContains('STACK_TEST', 'opencontrail')) {
560 stage('Run opencontrail tests') {
561 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
562 def report_dir = "/opt/opencontrail-test-report/"
563 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
564 "cd ${opencontrail_tests_dir} && " +
565 "py.test --junit-xml=${report_dir}report.xml" +
566 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400567
Jakub Josefa63f9862018-01-11 17:58:38 +0100568 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
569 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100570
Jakub Josefa63f9862018-01-11 17:58:38 +0100571 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
572
573 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
574 'I@opencontrail:test', "${report_dir}report.xml"))
575 junit(keepLongStdio: true, testResults: 'report.xml')
576 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100577 }
578
579
Jakub Josefa63f9862018-01-11 17:58:38 +0100580 stage('Finalize') {
581 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100582 def gluster_compound = 'I@glusterfs:server'
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200583 def salt_ca_compound = 'I@salt:minion:ca:salt_master_ca'
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100584 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200585 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100586 // Iterate over nonempty set of gluster servers and apply highstates one by one
587 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200588 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
589 if ( !saltcaMinions.isEmpty() ) {
590 for ( target in saltcaMinions ) {
591 salt.enforceHighstate(venvPepper, target)
592 }
593 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100594 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
595 if ( !glusterMinions.isEmpty() ) {
596 for ( target in glusterMinions ) {
597 salt.enforceHighstate(venvPepper, target)
598 }
599 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100600 }
601
602 outputsPretty = common.prettify(outputs)
603 print(outputsPretty)
604 writeFile(file: 'outputs.json', text: outputsPretty)
605 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100606 }
607
Jakub Josefa63f9862018-01-11 17:58:38 +0100608 } catch (Throwable e) {
609 currentBuild.result = 'FAILURE'
610 throw e
611 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100612
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400613
Jakub Josefa63f9862018-01-11 17:58:38 +0100614 //
615 // Clean
616 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400617
Jakub Josefa63f9862018-01-11 17:58:38 +0100618 if (common.validInputParam('STACK_NAME')) {
619 // send notification
620 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200621 }
622
Jakub Josefa63f9862018-01-11 17:58:38 +0100623 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
624 stage('Trigger cleanup job') {
625 common.errorMsg('Stack cleanup job triggered')
626 build(job: STACK_CLEANUP_JOB, parameters: [
627 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
628 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
629 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
630 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
631 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
632 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
633 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
634 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
635 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
636 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
637 ])
638 }
639 } else {
640 if (currentBuild.result == 'FAILURE') {
641 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Vasyl Saienkoff24e582017-08-04 10:04:33 +0300642
Jakub Josefa63f9862018-01-11 17:58:38 +0100643 if (common.validInputParam('SALT_MASTER_URL')) {
644 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
645 }
Ales Komarek24097402017-05-22 16:28:10 +0200646 }
647 }
648 }
649 }
650}