blob: 144f60427b7d544d3597ed810f6cfbd86ef6a2dc [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 Egorenko70002bc2019-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 Berezovskiy07adcde2020-01-27 14:25:31 +040052 * DIST_UPGRADE_NODES Whether to run "apt-get dist-upgrade" on all nodes in cluster before deployment
Denis Egorenko70002bc2019-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 Berezovskiy07adcde2020-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 = ''
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400110def extra_tgt_bckp = ''
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300111if (common.validInputParam('EXTRA_TARGET')) {
112 extra_tgt = "${EXTRA_TARGET}"
113}
Denis Egorenko70002bc2019-08-19 19:41:27 +0400114def batch_size = ''
115if (common.validInputParam('BATCH_SIZE')) {
116 batch_size = "${BATCH_SIZE}"
117}
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400118def upgrade_nodes = false
119if (common.validInputParam('DIST_UPGRADE_NODES')) {
120 upgrade_nodes = "${DIST_UPGRADE_NODES}".toBoolean()
121}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300122
Jakub Josefa63f9862018-01-11 17:58:38 +0100123timeout(time: 12, unit: 'HOURS') {
124 node(slave_node) {
125 try {
126 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100127 def workspace = common.getWorkspace()
128 venv = "${workspace}/venv"
129 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100130 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
131 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
132 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100133 //
134 // Prepare machines
135 //
136 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200137
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200139
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 if (STACK_TYPE == 'heat') {
141 // value defaults
142 envParams = [
143 'cluster_zone': HEAT_STACK_ZONE,
144 'cluster_public_net': HEAT_STACK_PUBLIC_NET
145 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200146
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
148 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400149 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200150
Jakub Josefa63f9862018-01-11 17:58:38 +0100151 if (STACK_REUSE.toBoolean() == false) {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200152 // TODO(vsaienko): remove stack creation from this pipeline to separate job
153 // Allow to set custom stack name but user-id will be added anyway
154 // This will fix issue with cleanup when job is aborted by jenkins and
155 // still guarantee stack count per user.
156 def stackNameSuffix = "${JOB_NAME}-${BUILD_NUMBER}"
157 if (STACK_NAME != ''){
158 stackNameSuffix = STACK_NAME
159 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100160 wrap([$class: 'BuildUser']) {
161 if (env.BUILD_USER_ID) {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200162 STACK_NAME = "${env.BUILD_USER_ID}-${stackNameSuffix}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100163 } else {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200164 STACK_NAME = "jenkins-${stackNameSuffix}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100165 }
166 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200167 }
Inessa Vasilevskaya7fd23f22018-10-09 10:58:46 +0200168 } else {
169 // In case name was copied with unicode zero-width space chars -
170 // remove them
171 STACK_NAME = STACK_NAME.trim().replaceAll("\\p{C}", "")
Ales Komarek24097402017-05-22 16:28:10 +0200172 }
173
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400174 // no underscore in STACK_NAME
175 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200177
Jakub Josefa63f9862018-01-11 17:58:38 +0100178 // set description
179 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400180
Ales Komarek24097402017-05-22 16:28:10 +0200181 // get templates
182 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
183
Jakub Josefa63f9862018-01-11 17:58:38 +0100184 // create openstack env
185 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100186 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100187 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
188 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
189 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
190 OPENSTACK_API_VERSION)
191 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200192
Jakub Josefa63f9862018-01-11 17:58:38 +0100193 //
194 // Verify possibility of create stack for given user and stack type
195 //
196 wrap([$class: 'BuildUser']) {
197 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
198 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
199 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
200 STACK_DELETE = "false"
201 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
202 }
203 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200204 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100205 // launch stack
206 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400207
Jakub Josefa63f9862018-01-11 17:58:38 +0100208 // set reclass repo in heat env
209 try {
210 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
211 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
212 } catch (MissingPropertyException e) {
213 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 +0100214 }
215
sgarbuz489ae3e2019-04-04 10:27:09 +0300216 // put reclass-system repo to branch/tag/ref. If empty will be used reclass pinned commit in AIO model.
217 if (common.validInputParam('RECLASS_SYSTEM_BRANCH')) {
218 common.infoMsg("Setting reclass-system repo to ${RECLASS_SYSTEM_BRANCH} branch/tag/ref")
219 envParams.put('cfg_reclass_system_branch', RECLASS_SYSTEM_BRANCH)
220 }
221
Jakub Josefa63f9862018-01-11 17:58:38 +0100222 // put formulas revision - stable, testing or nightly
223 if (common.validInputParam('FORMULA_PKG_REVISION')) {
224 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
225 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
226 }
227
228 // put extra repo definitions
229 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
230 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
231 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
232 }
233
azvyagintsevb8ddb492018-09-12 14:59:45 +0300234 // put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127
Jakub Josefa63f9862018-01-11 17:58:38 +0100235 if (common.validInputParam('EXTRA_FORMULAS')) {
236 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
237 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
238 }
239
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200240 // add cluster name if specified
241 if (common.validInputParam('STACK_CLUSTER_NAME')) {
242 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
243 envParams.put('cluster_name', STACK_CLUSTER_NAME)
244 }
245
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300246 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
247 if (STACK_COMPUTE_COUNT.toInteger() > 0){
248 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
249 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
250 }
251 }
252
Oleh Hryhorov825b5be2018-06-13 13:01:53 +0300253
254 if (common.validInputParam('SALT_VERSION')) {
255 common.infoMsg("Setting salt version to ${SALT_VERSION}")
256 envParams.put('cfg_saltversion', SALT_VERSION)
257 }
258
Mykyta Karpin35f71332018-07-27 11:54:51 +0300259 // If stack wasn't removed by the same user which has created it,
260 // nova key pair won't be removed, so need to make sure that no
261 // key pair with the same name exists before creating the stack.
262 if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
263 try {
264 openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
265 } catch (Exception e) {
266 common.errorMsg("Key pair failed to remove with error ${e.message}")
267 }
268 }
269
Jakub Josefa63f9862018-01-11 17:58:38 +0100270 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
271 }
272
273 // get SALT_MASTER_URL
274 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
275 // check that saltMasterHost is valid
276 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
277 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
278 throw new Exception("saltMasterHost is not a valid ip")
279 }
280
281 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
282
283 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
284
285 } else if (STACK_TYPE == 'aws') {
286
287 // setup environment
288 aws.setupVirtualEnv(venv)
289
290 // set aws_env_vars
291 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
292
293 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
294 error("If you want to reuse existing stack you need to provide it's name")
295 }
296
297 if (STACK_REUSE.toBoolean() == false) {
298 // Don't allow to set custom stack name
299 wrap([$class: 'BuildUser']) {
300 if (env.BUILD_USER_ID) {
301 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
302 } else {
303 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
304 }
305 }
306
307 // no underscore in STACK_NAME
308 STACK_NAME = STACK_NAME.replaceAll('_', '-')
309 }
310
311 // set description
312 currentBuild.description = STACK_NAME
313 outputs.put('stack_name', STACK_NAME)
314
315 if (STACK_REUSE.toBoolean() == false) {
316 // get templates
317 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
318
319 // start stack
320 def stack_params = [
321 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
322 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
323 ]
324 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
325 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
326 }
327
328 // wait for stack to be ready
329 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
330
331 // get outputs
332 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
333
334 // check that saltMasterHost is valid
335 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
336 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
337 throw new Exception("saltMasterHost is not a valid ip")
338 }
339
340 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
341 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
342
343 } else if (STACK_TYPE != 'physical') {
344 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
345 }
346
347 outputs.put('salt_api', SALT_MASTER_URL)
348
349 // Setup virtualenv for pepper
350 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
351 }
352
353
354 // Set up override params
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200355 if (common.validInputParam('SALT_OVERRIDES') && common.validInputParam('STACK_INSTALL')) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100356 stage('Set Salt overrides') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300357 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100358 }
359 }
360
361 //
362 // Install
363 //
Denis Egorenko70002bc2019-08-19 19:41:27 +0400364 if (!batch_size) {
Denis Egorenko9ef25b92019-12-19 16:45:25 +0400365 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
366 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
367 // do not use toDouble/Double as it requires additional approved method
368 def workerThreads = salt.getWorkerThreads(venvPepper).toInteger()
369 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenko70002bc2019-08-19 19:41:27 +0400370 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100371
Martin Polreich65cfeda2019-03-28 12:50:57 +0100372 // Check if all minions are reachable and ready
Denis Egorenko70002bc2019-08-19 19:41:27 +0400373 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': '*', batch: batch_size])
Martin Polreich65cfeda2019-03-28 12:50:57 +0100374
Jakub Josefa63f9862018-01-11 17:58:38 +0100375 if (common.checkContains('STACK_INSTALL', 'core')) {
376 stage('Install core infrastructure') {
377 def staticMgmtNetwork = false
378 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
379 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
380 }
Denis Egorenko70002bc2019-08-19 19:41:27 +0400381 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100382
383 if (common.checkContains('STACK_INSTALL', 'kvm')) {
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400384 if (upgrade_nodes) {
385 debian.osUpgradeNode(venvPepper, 'I@salt:control', 'dist-upgrade', 30, 20, batch_size)
386 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'I@salt:control', wait: 60, timeout: 10])
387 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300388 orchestrate.installInfraKvm(venvPepper, extra_tgt)
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400389 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100390 }
391
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300392 orchestrate.validateFoundationInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100393 }
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400394 if (upgrade_nodes) {
395 debian.osUpgradeNode(venvPepper, 'not ( I@salt:master or I@salt:control )', 'dist-upgrade', false, 30, 10, batch_size)
396 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'not ( I@salt:master or I@salt:control )', wait: 60, timeout: 10])
397 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100398 }
399
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300400 stage('Install infra') {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400401 if (common.checkContains('STACK_INSTALL', 'core') ||
Denis Egorenkod13c1522019-11-07 20:35:26 +0400402 common.checkContains('STACK_INSTALL', 'openstack') ||
403 common.checkContains('STACK_INSTALL', 'cicd')) {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400404 orchestrate.installInfra(venvPepper, extra_tgt)
405 }
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300406 }
407
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200408 if (common.validInputParam('STACK_INSTALL')) {
409 stage('Install Orchestrated Apps'){
410 orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications")
411 }
Vasyl Saienko4c78fe12018-08-06 10:17:28 +0300412 }
413
Jakub Josefa63f9862018-01-11 17:58:38 +0100414 // install k8s
415 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400416 extra_tgt_bckp = extra_tgt
Denis Egorenkoe983d452019-08-23 14:29:34 +0400417 extra_tgt = 'and not kdt* and not I@salt:master ' + extra_tgt_bckp
Jakub Josefa63f9862018-01-11 17:58:38 +0100418 stage('Install Kubernetes infra') {
419 if (STACK_TYPE == 'aws') {
420 // configure kubernetes_control_address - save loadbalancer
421 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
422 common.prettyPrint(awsOutputs)
423 if (awsOutputs.containsKey('ControlLoadBalancer')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300424 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 +0100425 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
426 }
427 }
428
429 // ensure certificates are generated properly
Andrey Shestakovf23ed002018-08-21 12:09:51 +0300430 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
431 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 }
433
434 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200435 stage('Install Contrail control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300436 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200437 }
Ales Komarek24097402017-05-22 16:28:10 +0200438 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100439
Jakub Josefa63f9862018-01-11 17:58:38 +0100440 stage('Install Kubernetes control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300441 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
Anton Samoylovf8a65aa2019-01-23 20:22:26 +0400442 if (common.checkContains('STACK_INSTALL', 'contrail')) {
443 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
444 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400445
Jakub Josefa63f9862018-01-11 17:58:38 +0100446 // collect artifacts (kubeconfig)
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300447 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 +0100448 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400449 }
450
Svimbaa554ea02018-06-06 18:45:23 +0200451 if (common.checkContains('STACK_INSTALL', 'contrail')) {
452 stage('Install Contrail compute') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300453 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Svimbaa554ea02018-06-06 18:45:23 +0200454 }
455 }
456
Jakub Josefa63f9862018-01-11 17:58:38 +0100457 stage('Install Kubernetes computes') {
458 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
459 if (STACK_COMPUTE_COUNT > 0) {
460 if (STACK_TYPE == 'aws') {
461 // get stack info
462 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
463
464 //update autoscaling group
465 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
466
467 // wait for computes to boot up
468 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
469 sleep(60)
470
471 } else if (STACK_TYPE == 'heat') {
472 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
473
474 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
475 sleep(60)
476 }
477
478 }
479 }
480
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300481 orchestrate.installKubernetesCompute(venvPepper, extra_tgt)
Svimbaa979f8f2018-09-26 11:24:49 +0200482 // Setup kubernetes addons for opencontrail. More info in the definition of the func.
483 orchestrate.setupKubeAddonForContrail(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100484 }
Vasyl Saienkob8494f22019-03-05 10:56:29 +0200485 orchestrate.installKubernetesClient(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400486 extra_tgt = extra_tgt_bckp
487 }
488
489 // install kdt (drivetrain on k8s) cluster
490 if (common.checkContains('STACK_INSTALL', 'kdt')){
491 extra_tgt_bckp = extra_tgt
492 extra_tgt = 'and kdt* ' + extra_tgt_bckp
493 stage('Install Kubernetes infra for kdt') {
494 // ensure certificates are generated properly
495 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
496 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
497 }
498
499 stage('Install Kubernetes control for kdt') {
Stanislav Riazanovba650f52019-03-15 22:02:56 +0400500 salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool.images'])
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400501 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
502
Stanislav Riazanovba650f52019-03-15 22:02:56 +0400503 salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'nginx.server'])
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400504 // collect artifacts (kubeconfig)
505 writeFile(file: 'kubeconfig-kdt', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config'))
506 archiveArtifacts(artifacts: 'kubeconfig-kdt')
507 }
Vasyl Saienkob8494f22019-03-05 10:56:29 +0200508 orchestrate.installKubernetesClient(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400509 extra_tgt = extra_tgt_bckp
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400510 }
Ales Komarek24097402017-05-22 16:28:10 +0200511
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300512 // install ceph
513 if (common.checkContains('STACK_INSTALL', 'ceph')) {
514 stage('Install Ceph MONs') {
515 orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt)
516 }
517
518 stage('Install Ceph OSDs') {
519 orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt)
520 }
521
522 stage('Install Ceph clients') {
523 orchestrate.installCephClient(venvPepper, extra_tgt)
524 }
525 }
526
Vasyl Saienkoc562fc42018-12-15 22:19:28 +0200527 // install docker swarm
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200528 if (common.validInputParam('STACK_INSTALL')) {
529 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
530 }
Vasyl Saienkoc562fc42018-12-15 22:19:28 +0200531
Jakub Josefa63f9862018-01-11 17:58:38 +0100532 // install openstack
533 if (common.checkContains('STACK_INSTALL', 'openstack')) {
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300534 // install control, tests, ...
Jakub Josefa63f9862018-01-11 17:58:38 +0100535 stage('Install OpenStack control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300536 orchestrate.installOpenstackControl(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100537 }
538
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200539 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
540 // More details: https://mirantis.jira.com/browse/PROD-17765
Ivan Berezovskiy4d6885e2019-08-01 15:23:14 +0400541 salt.restartSaltMinion(venvPepper, "I@keystone:client ${extra_tgt}")
Denis Egorenkoe983d452019-08-23 14:29:34 +0400542 //
543 salt.minionsReachable(venvPepper, 'I@salt:master', 'I@keystone:client ${extra_tgt}', null, 10, 6)
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200544
Jakub Josefa63f9862018-01-11 17:58:38 +0100545 stage('Install OpenStack network') {
546
547 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300548 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Anton Samoylovf8a65aa2019-01-23 20:22:26 +0400549 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100550 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300551 orchestrate.installOpenstackNetwork(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100552 }
553
Petr Jedinýefd668f2018-05-24 14:44:08 +0200554 // Wait for network to come up, 150s should be enough
555 common.retry(10, 15) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300556 salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list')
Petr Jedinýefd668f2018-05-24 14:44:08 +0200557 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100558 }
559
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300560 if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){
Jakub Josefa63f9862018-01-11 17:58:38 +0100561 stage('Install OpenStack Ironic conductor') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300562 orchestrate.installIronicConductor(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100563 }
564 }
565
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300566 if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200567 stage('Install OpenStack Manila data and share') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300568 orchestrate.installManilaShare(venvPepper, extra_tgt)
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200569 }
570 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100571
572 stage('Install OpenStack compute') {
Denis Egorenko70002bc2019-08-19 19:41:27 +0400573 orchestrate.installOpenstackCompute(venvPepper, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100574
575 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300576 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Inessa Vasilevskaya30cb7312018-10-08 12:13:03 +0200577 orchestrate.installBackup(venvPepper, 'contrail', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100578 }
579 }
580
581 }
582
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300583 // connect ceph
Jakub Josefa63f9862018-01-11 17:58:38 +0100584 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100585
586 stage('Connect Ceph') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300587 orchestrate.connectCeph(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100588 }
589 }
590
Jakub Josefa63f9862018-01-11 17:58:38 +0100591 if (common.checkContains('STACK_INSTALL', 'cicd')) {
592 stage('Install Cicd') {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400593 extra_tgt_bckp = extra_tgt
Denis Egorenkoe983d452019-08-23 14:29:34 +0400594 extra_tgt = 'and I@_param:drivetrain_role:cicd ' + extra_tgt_bckp
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300595 orchestrate.installCicd(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400596 extra_tgt = extra_tgt_bckp
597 }
598 }
599
600 if (common.checkContains('STACK_INSTALL', 'kdt')) {
601 stage('Install Cicd on kdt') {
602 extra_tgt_bckp = extra_tgt
603 extra_tgt = 'and kdt* ' + extra_tgt_bckp
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400604 orchestrate.installCicd(venvPepper, extra_tgt)
605 extra_tgt = extra_tgt_bckp
Jakub Josefa63f9862018-01-11 17:58:38 +0100606 }
607 }
608
609 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
610 stage('Install StackLight v1') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300611 orchestrate.installStacklightv1Control(venvPepper, extra_tgt)
612 orchestrate.installStacklightv1Client(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100613 }
614 }
615
616 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
617 stage('Install StackLight') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300618 orchestrate.installStacklight(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100619 }
620 }
621
Jakub Josefa63f9862018-01-11 17:58:38 +0100622 //
623 // Test
624 //
625 def artifacts_dir = '_artifacts/'
626
627 if (common.checkContains('STACK_TEST', 'k8s')) {
628 stage('Run k8s conformance e2e tests') {
629 def image = TEST_K8S_CONFORMANCE_IMAGE
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400630 def autodetect = AUTODETECT
631 def ctl_target = 'I@kubernetes:master'
632 firstTarget = salt.getFirstMinion(venvPepper, ctl_target)
633 def containerd_enabled = salt.getPillar(
634 venvPepper, firstTarget, "kubernetes:common:containerd:enabled"
635 )["return"][0].values()[0].toBoolean()
636 if (containerd_enabled) {
637 def config = ['master': venvPepper,
638 'target': firstTarget,
639 'junitResults': true,
640 'autodetect': autodetect,
641 'image': image]
642 test.executeConformance(config)
643 } else {
644 def output_file = image.replaceAll('/', '-') + '.output'
Denis Egorenkoe983d452019-08-23 14:29:34 +0400645 def target = "I@keystone:server:role:primary ${extra_tgt}"
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400646 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100647
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400648 // run image
649 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100650
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400651 // collect output
652 sh "mkdir -p ${artifacts_dir}"
653 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
654 writeFile file: "${artifacts_dir}${output_file}", text: file_content
655 sh "cat ${artifacts_dir}${output_file}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100656
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400657 // collect artifacts
658 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400659
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400660 // Copy test results
661 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
662 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100663 }
664 }
665
Jakub Josefa63f9862018-01-11 17:58:38 +0100666 if (common.checkContains('STACK_TEST', 'opencontrail')) {
667 stage('Run opencontrail tests') {
668 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
669 def report_dir = "/opt/opencontrail-test-report/"
670 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
671 "cd ${opencontrail_tests_dir} && " +
672 "py.test --junit-xml=${report_dir}report.xml" +
673 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400674
Denis Egorenkoe983d452019-08-23 14:29:34 +0400675 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'saltutil.refresh_pillar', [], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100676 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100677
Jakub Josefa63f9862018-01-11 17:58:38 +0100678 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
679
680 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
681 'I@opencontrail:test', "${report_dir}report.xml"))
682 junit(keepLongStdio: true, testResults: 'report.xml')
683 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100684 }
685
686
Jakub Josefa63f9862018-01-11 17:58:38 +0100687 stage('Finalize') {
688 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300689 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
690 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100691 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Denis Egorenko70002bc2019-08-19 19:41:27 +0400692 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound, batch_size)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100693 // Iterate over nonempty set of gluster servers and apply highstates one by one
694 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200695 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
696 if ( !saltcaMinions.isEmpty() ) {
697 for ( target in saltcaMinions ) {
698 salt.enforceHighstate(venvPepper, target)
699 }
700 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100701 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
702 if ( !glusterMinions.isEmpty() ) {
703 for ( target in glusterMinions ) {
704 salt.enforceHighstate(venvPepper, target)
705 }
706 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100707 }
708
709 outputsPretty = common.prettify(outputs)
710 print(outputsPretty)
711 writeFile(file: 'outputs.json', text: outputsPretty)
712 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100713 }
714
Jakub Josefa63f9862018-01-11 17:58:38 +0100715 } catch (Throwable e) {
716 currentBuild.result = 'FAILURE'
717 throw e
718 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100719
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400720
Jakub Josefa63f9862018-01-11 17:58:38 +0100721 //
722 // Clean
723 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400724
Jakub Josefa63f9862018-01-11 17:58:38 +0100725 if (common.validInputParam('STACK_NAME')) {
726 // send notification
727 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200728 }
729
Jakub Josefa63f9862018-01-11 17:58:38 +0100730 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
731 stage('Trigger cleanup job') {
732 common.errorMsg('Stack cleanup job triggered')
733 build(job: STACK_CLEANUP_JOB, parameters: [
734 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
735 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
736 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
737 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
738 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
739 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
740 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
741 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
742 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
743 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
744 ])
745 }
746 } else {
747 if (currentBuild.result == 'FAILURE') {
748 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 +0300749
Jakub Josefa63f9862018-01-11 17:58:38 +0100750 if (common.validInputParam('SALT_MASTER_URL')) {
751 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
752 }
Ales Komarek24097402017-05-22 16:28:10 +0200753 }
754 }
755 }
756 }
757}