blob: ce35b5163269776e438adfdc23a33adc3586f73c [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
49 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020050 * Test settings:
51 * TEST_K8S_API_SERVER Kubernetes API address
52 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020053 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020054 * TEST_DOCKER_INSTALL Install docker on the target if true
55 * TEST_TEMPEST_IMAGE Tempest image link
56 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
57 * TEST_TEMPEST_TARGET Salt target for tempest node
ibumarskov637a2152018-01-16 10:39:57 +040058 * TESTRAIL_REPORT Whether upload results to testrail or not
59 * TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
60 * TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
61 * TESTRAIL_MILESTONE Product version for tests
62 * TESTRAIL_PLAN Testrail test plan
63 * TESTRAIL_GROUP Testrail test group
64 * TESTRAIL_SUITE Testrail test suite
Ales Komarek24097402017-05-22 16:28:10 +020065 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020066 * optional parameters for overwriting soft params
67 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020068 *
69 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020070
Ales Komarek24097402017-05-22 16:28:10 +020071common = new com.mirantis.mk.Common()
72git = new com.mirantis.mk.Git()
73openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020074aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020075orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030076python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020077salt = new com.mirantis.mk.Salt()
78test = new com.mirantis.mk.Test()
79
80_MAX_PERMITTED_STACKS = 2
81overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
82
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020083// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020084def venv
chnyda597fb032017-10-06 13:42:48 +020085def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020086def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020087
chnydae14058a2017-08-29 15:07:48 +020088def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
89
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020090if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020091 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020092} else if (STACK_TYPE == 'heat') {
93 def envParams
94 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020095}
96
Oleh Hryhorov9630a762017-10-24 14:33:25 +030097def slave_node = 'python'
98
Oleh Hryhorov54460512017-10-26 18:45:36 +030099if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +0300100 slave_node = SLAVE_NODE
101}
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300102
103def extra_tgt = ''
104if (common.validInputParam('EXTRA_TARGET')) {
105 extra_tgt = "${EXTRA_TARGET}"
106}
107
Jakub Josefa63f9862018-01-11 17:58:38 +0100108timeout(time: 12, unit: 'HOURS') {
109 node(slave_node) {
110 try {
111 // Set build-specific variables
Jakub Josef88aaf832018-01-18 16:18:28 +0100112 def workspace = common.getWorkspace()
113 venv = "${workspace}/venv"
114 venvPepper = "${workspace}/venvPepper"
Jakub Josef052e77a2018-03-05 15:19:03 +0100115 if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
116 common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
117 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100118 //
119 // Prepare machines
120 //
121 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200122
Jakub Josefa63f9862018-01-11 17:58:38 +0100123 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200124
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 if (STACK_TYPE == 'heat') {
126 // value defaults
127 envParams = [
128 'cluster_zone': HEAT_STACK_ZONE,
129 'cluster_public_net': HEAT_STACK_PUBLIC_NET
130 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200131
Jakub Josefa63f9862018-01-11 17:58:38 +0100132 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
133 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400134 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200135
Jakub Josefa63f9862018-01-11 17:58:38 +0100136 if (STACK_REUSE.toBoolean() == false) {
137 // Don't allow to set custom heat stack name
138 wrap([$class: 'BuildUser']) {
139 if (env.BUILD_USER_ID) {
140 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
141 } else {
142 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
143 }
144 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200145 }
146 }
147
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400148 // no underscore in STACK_NAME
149 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200151
Jakub Josefa63f9862018-01-11 17:58:38 +0100152 // set description
153 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400154
Ales Komarek24097402017-05-22 16:28:10 +0200155 // get templates
156 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
157
Jakub Josefa63f9862018-01-11 17:58:38 +0100158 // create openstack env
159 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
Jakub Josef88aaf832018-01-18 16:18:28 +0100160 openstackCloud = openstack.createOpenstackEnv(venv,
Jakub Josefa63f9862018-01-11 17:58:38 +0100161 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
162 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
163 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
164 OPENSTACK_API_VERSION)
165 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200166
Jakub Josefa63f9862018-01-11 17:58:38 +0100167 //
168 // Verify possibility of create stack for given user and stack type
169 //
170 wrap([$class: 'BuildUser']) {
171 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
172 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
173 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
174 STACK_DELETE = "false"
175 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
176 }
177 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200178 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100179 // launch stack
180 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400181
Jakub Josefa63f9862018-01-11 17:58:38 +0100182 // set reclass repo in heat env
183 try {
184 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
185 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
186 } catch (MissingPropertyException e) {
187 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 +0100188 }
189
Jakub Josefa63f9862018-01-11 17:58:38 +0100190 // put formulas revision - stable, testing or nightly
191 if (common.validInputParam('FORMULA_PKG_REVISION')) {
192 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
193 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
194 }
195
196 // put extra repo definitions
197 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
198 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
199 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
200 }
201
azvyagintsevb8ddb492018-09-12 14:59:45 +0300202 // put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127
Jakub Josefa63f9862018-01-11 17:58:38 +0100203 if (common.validInputParam('EXTRA_FORMULAS')) {
204 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
205 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
206 }
207
Vasyl Saienkoa81e9312018-03-06 01:28:35 +0200208 // add cluster name if specified
209 if (common.validInputParam('STACK_CLUSTER_NAME')) {
210 common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
211 envParams.put('cluster_name', STACK_CLUSTER_NAME)
212 }
213
Vasyl Saienko51139fd2018-04-20 12:01:50 +0300214 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
215 if (STACK_COMPUTE_COUNT.toInteger() > 0){
216 common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
217 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
218 }
219 }
220
Oleh Hryhorov825b5be2018-06-13 13:01:53 +0300221
222 if (common.validInputParam('SALT_VERSION')) {
223 common.infoMsg("Setting salt version to ${SALT_VERSION}")
224 envParams.put('cfg_saltversion', SALT_VERSION)
225 }
226
Mykyta Karpin35f71332018-07-27 11:54:51 +0300227 // If stack wasn't removed by the same user which has created it,
228 // nova key pair won't be removed, so need to make sure that no
229 // key pair with the same name exists before creating the stack.
230 if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
231 try {
232 openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
233 } catch (Exception e) {
234 common.errorMsg("Key pair failed to remove with error ${e.message}")
235 }
236 }
237
Jakub Josefa63f9862018-01-11 17:58:38 +0100238 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
239 }
240
241 // get SALT_MASTER_URL
242 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
243 // check that saltMasterHost is valid
244 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
245 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
246 throw new Exception("saltMasterHost is not a valid ip")
247 }
248
249 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
250
251 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
252
253 } else if (STACK_TYPE == 'aws') {
254
255 // setup environment
256 aws.setupVirtualEnv(venv)
257
258 // set aws_env_vars
259 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
260
261 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
262 error("If you want to reuse existing stack you need to provide it's name")
263 }
264
265 if (STACK_REUSE.toBoolean() == false) {
266 // Don't allow to set custom stack name
267 wrap([$class: 'BuildUser']) {
268 if (env.BUILD_USER_ID) {
269 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
270 } else {
271 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
272 }
273 }
274
275 // no underscore in STACK_NAME
276 STACK_NAME = STACK_NAME.replaceAll('_', '-')
277 }
278
279 // set description
280 currentBuild.description = STACK_NAME
281 outputs.put('stack_name', STACK_NAME)
282
283 if (STACK_REUSE.toBoolean() == false) {
284 // get templates
285 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
286
287 // start stack
288 def stack_params = [
289 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
290 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
291 ]
292 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
293 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
294 }
295
296 // wait for stack to be ready
297 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
298
299 // get outputs
300 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
301
302 // check that saltMasterHost is valid
303 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
304 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
305 throw new Exception("saltMasterHost is not a valid ip")
306 }
307
308 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
309 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
310
311 } else if (STACK_TYPE != 'physical') {
312 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
313 }
314
315 outputs.put('salt_api', SALT_MASTER_URL)
316
317 // Setup virtualenv for pepper
318 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
319 }
320
321
322 // Set up override params
323 if (common.validInputParam('SALT_OVERRIDES')) {
324 stage('Set Salt overrides') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300325 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100326 }
327 }
328
329 //
330 // Install
331 //
332
333 if (common.checkContains('STACK_INSTALL', 'core')) {
334 stage('Install core infrastructure') {
335 def staticMgmtNetwork = false
336 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
337 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
338 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300339 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100340
341 if (common.checkContains('STACK_INSTALL', 'kvm')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300342 orchestrate.installInfraKvm(venvPepper, extra_tgt)
Dzmitry Stremkouski16fb74f2018-07-10 02:01:34 +0200343 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100344 }
345
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300346 orchestrate.validateFoundationInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100347 }
348 }
349
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300350 stage('Install infra') {
351 if (common.checkContains('STACK_INSTALL', 'core') ||
352 common.checkContains('STACK_INSTALL', 'openstack') ||
353 common.checkContains('STACK_INSTALL', 'oss')) {
354 orchestrate.installInfra(venvPepper, extra_tgt)
355 }
356 }
357
Vasyl Saienko4c78fe12018-08-06 10:17:28 +0300358 stage('Install Orchestrated Apps'){
359 orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications")
360 }
361
Jakub Josefa63f9862018-01-11 17:58:38 +0100362 // install k8s
363 if (common.checkContains('STACK_INSTALL', 'k8s')) {
364
365 stage('Install Kubernetes infra') {
366 if (STACK_TYPE == 'aws') {
367 // configure kubernetes_control_address - save loadbalancer
368 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
369 common.prettyPrint(awsOutputs)
370 if (awsOutputs.containsKey('ControlLoadBalancer')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300371 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 +0100372 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
373 }
374 }
375
376 // ensure certificates are generated properly
Andrey Shestakovf23ed002018-08-21 12:09:51 +0300377 salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
378 salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100379 }
380
381 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Svimbaa554ea02018-06-06 18:45:23 +0200382 stage('Install Contrail control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300383 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200384 }
Ales Komarek24097402017-05-22 16:28:10 +0200385 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100386
Jakub Josefa63f9862018-01-11 17:58:38 +0100387 stage('Install Kubernetes control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300388 orchestrate.installKubernetesControl(venvPepper, extra_tgt)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400389
Jakub Josefa63f9862018-01-11 17:58:38 +0100390 // collect artifacts (kubeconfig)
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300391 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 +0100392 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400393 }
394
Svimbaa554ea02018-06-06 18:45:23 +0200395 if (common.checkContains('STACK_INSTALL', 'contrail')) {
396 stage('Install Contrail compute') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300397 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Svimbaa554ea02018-06-06 18:45:23 +0200398 }
399 }
400
Jakub Josefa63f9862018-01-11 17:58:38 +0100401 stage('Install Kubernetes computes') {
402 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
403 if (STACK_COMPUTE_COUNT > 0) {
404 if (STACK_TYPE == 'aws') {
405 // get stack info
406 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
407
408 //update autoscaling group
409 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
410
411 // wait for computes to boot up
412 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
413 sleep(60)
414
415 } else if (STACK_TYPE == 'heat') {
416 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
417
418 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
419 sleep(60)
420 }
421
422 }
423 }
424
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300425 orchestrate.installKubernetesCompute(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100426 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400427 }
Ales Komarek24097402017-05-22 16:28:10 +0200428
Jakub Josefa63f9862018-01-11 17:58:38 +0100429 // install openstack
430 if (common.checkContains('STACK_INSTALL', 'openstack')) {
Oleksii Grudevd3d5fad2018-06-29 16:25:35 +0300431 // install control, tests, ...
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 stage('Install OpenStack control') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300433 orchestrate.installOpenstackControl(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100434 }
435
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200436 // Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
437 // More details: https://mirantis.jira.com/browse/PROD-17765
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300438 salt.runSaltProcessStep(venvPepper, "I@keystone:client ${extra_tgt}", 'service.restart', ['salt-minion'])
439 salt.minionsReachable(venvPepper, "I@salt:master and *01* ${extra_tgt}", 'I@keystone:client', null, 10, 6)
Oleg Iurchenko86f1a842018-02-13 22:18:28 +0200440
Jakub Josefa63f9862018-01-11 17:58:38 +0100441 stage('Install OpenStack network') {
442
443 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300444 orchestrate.installContrailNetwork(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100445 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300446 orchestrate.installOpenstackNetwork(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100447 }
448
Petr Jedinýefd668f2018-05-24 14:44:08 +0200449 // Wait for network to come up, 150s should be enough
450 common.retry(10, 15) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300451 salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list')
Petr Jedinýefd668f2018-05-24 14:44:08 +0200452 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100453 }
454
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300455 if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){
Jakub Josefa63f9862018-01-11 17:58:38 +0100456 stage('Install OpenStack Ironic conductor') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300457 orchestrate.installIronicConductor(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100458 }
459 }
460
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300461 if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200462 stage('Install OpenStack Manila data and share') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300463 orchestrate.installManilaShare(venvPepper, extra_tgt)
Vasyl Saienkob800a0f2018-02-21 18:38:53 +0200464 }
465 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100466
467 stage('Install OpenStack compute') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300468 orchestrate.installOpenstackCompute(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100469
470 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300471 orchestrate.installContrailCompute(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100472 }
473 }
474
475 }
476
477 // install ceph
478 if (common.checkContains('STACK_INSTALL', 'ceph')) {
479 stage('Install Ceph MONs') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300480 orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100481 }
482
483 stage('Install Ceph OSDs') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300484 orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100485 }
486
487
488 stage('Install Ceph clients') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300489 orchestrate.installCephClient(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100490 }
491
492 stage('Connect Ceph') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300493 orchestrate.connectCeph(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100494 }
495 }
496
497 if (common.checkContains('STACK_INSTALL', 'oss')) {
498 stage('Install Oss infra') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300499 orchestrate.installOssInfra(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100500 }
501 }
502
503 if (common.checkContains('STACK_INSTALL', 'cicd')) {
504 stage('Install Cicd') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300505 orchestrate.installInfra(venvPepper, extra_tgt)
506 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
507 orchestrate.installCicd(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100508 }
509 }
510
511 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
512 stage('Install StackLight v1') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300513 orchestrate.installStacklightv1Control(venvPepper, extra_tgt)
514 orchestrate.installStacklightv1Client(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100515 }
516 }
517
518 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
519 stage('Install StackLight') {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300520 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
521 orchestrate.installStacklight(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100522 }
523 }
524
525 if (common.checkContains('STACK_INSTALL', 'oss')) {
526 stage('Install OSS') {
527 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
528 // In case if StackLightv2 enabled containers already started
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300529 orchestrate.installDockerSwarm(venvPepper, extra_tgt)
530 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 +0100531 }
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300532 orchestrate.installOss(venvPepper, extra_tgt)
Jakub Josefa63f9862018-01-11 17:58:38 +0100533 }
534 }
535
536 //
537 // Test
538 //
539 def artifacts_dir = '_artifacts/'
540
541 if (common.checkContains('STACK_TEST', 'k8s')) {
542 stage('Run k8s conformance e2e tests') {
543 def image = TEST_K8S_CONFORMANCE_IMAGE
544 def output_file = image.replaceAll('/', '-') + '.output'
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300545 def target = "ctl01* ${extra_tgt}"
vrovachevff3e72d2018-01-25 16:14:43 +0400546 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100547
548 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400549 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100550
551 // collect output
552 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400553 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100554 writeFile file: "${artifacts_dir}${output_file}", text: file_content
555 sh "cat ${artifacts_dir}${output_file}"
556
557 // collect artifacts
558 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400559
560 // Copy test results
561 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100562 }
563 }
564
565 if (common.checkContains('STACK_TEST', 'openstack')) {
566 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
567 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
568 }
569 stage('Run OpenStack tests') {
570 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
571 }
572
573 stage('Copy Tempest results to config node') {
574 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
575 }
576
577 stage('Archive rally artifacts') {
578 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200579 }
ibumarskov637a2152018-01-16 10:39:57 +0400580
581 if (common.validInputParam('TESTRAIL_REPORT') && TESTRAIL_REPORT.toBoolean()) {
582 stage('Upload test results to TestRail') {
583 def date = sh(script: 'date +%Y-%m-%d', returnStdout: true).trim()
584 def plan = TESTRAIL_PLAN ?: "[${TESTRAIL_MILESTONE}]System-Devcloud-${date}"
585 def group = TESTRAIL_GROUP ?: STACK_TEMPLATE
586
587 salt.cmdRun(venvPepper, TEST_TEMPEST_TARGET, "cd /root/rally_reports && cp \$(ls -t *xml | head -n1) report.xml")
588 test.uploadResultsTestrail("/root/rally_reports/report.xml",
589 TESTRAIL_REPORTER_IMAGE, group, TESTRAIL_QA_CREDENTIALS,
590 plan, TESTRAIL_MILESTONE, TESTRAIL_SUITE)
591 }
592 }
Ales Komarek24097402017-05-22 16:28:10 +0200593 }
594
Ales Komarek24097402017-05-22 16:28:10 +0200595
Jakub Josefa63f9862018-01-11 17:58:38 +0100596 if (common.checkContains('STACK_TEST', 'ceph')) {
597 stage('Run infra tests') {
598 sleep(120)
599 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/"
600 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
601 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
602 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200603 }
604 }
605
Jakub Josefa63f9862018-01-11 17:58:38 +0100606 if (common.checkContains('STACK_TEST', 'opencontrail')) {
607 stage('Run opencontrail tests') {
608 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
609 def report_dir = "/opt/opencontrail-test-report/"
610 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
611 "cd ${opencontrail_tests_dir} && " +
612 "py.test --junit-xml=${report_dir}report.xml" +
613 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400614
Jakub Josefa63f9862018-01-11 17:58:38 +0100615 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
616 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100617
Jakub Josefa63f9862018-01-11 17:58:38 +0100618 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
619
620 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
621 'I@opencontrail:test', "${report_dir}report.xml"))
622 junit(keepLongStdio: true, testResults: 'report.xml')
623 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100624 }
625
626
Jakub Josefa63f9862018-01-11 17:58:38 +0100627 stage('Finalize') {
628 if (common.checkContains('STACK_INSTALL', 'finalize')) {
Oleh Hryhorov2a63aa62018-06-22 17:26:41 +0300629 def gluster_compound = "I@glusterfs:server ${extra_tgt}"
630 def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100631 // Enforce highstate asynchronous only on the nodes which are not glusterfs servers
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200632 salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound)
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100633 // Iterate over nonempty set of gluster servers and apply highstates one by one
634 // TODO: switch to batch once salt 2017.7+ would be used
Dzmitry Stremkouski47a45122018-04-25 17:05:56 +0200635 def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
636 if ( !saltcaMinions.isEmpty() ) {
637 for ( target in saltcaMinions ) {
638 salt.enforceHighstate(venvPepper, target)
639 }
640 }
Dzmitry Stremkouskifa4c1632018-03-21 17:55:39 +0100641 def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
642 if ( !glusterMinions.isEmpty() ) {
643 for ( target in glusterMinions ) {
644 salt.enforceHighstate(venvPepper, target)
645 }
646 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100647 }
648
649 outputsPretty = common.prettify(outputs)
650 print(outputsPretty)
651 writeFile(file: 'outputs.json', text: outputsPretty)
652 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100653 }
654
Jakub Josefa63f9862018-01-11 17:58:38 +0100655 } catch (Throwable e) {
656 currentBuild.result = 'FAILURE'
657 throw e
658 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100659
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400660
Jakub Josefa63f9862018-01-11 17:58:38 +0100661 //
662 // Clean
663 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400664
Jakub Josefa63f9862018-01-11 17:58:38 +0100665 if (common.validInputParam('STACK_NAME')) {
666 // send notification
667 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200668 }
669
Jakub Josefa63f9862018-01-11 17:58:38 +0100670 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
671 stage('Trigger cleanup job') {
672 common.errorMsg('Stack cleanup job triggered')
673 build(job: STACK_CLEANUP_JOB, parameters: [
674 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
675 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
676 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
677 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
678 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
679 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
680 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
681 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
682 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
683 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
684 ])
685 }
686 } else {
687 if (currentBuild.result == 'FAILURE') {
688 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 +0300689
Jakub Josefa63f9862018-01-11 17:58:38 +0100690 if (common.validInputParam('SALT_MASTER_URL')) {
691 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
692 }
Ales Komarek24097402017-05-22 16:28:10 +0200693 }
694 }
695 }
696 }
697}