blob: 8009b05838dd8b79e29a16454e9fff4c8c29cdb9 [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 V. Meltsaykin689079a2020-05-18 15:39:36 +020053 * UPGRADE_SALTSTACK Whether to install recent versions of saltstack packages
Denis Egorenko70002bc2019-08-19 19:41:27 +040054
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +030055 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020056 * Test settings:
57 * TEST_K8S_API_SERVER Kubernetes API address
58 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020059 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020060 * TEST_DOCKER_INSTALL Install docker on the target if true
61 * TEST_TEMPEST_IMAGE Tempest image link
62 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
63 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040064 * TESTRAIL_REPORT Whether upload results to testrail or not
65 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
66 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
67 * TESTRAIL_MILESTONE Product version for tests
68 * TESTRAIL_PLAN Testrail test plan
69 * TESTRAIL_GROUP Testrail test group
70 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020071 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020072 * optional parameters for overwriting soft params
73 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020074 *
75 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020076
Ales Komarek24097402017-05-22 16:28:10 +020077common = new com.mirantis.mk.Common()
78git = new com.mirantis.mk.Git()
79openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020080aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020081orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030082python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020083salt = new com.mirantis.mk.Salt()
84test = new com.mirantis.mk.Test()
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +040085debian = new com.mirantis.mk.Debian()
Ales Komarek24097402017-05-22 16:28:10 +020086
87_MAX_PERMITTED_STACKS = 2
88overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
89
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020090// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020091def venv
chnyda597fb032017-10-06 13:42:48 +020092def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020093def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020094
chnydae14058a2017-08-29 15:07:48 +020095def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
96
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020097if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020098 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020099} else if (STACK_TYPE == 'heat') {
100 def envParams
101 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +0200102}
103
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300104def slave_node = 'python'
105
Oleh Hryhorov54460512017-10-26 18:45:36 +0300106if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300107 slave_node = SLAVE_NODE
108}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300109
110def extra_tgt = ''
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400111def extra_tgt_bckp = ''
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300112if (common.validInputParam('EXTRA_TARGET')) {
113 extra_tgt = "${EXTRA_TARGET}"
114}
Denis Egorenko70002bc2019-08-19 19:41:27 +0400115def batch_size = ''
116if (common.validInputParam('BATCH_SIZE')) {
117 batch_size = "${BATCH_SIZE}"
118}
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400119def upgrade_nodes = false
120if (common.validInputParam('DIST_UPGRADE_NODES')) {
121 upgrade_nodes = "${DIST_UPGRADE_NODES}".toBoolean()
122}
Denis V. Meltsaykin689079a2020-05-18 15:39:36 +0200123def upgrade_salt = false
124if (common.validInputParam('UPGRADE_SALTSTACK')){
125 upgrade_salt = "${UPGRADE_SALTSTACK}".toBoolean()
126}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300127
Jakub Josefa63f9862018-01-11 17:58:38 +0100128timeout(time: 12, unit: 'HOURS') {
129 node(slave_node) {
130 try {
131 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100132 def workspace = common.getWorkspace()
133 venv = "${workspace}/venv"
134 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100135 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
136 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
137 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 //
139 // Prepare machines
140 //
141 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200142
Jakub Josefa63f9862018-01-11 17:58:38 +0100143 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200144
Jakub Josefa63f9862018-01-11 17:58:38 +0100145 if (STACK_TYPE == 'heat') {
146 // value defaults
147 envParams = [
148 'cluster_zone': HEAT_STACK_ZONE,
149 'cluster_public_net': HEAT_STACK_PUBLIC_NET
150 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200151
Jakub Josefa63f9862018-01-11 17:58:38 +0100152 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
153 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400154 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200155
Jakub Josefa63f9862018-01-11 17:58:38 +0100156 if (STACK_REUSE.toBoolean() == false) {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200157 // TODO(vsaienko): remove stack creation from this pipeline to separate job
158 // Allow to set custom stack name but user-id will be added anyway
159 // This will fix issue with cleanup when job is aborted by jenkins and
160 // still guarantee stack count per user.
161 def stackNameSuffix = "${JOB_NAME}-${BUILD_NUMBER}"
162 if (STACK_NAME != ''){
163 stackNameSuffix = STACK_NAME
164 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100165 wrap([$class: 'BuildUser']) {
166 if (env.BUILD_USER_ID) {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200167 STACK_NAME = "${env.BUILD_USER_ID}-${stackNameSuffix}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 } else {
Vasyl Saienko293fa3f2019-01-22 21:14:37 +0200169 STACK_NAME = "jenkins-${stackNameSuffix}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100170 }
171 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200172 }
Inessa Vasilevskaya7fd23f22018-10-09 10:58:46 +0200173 } else {
174 // In case name was copied with unicode zero-width space chars -
175 // remove them
176 STACK_NAME = STACK_NAME.trim().replaceAll("\\p{C}", "")
Ales Komarek24097402017-05-22 16:28:10 +0200177 }
178
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400179 // no underscore in STACK_NAME
180 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100181 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200182
Jakub Josefa63f9862018-01-11 17:58:38 +0100183 // set description
184 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400185
Ales Komarek24097402017-05-22 16:28:10 +0200186 // get templates
187 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
188
Jakub Josefa63f9862018-01-11 17:58:38 +0100189 // create openstack env
190 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100191 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100192 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
193 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
194 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
195 OPENSTACK_API_VERSION)
196 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200197
Jakub Josefa63f9862018-01-11 17:58:38 +0100198 //
199 // Verify possibility of create stack for given user and stack type
200 //
201 wrap([$class: 'BuildUser']) {
202 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
203 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
204 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
205 STACK_DELETE = "false"
206 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
207 }
208 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200209 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100210 // launch stack
211 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400212
Jakub Josefa63f9862018-01-11 17:58:38 +0100213 // set reclass repo in heat env
214 try {
215 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
216 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
217 } catch (MissingPropertyException e) {
218 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 +0100219 }
220
sgarbuz489ae3e2019-04-04 10:27:09 +0300221 // put reclass-system repo to branch/tag/ref. If empty will be used reclass pinned commit in AIO model.
222 if (common.validInputParam('RECLASS_SYSTEM_BRANCH')) {
223 common.infoMsg("Setting reclass-system repo to ${RECLASS_SYSTEM_BRANCH} branch/tag/ref")
224 envParams.put('cfg_reclass_system_branch', RECLASS_SYSTEM_BRANCH)
225 }
226
Jakub Josefa63f9862018-01-11 17:58:38 +0100227 // put formulas revision - stable, testing or nightly
228 if (common.validInputParam('FORMULA_PKG_REVISION')) {
229 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
230 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
231 }
232
233 // put extra repo definitions
234 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
235 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
236 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
237 }
238
azvyagintsevb8ddb492018-09-12 14:59:45 +0300239 // put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127
Jakub Josefa63f9862018-01-11 17:58:38 +0100240 if (common.validInputParam('EXTRA_FORMULAS')) {
241 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
242 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
243 }
244
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200245 // add cluster name if specified
246 if (common.validInputParam('STACK_CLUSTER_NAME')) {
247 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
248 envParams.put('cluster_name', STACK_CLUSTER_NAME)
249 }
250
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300251 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
252 if (STACK_COMPUTE_COUNT.toInteger() > 0){
253 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
254 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
255 }
256 }
257
Oleh Hryhorov825b5be2018-06-13 13:01:53 +0300258
259 if (common.validInputParam('SALT_VERSION')) {
260 common.infoMsg("Setting salt version to ${SALT_VERSION}")
261 envParams.put('cfg_saltversion', SALT_VERSION)
262 }
263
Mykyta Karpin35f71332018-07-27 11:54:51 +0300264 // If stack wasn't removed by the same user which has created it,
265 // nova key pair won't be removed, so need to make sure that no
266 // key pair with the same name exists before creating the stack.
267 if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
268 try {
269 openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
270 } catch (Exception e) {
271 common.errorMsg("Key pair failed to remove with error ${e.message}")
272 }
273 }
274
Jakub Josefa63f9862018-01-11 17:58:38 +0100275 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
276 }
277
278 // get SALT_MASTER_URL
279 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
280 // check that saltMasterHost is valid
281 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
282 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
283 throw new Exception("saltMasterHost is not a valid ip")
284 }
285
286 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
287
288 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
289
290 } else if (STACK_TYPE == 'aws') {
291
292 // setup environment
293 aws.setupVirtualEnv(venv)
294
295 // set aws_env_vars
296 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
297
298 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
299 error("If you want to reuse existing stack you need to provide it's name")
300 }
301
302 if (STACK_REUSE.toBoolean() == false) {
303 // Don't allow to set custom stack name
304 wrap([$class: 'BuildUser']) {
305 if (env.BUILD_USER_ID) {
306 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
307 } else {
308 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
309 }
310 }
311
312 // no underscore in STACK_NAME
313 STACK_NAME = STACK_NAME.replaceAll('_', '-')
314 }
315
316 // set description
317 currentBuild.description = STACK_NAME
318 outputs.put('stack_name', STACK_NAME)
319
320 if (STACK_REUSE.toBoolean() == false) {
321 // get templates
322 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
323
324 // start stack
325 def stack_params = [
326 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
327 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
328 ]
329 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
330 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
331 }
332
333 // wait for stack to be ready
334 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
335
336 // get outputs
337 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
338
339 // check that saltMasterHost is valid
340 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
341 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
342 throw new Exception("saltMasterHost is not a valid ip")
343 }
344
345 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
346 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
347
348 } else if (STACK_TYPE != 'physical') {
349 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
350 }
351
352 outputs.put('salt_api', SALT_MASTER_URL)
353
354 // Setup virtualenv for pepper
355 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
356 }
357
358
359 // Set up override params
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200360 if (common.validInputParam('SALT_OVERRIDES') && common.validInputParam('STACK_INSTALL')) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100361 stage('Set Salt overrides') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300362 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100363 }
364 }
365
366 //
367 // Install
368 //
Denis Egorenko70002bc2019-08-19 19:41:27 +0400369 if (!batch_size) {
Denis Egorenko9ef25b92019-12-19 16:45:25 +0400370 // if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
371 // 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
372 // do not use toDouble/Double as it requires additional approved method
373 def workerThreads = salt.getWorkerThreads(venvPepper).toInteger()
374 batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
Denis Egorenko70002bc2019-08-19 19:41:27 +0400375 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100376
Martin Polreich65cfeda2019-03-28 12:50:57 +0100377 // Check if all minions are reachable and ready
Denis Egorenko70002bc2019-08-19 19:41:27 +0400378 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': '*', batch: batch_size])
Martin Polreich65cfeda2019-03-28 12:50:57 +0100379
Jakub Josefa63f9862018-01-11 17:58:38 +0100380 if (common.checkContains('STACK_INSTALL', 'core')) {
381 stage('Install core infrastructure') {
382 def staticMgmtNetwork = false
383 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
384 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
385 }
Denis Egorenko70002bc2019-08-19 19:41:27 +0400386 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100387
Denis V. Meltsaykin689079a2020-05-18 15:39:36 +0200388 if (upgrade_salt) {
389 debian.upgradeSaltPackages(venvPepper, 'I@salt:master')
390 debian.upgradeSaltPackages(venvPepper, 'I@salt:minion and not I@salt:master')
391 }
392
Jakub Josefa63f9862018-01-11 17:58:38 +0100393 if (common.checkContains('STACK_INSTALL', 'kvm')) {
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400394 if (upgrade_nodes) {
395 debian.osUpgradeNode(venvPepper, 'I@salt:control', 'dist-upgrade', 30, 20, batch_size)
396 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'I@salt:control', wait: 60, timeout: 10])
397 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300398 orchestrate.installInfraKvm(venvPepper, extra_tgt)
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400399 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100400 }
401
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300402 orchestrate.validateFoundationInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100403 }
Ivan Berezovskiy07adcde2020-01-27 14:25:31 +0400404 if (upgrade_nodes) {
405 debian.osUpgradeNode(venvPepper, 'not ( I@salt:master or I@salt:control )', 'dist-upgrade', false, 30, 10, batch_size)
406 salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'not ( I@salt:master or I@salt:control )', wait: 60, timeout: 10])
407 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100408 }
409
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300410 stage('Install infra') {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400411 if (common.checkContains('STACK_INSTALL', 'core') ||
Denis Egorenkod13c1522019-11-07 20:35:26 +0400412 common.checkContains('STACK_INSTALL', 'openstack') ||
413 common.checkContains('STACK_INSTALL', 'cicd')) {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400414 orchestrate.installInfra(venvPepper, extra_tgt)
415 }
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300416 }
417
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200418 if (common.validInputParam('STACK_INSTALL')) {
419 stage('Install Orchestrated Apps'){
420 orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications")
421 }
Vasyl Saienko4c78fe12018-08-06 10:17:28 +0300422 }
423
Jakub Josefa63f9862018-01-11 17:58:38 +0100424 // install k8s
425 if (common.checkContains('STACK_INSTALL', 'k8s')) {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400426 extra_tgt_bckp = extra_tgt
Denis Egorenkoe983d452019-08-23 14:29:34 +0400427 extra_tgt = 'and not kdt* and not I@salt:master ' + extra_tgt_bckp
Jakub Josefa63f9862018-01-11 17:58:38 +0100428 stage('Install Kubernetes infra') {
429 if (STACK_TYPE == 'aws') {
430 // configure kubernetes_control_address - save loadbalancer
431 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
432 common.prettyPrint(awsOutputs)
433 if (awsOutputs.containsKey('ControlLoadBalancer')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300434 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 +0100435 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
436 }
437 }
438
439 // ensure certificates are generated properly
Andrey Shestakovf23ed002018-08-21 12:09:51 +0300440 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
441 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100442 }
443
444 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200445 stage('Install Contrail control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300446 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200447 }
Ales Komarek24097402017-05-22 16:28:10 +0200448 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100449
Jakub Josefa63f9862018-01-11 17:58:38 +0100450 stage('Install Kubernetes control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300451 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
Anton Samoylovf8a65aa2019-01-23 20:22:26 +0400452 if (common.checkContains('STACK_INSTALL', 'contrail')) {
453 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
454 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400455
Jakub Josefa63f9862018-01-11 17:58:38 +0100456 // collect artifacts (kubeconfig)
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300457 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 +0100458 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400459 }
460
Svimbaa554ea02018-06-06 18:45:23 +0200461 if (common.checkContains('STACK_INSTALL', 'contrail')) {
462 stage('Install Contrail compute') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300463 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Svimbaa554ea02018-06-06 18:45:23 +0200464 }
465 }
466
Jakub Josefa63f9862018-01-11 17:58:38 +0100467 stage('Install Kubernetes computes') {
468 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
469 if (STACK_COMPUTE_COUNT > 0) {
470 if (STACK_TYPE == 'aws') {
471 // get stack info
472 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
473
474 //update autoscaling group
475 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
476
477 // wait for computes to boot up
478 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
479 sleep(60)
480
481 } else if (STACK_TYPE == 'heat') {
482 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
483
484 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
485 sleep(60)
486 }
487
488 }
489 }
490
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300491 orchestrate.installKubernetesCompute(venvPepper, extra_tgt)
Svimbaa979f8f2018-09-26 11:24:49 +0200492 // Setup kubernetes addons for opencontrail. More info in the definition of the func.
493 orchestrate.setupKubeAddonForContrail(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100494 }
Vasyl Saienkob8494f22019-03-05 10:56:29 +0200495 orchestrate.installKubernetesClient(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400496 extra_tgt = extra_tgt_bckp
497 }
498
499 // install kdt (drivetrain on k8s) cluster
500 if (common.checkContains('STACK_INSTALL', 'kdt')){
501 extra_tgt_bckp = extra_tgt
502 extra_tgt = 'and kdt* ' + extra_tgt_bckp
503 stage('Install Kubernetes infra for kdt') {
504 // ensure certificates are generated properly
505 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
506 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
507 }
508
509 stage('Install Kubernetes control for kdt') {
Stanislav Riazanovba650f52019-03-15 22:02:56 +0400510 salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool.images'])
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400511 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
512
Stanislav Riazanovba650f52019-03-15 22:02:56 +0400513 salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'nginx.server'])
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400514 // collect artifacts (kubeconfig)
515 writeFile(file: 'kubeconfig-kdt', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config'))
516 archiveArtifacts(artifacts: 'kubeconfig-kdt')
517 }
Vasyl Saienkob8494f22019-03-05 10:56:29 +0200518 orchestrate.installKubernetesClient(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400519 extra_tgt = extra_tgt_bckp
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400520 }
Ales Komarek24097402017-05-22 16:28:10 +0200521
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300522 // install ceph
523 if (common.checkContains('STACK_INSTALL', 'ceph')) {
524 stage('Install Ceph MONs') {
525 orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt)
526 }
527
528 stage('Install Ceph OSDs') {
529 orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt)
530 }
531
532 stage('Install Ceph clients') {
533 orchestrate.installCephClient(venvPepper, extra_tgt)
534 }
535 }
536
Vasyl Saienkoc562fc42018-12-15 22:19:28 +0200537 // install docker swarm
Oleh Hryhorovc409d1e2019-02-27 16:57:09 +0200538 if (common.validInputParam('STACK_INSTALL')) {
539 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
540 }
Vasyl Saienkoc562fc42018-12-15 22:19:28 +0200541
Jakub Josefa63f9862018-01-11 17:58:38 +0100542 // install openstack
543 if (common.checkContains('STACK_INSTALL', 'openstack')) {
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300544 // install control, tests, ...
Jakub Josefa63f9862018-01-11 17:58:38 +0100545 stage('Install OpenStack control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300546 orchestrate.installOpenstackControl(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100547 }
548
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200549 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
550 // More details: https://mirantis.jira.com/browse/PROD-17765
Ivan Berezovskiy4d6885e2019-08-01 15:23:14 +0400551 salt.restartSaltMinion(venvPepper, "I@keystone:client ${extra_tgt}")
Denis Egorenkoe983d452019-08-23 14:29:34 +0400552 //
553 salt.minionsReachable(venvPepper, 'I@salt:master', 'I@keystone:client ${extra_tgt}', null, 10, 6)
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200554
Jakub Josefa63f9862018-01-11 17:58:38 +0100555 stage('Install OpenStack network') {
556
557 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300558 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Anton Samoylovf8a65aa2019-01-23 20:22:26 +0400559 orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100560 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300561 orchestrate.installOpenstackNetwork(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100562 }
563
Petr Jedinýefd668f2018-05-24 14:44:08 +0200564 // Wait for network to come up, 150s should be enough
565 common.retry(10, 15) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300566 salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list')
Petr Jedinýefd668f2018-05-24 14:44:08 +0200567 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100568 }
569
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300570 if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){
Jakub Josefa63f9862018-01-11 17:58:38 +0100571 stage('Install OpenStack Ironic conductor') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300572 orchestrate.installIronicConductor(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100573 }
574 }
575
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300576 if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200577 stage('Install OpenStack Manila data and share') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300578 orchestrate.installManilaShare(venvPepper, extra_tgt)
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200579 }
580 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100581
582 stage('Install OpenStack compute') {
Denis Egorenko70002bc2019-08-19 19:41:27 +0400583 orchestrate.installOpenstackCompute(venvPepper, extra_tgt, batch_size)
Jakub Josefa63f9862018-01-11 17:58:38 +0100584
585 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300586 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Inessa Vasilevskaya30cb7312018-10-08 12:13:03 +0200587 orchestrate.installBackup(venvPepper, 'contrail', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100588 }
589 }
590
591 }
592
Mykyta Karpin5b7c2602018-09-11 17:47:20 +0300593 // connect ceph
Jakub Josefa63f9862018-01-11 17:58:38 +0100594 if (common.checkContains('STACK_INSTALL', 'ceph')) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100595
596 stage('Connect Ceph') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300597 orchestrate.connectCeph(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100598 }
599 }
600
Jakub Josefa63f9862018-01-11 17:58:38 +0100601 if (common.checkContains('STACK_INSTALL', 'cicd')) {
602 stage('Install Cicd') {
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400603 extra_tgt_bckp = extra_tgt
Denis Egorenkoe983d452019-08-23 14:29:34 +0400604 extra_tgt = 'and I@_param:drivetrain_role:cicd ' + extra_tgt_bckp
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300605 orchestrate.installCicd(venvPepper, extra_tgt)
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400606 extra_tgt = extra_tgt_bckp
607 }
608 }
609
610 if (common.checkContains('STACK_INSTALL', 'kdt')) {
611 stage('Install Cicd on kdt') {
612 extra_tgt_bckp = extra_tgt
613 extra_tgt = 'and kdt* ' + extra_tgt_bckp
Stanislav Riazanovf0302582019-02-04 17:47:06 +0400614 orchestrate.installCicd(venvPepper, extra_tgt)
615 extra_tgt = extra_tgt_bckp
Jakub Josefa63f9862018-01-11 17:58:38 +0100616 }
617 }
618
619 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
620 stage('Install StackLight v1') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300621 orchestrate.installStacklightv1Control(venvPepper, extra_tgt)
622 orchestrate.installStacklightv1Client(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100623 }
624 }
625
626 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
627 stage('Install StackLight') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300628 orchestrate.installStacklight(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100629 }
630 }
631
Jakub Josefa63f9862018-01-11 17:58:38 +0100632 //
633 // Test
634 //
635 def artifacts_dir = '_artifacts/'
636
637 if (common.checkContains('STACK_TEST', 'k8s')) {
638 stage('Run k8s conformance e2e tests') {
639 def image = TEST_K8S_CONFORMANCE_IMAGE
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400640 def autodetect = AUTODETECT
641 def ctl_target = 'I@kubernetes:master'
642 firstTarget = salt.getFirstMinion(venvPepper, ctl_target)
643 def containerd_enabled = salt.getPillar(
644 venvPepper, firstTarget, "kubernetes:common:containerd:enabled"
645 )["return"][0].values()[0].toBoolean()
646 if (containerd_enabled) {
647 def config = ['master': venvPepper,
648 'target': firstTarget,
649 'junitResults': true,
650 'autodetect': autodetect,
651 'image': image]
652 test.executeConformance(config)
653 } else {
654 def output_file = image.replaceAll('/', '-') + '.output'
Denis Egorenkoe983d452019-08-23 14:29:34 +0400655 def target = "I@keystone:server:role:primary ${extra_tgt}"
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400656 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100657
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400658 // run image
659 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100660
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400661 // collect output
662 sh "mkdir -p ${artifacts_dir}"
663 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
664 writeFile file: "${artifacts_dir}${output_file}", text: file_content
665 sh "cat ${artifacts_dir}${output_file}"
Jakub Josefa63f9862018-01-11 17:58:38 +0100666
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400667 // collect artifacts
668 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400669
Victor Ryzhenkin723bd062018-12-11 17:09:06 +0400670 // Copy test results
671 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
672 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100673 }
674 }
675
Jakub Josefa63f9862018-01-11 17:58:38 +0100676 if (common.checkContains('STACK_TEST', 'opencontrail')) {
677 stage('Run opencontrail tests') {
678 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
679 def report_dir = "/opt/opencontrail-test-report/"
680 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
681 "cd ${opencontrail_tests_dir} && " +
682 "py.test --junit-xml=${report_dir}report.xml" +
683 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400684
Denis Egorenkoe983d452019-08-23 14:29:34 +0400685 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'saltutil.refresh_pillar', [], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100686 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100687
Jakub Josefa63f9862018-01-11 17:58:38 +0100688 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
689
690 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
691 'I@opencontrail:test', "${report_dir}report.xml"))
692 junit(keepLongStdio: true, testResults: 'report.xml')
693 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100694 }
695
696
Jakub Josefa63f9862018-01-11 17:58:38 +0100697 stage('Finalize') {
698 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300699 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
700 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100701 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Denis Egorenko70002bc2019-08-19 19:41:27 +0400702 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound, batch_size)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100703 // Iterate over nonempty set of gluster servers and apply highstates one by one
704 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200705 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
706 if ( !saltcaMinions.isEmpty() ) {
707 for ( target in saltcaMinions ) {
708 salt.enforceHighstate(venvPepper, target)
709 }
710 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100711 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
712 if ( !glusterMinions.isEmpty() ) {
713 for ( target in glusterMinions ) {
714 salt.enforceHighstate(venvPepper, target)
715 }
716 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100717 }
718
719 outputsPretty = common.prettify(outputs)
720 print(outputsPretty)
721 writeFile(file: 'outputs.json', text: outputsPretty)
722 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100723 }
724
Jakub Josefa63f9862018-01-11 17:58:38 +0100725 } catch (Throwable e) {
726 currentBuild.result = 'FAILURE'
727 throw e
728 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100729
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400730
Jakub Josefa63f9862018-01-11 17:58:38 +0100731 //
732 // Clean
733 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400734
Jakub Josefa63f9862018-01-11 17:58:38 +0100735 if (common.validInputParam('STACK_NAME')) {
736 // send notification
737 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200738 }
739
Jakub Josefa63f9862018-01-11 17:58:38 +0100740 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
741 stage('Trigger cleanup job') {
742 common.errorMsg('Stack cleanup job triggered')
743 build(job: STACK_CLEANUP_JOB, parameters: [
744 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
745 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
746 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
747 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
748 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
749 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
750 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
751 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
752 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
753 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
754 ])
755 }
756 } else {
757 if (currentBuild.result == 'FAILURE') {
758 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 +0300759
Jakub Josefa63f9862018-01-11 17:58:38 +0100760 if (common.validInputParam('SALT_MASTER_URL')) {
761 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
762 }
Ales Komarek24097402017-05-22 16:28:10 +0200763 }
764 }
765 }
766 }
767}