blob: 9143b9702cb6f688a0383a77880a0e574a6abb41 [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
Oleh Hryhorov825b5be2018-06-13 13:01:53 +030046 * SALT_VERSION Version of Salt which is going to be installed i.e. 'stable 2016.3' or 'stable 2017.7' etc.
47 *
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +030048 * EXTRA_TARGET The value will be added to target nodes
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040049 * BATCH_SIZE Use batching for states, which may be targeted for huge amount of nodes. Format:
50 - 10 - number of nodes
51 - 10% - percentage of all targeted nodes
Ivan Berezovskiycf960672020-01-27 14:25:31 +040052 * DIST_UPGRADE_NODES Whether to run "apt-get dist-upgrade" on all nodes in cluster before deployment
Denis Egorenkoca6aeca2019-08-19 19:41:27 +040053
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +030054 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020055 * Test settings:
56 * TEST_K8S_API_SERVER Kubernetes API address
57 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020058 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020059 * TEST_DOCKER_INSTALL Install docker on the target if true
60 * TEST_TEMPEST_IMAGE Tempest image link
61 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
62 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040063 * TESTRAIL_REPORT Whether upload results to testrail or not
64 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
65 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
66 * TESTRAIL_MILESTONE Product version for tests
67 * TESTRAIL_PLAN Testrail test plan
68 * TESTRAIL_GROUP Testrail test group
69 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020070 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020071 * optional parameters for overwriting soft params
72 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020073 *
74 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020075
Ales Komarek24097402017-05-22 16:28:10 +020076common = new com.mirantis.mk.Common()
77git = new com.mirantis.mk.Git()
78openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020079aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020080orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030081python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020082salt = new com.mirantis.mk.Salt()
83test = new com.mirantis.mk.Test()
Ivan Berezovskiycf960672020-01-27 14:25:31 +040084debian = new com.mirantis.mk.Debian()
Ales Komarek24097402017-05-22 16:28:10 +020085
86_MAX_PERMITTED_STACKS = 2
87overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
88
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020089// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020090def venv
chnyda597fb032017-10-06 13:42:48 +020091def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020092def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020093
chnydae14058a2017-08-29 15:07:48 +020094def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
95
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020096if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020097 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020098} else if (STACK_TYPE == 'heat') {
99 def envParams
100 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +0200101}
102
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300103def slave_node = 'python'
104
Oleh Hryhorov54460512017-10-26 18:45:36 +0300105if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300106 slave_node = SLAVE_NODE
107}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300108
109def extra_tgt = ''
110if (common.validInputParam('EXTRA_TARGET')) {
111 extra_tgt = "${EXTRA_TARGET}"
112}
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400113def batch_size = ''
114if (common.validInputParam('BATCH_SIZE')) {
115 batch_size = "${BATCH_SIZE}"
116}
Ivan Berezovskiycf960672020-01-27 14:25:31 +0400117def upgrade_nodes = false
118if (common.validInputParam('DIST_UPGRADE_NODES')) {
119 upgrade_nodes = "${DIST_UPGRADE_NODES}".toBoolean()
120}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122timeout(time: 12, unit: 'HOURS') {
123 node(slave_node) {
124 try {
125 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100126 def workspace = common.getWorkspace()
127 venv = "${workspace}/venv"
128 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100129 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
130 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
131 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100132 //
133 // Prepare machines
134 //
135 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200136
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200138
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 if (STACK_TYPE == 'heat') {
140 // value defaults
141 envParams = [
142 'cluster_zone': HEAT_STACK_ZONE,
143 'cluster_public_net': HEAT_STACK_PUBLIC_NET
144 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200145
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
147 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400148 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200149
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 if (STACK_REUSE.toBoolean() == false) {
151 // Don't allow to set custom heat stack name
152 wrap([$class: 'BuildUser']) {
153 if (env.BUILD_USER_ID) {
154 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
155 } else {
156 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
157 }
158 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200159 }
Inessa Vasilevskaya7fd23f22018-10-09 10:58:46 +0200160 } else {
161 // In case name was copied with unicode zero-width space chars -
162 // remove them
163 STACK_NAME = STACK_NAME.trim().replaceAll("\\p{C}", "")
Ales Komarek24097402017-05-22 16:28:10 +0200164 }
165
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400166 // no underscore in STACK_NAME
167 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200169
Jakub Josefa63f9862018-01-11 17:58:38 +0100170 // set description
171 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400172
Ales Komarek24097402017-05-22 16:28:10 +0200173 // get templates
174 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
175
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 // create openstack env
177 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100178 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100179 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
180 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
181 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
182 OPENSTACK_API_VERSION)
183 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200184
Jakub Josefa63f9862018-01-11 17:58:38 +0100185 //
186 // Verify possibility of create stack for given user and stack type
187 //
188 wrap([$class: 'BuildUser']) {
189 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
190 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
191 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
192 STACK_DELETE = "false"
193 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
194 }
195 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200196 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100197 // launch stack
198 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400199
Jakub Josefa63f9862018-01-11 17:58:38 +0100200 // set reclass repo in heat env
201 try {
202 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
203 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
204 } catch (MissingPropertyException e) {
205 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 +0100206 }
207
Jakub Josefa63f9862018-01-11 17:58:38 +0100208 // put formulas revision - stable, testing or nightly
209 if (common.validInputParam('FORMULA_PKG_REVISION')) {
210 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
211 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
212 }
213
214 // put extra repo definitions
215 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
216 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
217 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
218 }
219
azvyagintsevb8ddb492018-09-12 14:59:45 +0300220 // put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127
Jakub Josefa63f9862018-01-11 17:58:38 +0100221 if (common.validInputParam('EXTRA_FORMULAS')) {
222 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
223 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
224 }
225
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200226 // add cluster name if specified
227 if (common.validInputParam('STACK_CLUSTER_NAME')) {
228 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
229 envParams.put('cluster_name', STACK_CLUSTER_NAME)
230 }
231
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300232 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
233 if (STACK_COMPUTE_COUNT.toInteger() > 0){
234 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
235 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
236 }
237 }
238
Oleh Hryhorov825b5be2018-06-13 13:01:53 +0300239
240 if (common.validInputParam('SALT_VERSION')) {
241 common.infoMsg("Setting salt version to ${SALT_VERSION}")
242 envParams.put('cfg_saltversion', SALT_VERSION)
243 }
244
Mykyta Karpin35f71332018-07-27 11:54:51 +0300245 // If stack wasn't removed by the same user which has created it,
246 // nova key pair won't be removed, so need to make sure that no
247 // key pair with the same name exists before creating the stack.
248 if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
249 try {
250 openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
251 } catch (Exception e) {
252 common.errorMsg("Key pair failed to remove with error ${e.message}")
253 }
254 }
255
Jakub Josefa63f9862018-01-11 17:58:38 +0100256 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
257 }
258
259 // get SALT_MASTER_URL
260 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
261 // check that saltMasterHost is valid
262 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
263 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
264 throw new Exception("saltMasterHost is not a valid ip")
265 }
266
267 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
268
269 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
270
271 } else if (STACK_TYPE == 'aws') {
272
273 // setup environment
274 aws.setupVirtualEnv(venv)
275
276 // set aws_env_vars
277 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
278
279 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
280 error("If you want to reuse existing stack you need to provide it's name")
281 }
282
283 if (STACK_REUSE.toBoolean() == false) {
284 // Don't allow to set custom stack name
285 wrap([$class: 'BuildUser']) {
286 if (env.BUILD_USER_ID) {
287 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
288 } else {
289 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
290 }
291 }
292
293 // no underscore in STACK_NAME
294 STACK_NAME = STACK_NAME.replaceAll('_', '-')
295 }
296
297 // set description
298 currentBuild.description = STACK_NAME
299 outputs.put('stack_name', STACK_NAME)
300
301 if (STACK_REUSE.toBoolean() == false) {
302 // get templates
303 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
304
305 // start stack
306 def stack_params = [
307 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
308 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
309 ]
310 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
311 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
312 }
313
314 // wait for stack to be ready
315 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
316
317 // get outputs
318 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
319
320 // check that saltMasterHost is valid
321 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
322 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
323 throw new Exception("saltMasterHost is not a valid ip")
324 }
325
326 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
327 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
328
329 } else if (STACK_TYPE != 'physical') {
330 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
331 }
332
333 outputs.put('salt_api', SALT_MASTER_URL)
334
335 // Setup virtualenv for pepper
336 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
337 }
338
339
340 // Set up override params
341 if (common.validInputParam('SALT_OVERRIDES')) {
342 stage('Set Salt overrides') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300343 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100344 }
345 }
346
347 //
348 // Install
349 //
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400350 if (!batch_size) {
Denis Egorenko7b098c32019-12-19 16:45:25 +0400351 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
352 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
353 // do not use toDouble/Double as it requires additional approved method
354 def workerThreads = salt.getWorkerThreads(venvPepper).toInteger()
355 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400356 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100357
Martin Polreichacc8b192019-03-28 12:50:57 +0100358 // Check if all minions are reachable and ready
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400359 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': '*', batch: batch_size])
Martin Polreichacc8b192019-03-28 12:50:57 +0100360
Jakub Josefa63f9862018-01-11 17:58:38 +0100361 if (common.checkContains('STACK_INSTALL', 'core')) {
362 stage('Install core infrastructure') {
363 def staticMgmtNetwork = false
364 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
365 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
366 }
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400367 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100368
369 if (common.checkContains('STACK_INSTALL', 'kvm')) {
Ivan Berezovskiycf960672020-01-27 14:25:31 +0400370 if (upgrade_nodes) {
371 debian.osUpgradeNode(venvPepper, 'I@salt:control', 'dist-upgrade', 30, 20, batch_size)
372 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'I@salt:control', wait: 60, timeout: 10])
373 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300374 orchestrate.installInfraKvm(venvPepper, extra_tgt)
Ivan Berezovskiycf960672020-01-27 14:25:31 +0400375 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100376 }
377
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300378 orchestrate.validateFoundationInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100379 }
Ivan Berezovskiycf960672020-01-27 14:25:31 +0400380 if (upgrade_nodes) {
381 debian.osUpgradeNode(venvPepper, 'not ( I@salt:master or I@salt:control )', 'dist-upgrade', false, 30, 10, batch_size)
382 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'not ( I@salt:master or I@salt:control )', wait: 60, timeout: 10])
383 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100384 }
385
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300386 stage('Install infra') {
387 if (common.checkContains('STACK_INSTALL', 'core') ||
388 common.checkContains('STACK_INSTALL', 'openstack') ||
Denis Egorenko9b7f0972019-11-07 20:42:43 +0400389 common.checkContains('STACK_INSTALL', 'oss') ||
390 common.checkContains('STACK_INSTALL', 'cicd')) {
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300391 orchestrate.installInfra(venvPepper, extra_tgt)
392 }
393 }
394
Vasyl Saienko4c78fe12018-08-06 10:17:28 +0300395 stage('Install Orchestrated Apps'){
396 orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications")
397 }
398
Jakub Josefa63f9862018-01-11 17:58:38 +0100399 // install k8s
400 if (common.checkContains('STACK_INSTALL', 'k8s')) {
401
402 stage('Install Kubernetes infra') {
403 if (STACK_TYPE == 'aws') {
404 // configure kubernetes_control_address - save loadbalancer
405 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
406 common.prettyPrint(awsOutputs)
407 if (awsOutputs.containsKey('ControlLoadBalancer')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300408 salt.runSaltProcessStep(venvPepper, "I@salt:master ${extra_tgt}", 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100409 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
410 }
411 }
412
413 // ensure certificates are generated properly
Andrey Shestakovf23ed002018-08-21 12:09:51 +0300414 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
415 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100416 }
417
418 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200419 stage('Install Contrail control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300420 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200421 }
Ales Komarek24097402017-05-22 16:28:10 +0200422 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100423
Jakub Josefa63f9862018-01-11 17:58:38 +0100424 stage('Install Kubernetes control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300425 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
Anton Samoylove53f9382019-01-23 20:22:26 +0400426 if (common.checkContains('STACK_INSTALL', 'contrail')) {
427 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
428 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400429
Jakub Josefa63f9862018-01-11 17:58:38 +0100430 // collect artifacts (kubeconfig)
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300431 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config'))
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400433 }
434
Svimbaa554ea02018-06-06 18:45:23 +0200435 if (common.checkContains('STACK_INSTALL', 'contrail')) {
436 stage('Install Contrail compute') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300437 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Svimbaa554ea02018-06-06 18:45:23 +0200438 }
439 }
440
Jakub Josefa63f9862018-01-11 17:58:38 +0100441 stage('Install Kubernetes computes') {
442 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
443 if (STACK_COMPUTE_COUNT > 0) {
444 if (STACK_TYPE == 'aws') {
445 // get stack info
446 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
447
448 //update autoscaling group
449 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
450
451 // wait for computes to boot up
452 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
453 sleep(60)
454
455 } else if (STACK_TYPE == 'heat') {
456 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
457
458 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
459 sleep(60)
460 }
461
462 }
463 }
464
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300465 orchestrate.installKubernetesCompute(venvPepper, extra_tgt)
Svimbaa979f8f2018-09-26 11:24:49 +0200466 // Setup kubernetes addons for opencontrail. More info in the definition of the func.
467 orchestrate.setupKubeAddonForContrail(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100468 }
Vasyl Saienkocdf8b292019-03-05 10:56:29 +0200469 orchestrate.installKubernetesClient(venvPepper, extra_tgt)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400470 }
Ales Komarek24097402017-05-22 16:28:10 +0200471
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300472 // install ceph
473 if (common.checkContains('STACK_INSTALL', 'ceph')) {
474 stage('Install Ceph MONs') {
475 orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt)
476 }
477
478 stage('Install Ceph OSDs') {
479 orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt)
480 }
481
482 stage('Install Ceph clients') {
483 orchestrate.installCephClient(venvPepper, extra_tgt)
484 }
485 }
486
Vasyl Saienkoc562fc42018-12-15 22:19:28 +0200487 // install docker swarm
488 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
489
Jakub Josefa63f9862018-01-11 17:58:38 +0100490 // install openstack
491 if (common.checkContains('STACK_INSTALL', 'openstack')) {
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300492 // install control, tests, ...
Jakub Josefa63f9862018-01-11 17:58:38 +0100493 stage('Install OpenStack control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300494 orchestrate.installOpenstackControl(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100495 }
496
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200497 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
498 // More details: https://mirantis.jira.com/browse/PROD-17765
Ivan Berezovskiyddd0cbb2019-08-01 15:23:14 +0400499 salt.restartSaltMinion(venvPepper, "I@keystone:client ${extra_tgt}")
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400500 salt.minionsReachable(venvPepper, 'I@salt:master', 'I@keystone:client ${extra_tgt}', null, 10, 6)
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200501
Jakub Josefa63f9862018-01-11 17:58:38 +0100502 stage('Install OpenStack network') {
503
504 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300505 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Anton Samoylove53f9382019-01-23 20:22:26 +0400506 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100507 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300508 orchestrate.installOpenstackNetwork(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100509 }
510
Petr Jedinýefd668f2018-05-24 14:44:08 +0200511 // Wait for network to come up, 150s should be enough
512 common.retry(10, 15) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300513 salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list')
Petr Jedinýefd668f2018-05-24 14:44:08 +0200514 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100515 }
516
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300517 if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){
Jakub Josefa63f9862018-01-11 17:58:38 +0100518 stage('Install OpenStack Ironic conductor') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300519 orchestrate.installIronicConductor(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100520 }
521 }
522
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300523 if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200524 stage('Install OpenStack Manila data and share') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300525 orchestrate.installManilaShare(venvPepper, extra_tgt)
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200526 }
527 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100528
529 stage('Install OpenStack compute') {
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400530 orchestrate.installOpenstackCompute(venvPepper, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100531
532 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300533 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Inessa Vasilevskaya30cb7312018-10-08 12:13:03 +0200534 orchestrate.installBackup(venvPepper, 'contrail', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100535 }
536 }
537
538 }
539
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300540 // connect ceph
Jakub Josefa63f9862018-01-11 17:58:38 +0100541 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100542
543 stage('Connect Ceph') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300544 orchestrate.connectCeph(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100545 }
546 }
547
548 if (common.checkContains('STACK_INSTALL', 'oss')) {
549 stage('Install Oss infra') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300550 orchestrate.installOssInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100551 }
552 }
553
554 if (common.checkContains('STACK_INSTALL', 'cicd')) {
555 stage('Install Cicd') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300556 orchestrate.installCicd(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100557 }
558 }
559
560 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
561 stage('Install StackLight v1') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300562 orchestrate.installStacklightv1Control(venvPepper, extra_tgt)
563 orchestrate.installStacklightv1Client(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100564 }
565 }
566
567 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
568 stage('Install StackLight') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300569 orchestrate.installStacklight(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100570 }
571 }
572
573 if (common.checkContains('STACK_INSTALL', 'oss')) {
574 stage('Install OSS') {
575 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
576 // In case if StackLightv2 enabled containers already started
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300577 salt.enforceState(venvPepper, "I@docker:swarm:role:master and I@devops_portal:config ${extra_tgt}", 'docker.client', true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100578 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300579 orchestrate.installOss(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100580 }
581 }
582
583 //
584 // Test
585 //
586 def artifacts_dir = '_artifacts/'
587
588 if (common.checkContains('STACK_TEST', 'k8s')) {
589 stage('Run k8s conformance e2e tests') {
590 def image = TEST_K8S_CONFORMANCE_IMAGE
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400591 def autodetect = AUTODETECT
592 def ctl_target = 'I@kubernetes:master'
593 firstTarget = salt.getFirstMinion(venvPepper, ctl_target)
594 def containerd_enabled = salt.getPillar(
595 venvPepper, firstTarget, "kubernetes:common:containerd:enabled"
596 )["return"][0].values()[0].toBoolean()
597 if (containerd_enabled) {
598 def config = ['master': venvPepper,
599 'target': firstTarget,
600 'junitResults': true,
601 'autodetect': autodetect,
602 'image': image]
603 test.executeConformance(config)
604 } else {
605 def output_file = image.replaceAll('/', '-') + '.output'
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400606 def target = "I@keystone:server:role:primary ${extra_tgt}"
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400607 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100608
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400609 // run image
610 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100611
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400612 // collect output
613 sh "mkdir -p ${artifacts_dir}"
614 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
615 writeFile file: "${artifacts_dir}${output_file}", text: file_content
616 sh "cat ${artifacts_dir}${output_file}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100617
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400618 // collect artifacts
619 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400620
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400621 // Copy test results
622 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
623 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100624 }
625 }
626
627 if (common.checkContains('STACK_TEST', 'openstack')) {
628 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
629 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
630 }
631 stage('Run OpenStack tests') {
632 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
633 }
634
635 stage('Copy Tempest results to config node') {
636 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
637 }
638
639 stage('Archive rally artifacts') {
640 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200641 }
ibumarskov637a2152018-01-16 10:39:57 +0400642
643 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
644 stage('Upload test results to TestRail') {
645 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
646 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
647 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
648
649 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
650 test.uploadResultsTestrail("/root/rally_reports/report.xml",
651 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
652 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
653 }
654 }
Ales Komarek24097402017-05-22 16:28:10 +0200655 }
656
Ales Komarek24097402017-05-22 16:28:10 +0200657
Jakub Josefa63f9862018-01-11 17:58:38 +0100658 if (common.checkContains('STACK_TEST', 'ceph')) {
659 stage('Run infra tests') {
660 sleep(120)
661 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/"
662 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
663 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
664 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200665 }
666 }
667
Jakub Josefa63f9862018-01-11 17:58:38 +0100668 if (common.checkContains('STACK_TEST', 'opencontrail')) {
669 stage('Run opencontrail tests') {
670 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
671 def report_dir = "/opt/opencontrail-test-report/"
672 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
673 "cd ${opencontrail_tests_dir} && " +
674 "py.test --junit-xml=${report_dir}report.xml" +
675 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400676
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400677 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'saltutil.refresh_pillar', [], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100678 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100679
Jakub Josefa63f9862018-01-11 17:58:38 +0100680 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
681
682 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
683 'I@opencontrail:test', "${report_dir}report.xml"))
684 junit(keepLongStdio: true, testResults: 'report.xml')
685 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100686 }
687
688
Jakub Josefa63f9862018-01-11 17:58:38 +0100689 stage('Finalize') {
690 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300691 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
692 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100693 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Denis Egorenkoca6aeca2019-08-19 19:41:27 +0400694 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound, batch_size)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100695 // Iterate over nonempty set of gluster servers and apply highstates one by one
696 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200697 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
698 if ( !saltcaMinions.isEmpty() ) {
699 for ( target in saltcaMinions ) {
700 salt.enforceHighstate(venvPepper, target)
701 }
702 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100703 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
704 if ( !glusterMinions.isEmpty() ) {
705 for ( target in glusterMinions ) {
706 salt.enforceHighstate(venvPepper, target)
707 }
708 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100709 }
710
711 outputsPretty = common.prettify(outputs)
712 print(outputsPretty)
713 writeFile(file: 'outputs.json', text: outputsPretty)
714 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100715 }
716
Jakub Josefa63f9862018-01-11 17:58:38 +0100717 } catch (Throwable e) {
718 currentBuild.result = 'FAILURE'
719 throw e
720 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100721
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400722
Jakub Josefa63f9862018-01-11 17:58:38 +0100723 //
724 // Clean
725 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400726
Jakub Josefa63f9862018-01-11 17:58:38 +0100727 if (common.validInputParam('STACK_NAME')) {
728 // send notification
729 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200730 }
731
Jakub Josefa63f9862018-01-11 17:58:38 +0100732 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
733 stage('Trigger cleanup job') {
734 common.errorMsg('Stack cleanup job triggered')
735 build(job: STACK_CLEANUP_JOB, parameters: [
736 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
737 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
738 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
739 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
740 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
741 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
742 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
743 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
744 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
745 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
746 ])
747 }
748 } else {
749 if (currentBuild.result == 'FAILURE') {
750 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 +0300751
Jakub Josefa63f9862018-01-11 17:58:38 +0100752 if (common.validInputParam('SALT_MASTER_URL')) {
753 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
754 }
Ales Komarek24097402017-05-22 16:28:10 +0200755 }
756 }
757 }
758 }
759}