blob: 47fcc362d4b4877738bada49735dc0b2bf10abbe [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
Jiri Broulik61b3e5d2017-12-19 15:42:30 +010021 * STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
Tomáš Kukrál74f92862017-06-05 19:18:43 +020022 *
Ales Komarek24097402017-05-22 16:28:10 +020023 * AWS_STACK_REGION CloudFormation AWS region
24 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020025 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020026 *
27 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
28 * HEAT_STACK_ZONE Heat stack availability zone
29 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
30 * OPENSTACK_API_URL OpenStack API address
31 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
32 * OPENSTACK_API_PROJECT OpenStack project to connect to
33 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
34 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Oleh Hryhorov9630a762017-10-24 14:33:25 +030035 * SLAVE_NODE Lable or node name where the job will be run
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020036
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020038 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020039 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020040
Oleg Iurchenko9a8c3d72017-12-21 14:55:38 +020041 * BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
42 * which have to be added during bootstrap.
43 * Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
44
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020045 * Test settings:
46 * TEST_K8S_API_SERVER Kubernetes API address
47 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020048 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020049 * TEST_DOCKER_INSTALL Install docker on the target if true
50 * TEST_TEMPEST_IMAGE Tempest image link
51 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
52 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020053 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020054 * optional parameters for overwriting soft params
55 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020056 *
57 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020058
Ales Komarek24097402017-05-22 16:28:10 +020059common = new com.mirantis.mk.Common()
60git = new com.mirantis.mk.Git()
61openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020062aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020063orchestrate = new com.mirantis.mk.Orchestrate()
Mykyta Karpine016d7e2017-10-09 13:35:20 +030064python = new com.mirantis.mk.Python()
Ales Komarek24097402017-05-22 16:28:10 +020065salt = new com.mirantis.mk.Salt()
66test = new com.mirantis.mk.Test()
67
68_MAX_PERMITTED_STACKS = 2
69overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
70
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020071// Define global variables
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020072def venv
chnyda597fb032017-10-06 13:42:48 +020073def venvPepper
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +020074def outputs = [:]
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020075
chnydae14058a2017-08-29 15:07:48 +020076def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
77
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020078if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020079 def aws_env_vars
Tomáš Kukrál8427ff52017-08-30 15:46:52 +020080} else if (STACK_TYPE == 'heat') {
81 def envParams
82 def openstackCloud
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020083}
84
Oleh Hryhorov9630a762017-10-24 14:33:25 +030085def slave_node = 'python'
86
Oleh Hryhorov54460512017-10-26 18:45:36 +030087if (common.validInputParam('SLAVE_NODE')) {
Oleh Hryhorov9630a762017-10-24 14:33:25 +030088 slave_node = SLAVE_NODE
89}
Jakub Josefa63f9862018-01-11 17:58:38 +010090timeout(time: 12, unit: 'HOURS') {
91 node(slave_node) {
92 try {
93 // Set build-specific variables
94 venv = "${env.WORKSPACE}/venv"
95 venvPepper = "${env.WORKSPACE}/venvPepper"
Oleh Hryhorov9630a762017-10-24 14:33:25 +030096
Jakub Josefa63f9862018-01-11 17:58:38 +010097 //
98 // Prepare machines
99 //
100 stage ('Create infrastructure') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200101
Jakub Josefa63f9862018-01-11 17:58:38 +0100102 outputs.put('stack_type', STACK_TYPE)
Ales Komarek24097402017-05-22 16:28:10 +0200103
Jakub Josefa63f9862018-01-11 17:58:38 +0100104 if (STACK_TYPE == 'heat') {
105 // value defaults
106 envParams = [
107 'cluster_zone': HEAT_STACK_ZONE,
108 'cluster_public_net': HEAT_STACK_PUBLIC_NET
109 ]
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200110
Jakub Josefa63f9862018-01-11 17:58:38 +0100111 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
112 error("If you want to reuse existing stack you need to provide it's name")
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400113 }
Tomáš Kukrál550364e2017-08-23 11:42:45 +0200114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 if (STACK_REUSE.toBoolean() == false) {
116 // Don't allow to set custom heat stack name
117 wrap([$class: 'BuildUser']) {
118 if (env.BUILD_USER_ID) {
119 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
120 } else {
121 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
122 }
123 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +0200124 }
125 }
126
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400127 // no underscore in STACK_NAME
128 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Jakub Josefa63f9862018-01-11 17:58:38 +0100129 outputs.put('stack_name', STACK_NAME)
Ales Komarek24097402017-05-22 16:28:10 +0200130
Jakub Josefa63f9862018-01-11 17:58:38 +0100131 // set description
132 currentBuild.description = "${STACK_NAME}"
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400133
Ales Komarek24097402017-05-22 16:28:10 +0200134 // get templates
135 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
136
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 // create openstack env
138 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
139 openstackCloud = openstack.createOpenstackEnv(
140 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
141 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
142 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
143 OPENSTACK_API_VERSION)
144 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200145
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 //
147 // Verify possibility of create stack for given user and stack type
148 //
149 wrap([$class: 'BuildUser']) {
150 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
151 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
152 if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
153 STACK_DELETE = "false"
154 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
155 }
156 }
Tomáš Kukrál8e50d8e2017-09-01 17:40:53 +0200157 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100158 // launch stack
159 if (STACK_REUSE.toBoolean() == false) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400160
Jakub Josefa63f9862018-01-11 17:58:38 +0100161 // set reclass repo in heat env
162 try {
163 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
164 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
165 } catch (MissingPropertyException e) {
166 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 +0100167 }
168
Jakub Josefa63f9862018-01-11 17:58:38 +0100169 // put formulas revision - stable, testing or nightly
170 if (common.validInputParam('FORMULA_PKG_REVISION')) {
171 common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
172 envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
173 }
174
175 // put extra repo definitions
176 if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
177 common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
178 envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
179 }
180
181 // put extra salt-formulas
182 if (common.validInputParam('EXTRA_FORMULAS')) {
183 common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
184 envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
185 }
186
187 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
188 }
189
190 // get SALT_MASTER_URL
191 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
192 // check that saltMasterHost is valid
193 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
194 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
195 throw new Exception("saltMasterHost is not a valid ip")
196 }
197
198 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
199
200 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
201
202 } else if (STACK_TYPE == 'aws') {
203
204 // setup environment
205 aws.setupVirtualEnv(venv)
206
207 // set aws_env_vars
208 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
209
210 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
211 error("If you want to reuse existing stack you need to provide it's name")
212 }
213
214 if (STACK_REUSE.toBoolean() == false) {
215 // Don't allow to set custom stack name
216 wrap([$class: 'BuildUser']) {
217 if (env.BUILD_USER_ID) {
218 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
219 } else {
220 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
221 }
222 }
223
224 // no underscore in STACK_NAME
225 STACK_NAME = STACK_NAME.replaceAll('_', '-')
226 }
227
228 // set description
229 currentBuild.description = STACK_NAME
230 outputs.put('stack_name', STACK_NAME)
231
232 if (STACK_REUSE.toBoolean() == false) {
233 // get templates
234 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
235
236 // start stack
237 def stack_params = [
238 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
239 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
240 ]
241 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
242 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
243 }
244
245 // wait for stack to be ready
246 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
247
248 // get outputs
249 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
250
251 // check that saltMasterHost is valid
252 if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
253 common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
254 throw new Exception("saltMasterHost is not a valid ip")
255 }
256
257 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
258 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
259
260 } else if (STACK_TYPE != 'physical') {
261 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
262 }
263
264 outputs.put('salt_api', SALT_MASTER_URL)
265
266 // Setup virtualenv for pepper
267 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
268 }
269
270
271 // Set up override params
272 if (common.validInputParam('SALT_OVERRIDES')) {
273 stage('Set Salt overrides') {
274 salt.setSaltOverrides(venvPepper, SALT_OVERRIDES)
275 }
276 }
277
278 //
279 // Install
280 //
281
282 if (common.checkContains('STACK_INSTALL', 'core')) {
283 stage('Install core infrastructure') {
284 def staticMgmtNetwork = false
285 if (common.validInputParam('STATIC_MGMT_NETWORK')) {
286 staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
287 }
288 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
289
290 if (common.checkContains('STACK_INSTALL', 'kvm')) {
291 orchestrate.installInfraKvm(venvPepper)
292 orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork)
293 }
294
295 orchestrate.validateFoundationInfra(venvPepper)
296 }
297 }
298
299 // install k8s
300 if (common.checkContains('STACK_INSTALL', 'k8s')) {
301
302 stage('Install Kubernetes infra') {
303 if (STACK_TYPE == 'aws') {
304 // configure kubernetes_control_address - save loadbalancer
305 def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
306 common.prettyPrint(awsOutputs)
307 if (awsOutputs.containsKey('ControlLoadBalancer')) {
308 salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
309 outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
310 }
311 }
312
313 // ensure certificates are generated properly
314 salt.runSaltProcessStep(venvPepper, '*', 'saltutil.refresh_pillar', [], null, true)
315 salt.enforceState(venvPepper, '*', ['salt.minion.cert'], true)
316
317 orchestrate.installKubernetesInfra(venvPepper)
318 }
319
320 if (common.checkContains('STACK_INSTALL', 'contrail')) {
321 stage('Install Contrail for Kubernetes') {
322 orchestrate.installContrailNetwork(venvPepper)
323 orchestrate.installContrailCompute(venvPepper)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200324 }
Ales Komarek24097402017-05-22 16:28:10 +0200325 }
Tomáš Kukrálf83409d2017-11-08 20:56:57 +0100326
Jakub Josefa63f9862018-01-11 17:58:38 +0100327 stage('Install Kubernetes control') {
328 orchestrate.installKubernetesControl(venvPepper)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400329
Jakub Josefa63f9862018-01-11 17:58:38 +0100330 // collect artifacts (kubeconfig)
331 writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, 'I@kubernetes:master and *01*', '/etc/kubernetes/admin-kube-config'))
332 archiveArtifacts(artifacts: 'kubeconfig')
vrovachev7be1e962017-07-05 13:28:26 +0400333 }
334
Jakub Josefa63f9862018-01-11 17:58:38 +0100335 stage('Install Kubernetes computes') {
336 if (common.validInputParam('STACK_COMPUTE_COUNT')) {
337 if (STACK_COMPUTE_COUNT > 0) {
338 if (STACK_TYPE == 'aws') {
339 // get stack info
340 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
341
342 //update autoscaling group
343 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
344
345 // wait for computes to boot up
346 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
347 sleep(60)
348
349 } else if (STACK_TYPE == 'heat') {
350 envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
351
352 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
353 sleep(60)
354 }
355
356 }
357 }
358
359 orchestrate.installKubernetesCompute(venvPepper)
360 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400361 }
Ales Komarek24097402017-05-22 16:28:10 +0200362
Jakub Josefa63f9862018-01-11 17:58:38 +0100363 // install openstack
364 if (common.checkContains('STACK_INSTALL', 'openstack')) {
365 // install Infra and control, tests, ...
366
367 stage('Install OpenStack infra') {
368 orchestrate.installOpenstackInfra(venvPepper)
369 }
370
371 stage('Install OpenStack control') {
372 orchestrate.installOpenstackControl(venvPepper)
373 }
374
375 stage('Install OpenStack network') {
376
377 if (common.checkContains('STACK_INSTALL', 'contrail')) {
378 orchestrate.installContrailNetwork(venvPepper)
379 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
380 orchestrate.installOpenstackNetwork(venvPepper)
381 }
382
383 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
384 salt.runSaltProcessStep(venvPepper, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
385 }
386
387 if (salt.testTarget(venvPepper, 'I@ironic:conductor')){
388 stage('Install OpenStack Ironic conductor') {
389 orchestrate.installIronicConductor(venvPepper)
390 }
391 }
392
393
394 stage('Install OpenStack compute') {
395 orchestrate.installOpenstackCompute(venvPepper)
396
397 if (common.checkContains('STACK_INSTALL', 'contrail')) {
398 orchestrate.installContrailCompute(venvPepper)
399 }
400 }
401
402 }
403
404 // install ceph
405 if (common.checkContains('STACK_INSTALL', 'ceph')) {
406 stage('Install Ceph MONs') {
407 orchestrate.installCephMon(venvPepper)
408 }
409
410 stage('Install Ceph OSDs') {
411 orchestrate.installCephOsd(venvPepper)
412 }
413
414
415 stage('Install Ceph clients') {
416 orchestrate.installCephClient(venvPepper)
417 }
418
419 stage('Connect Ceph') {
420 orchestrate.connectCeph(venvPepper)
421 }
422 }
423
424 if (common.checkContains('STACK_INSTALL', 'oss')) {
425 stage('Install Oss infra') {
426 orchestrate.installOssInfra(venvPepper)
427 }
428 }
429
430 if (common.checkContains('STACK_INSTALL', 'cicd')) {
431 stage('Install Cicd') {
432 orchestrate.installInfra(venvPepper)
433 orchestrate.installDockerSwarm(venvPepper)
434 orchestrate.installCicd(venvPepper)
435 }
436 }
437
438 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
439 stage('Install StackLight v1') {
440 orchestrate.installStacklightv1Control(venvPepper)
441 orchestrate.installStacklightv1Client(venvPepper)
442 }
443 }
444
445 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
446 stage('Install StackLight') {
447 orchestrate.installDockerSwarm(venvPepper)
448 orchestrate.installStacklight(venvPepper)
449 }
450 }
451
452 if (common.checkContains('STACK_INSTALL', 'oss')) {
453 stage('Install OSS') {
454 if (!common.checkContains('STACK_INSTALL', 'stacklight')) {
455 // In case if StackLightv2 enabled containers already started
456 orchestrate.installDockerSwarm(venvPepper)
457 salt.enforceState(venvPepper, 'I@docker:swarm:role:master and I@devops_portal:config', 'docker.client', true)
458 }
459 orchestrate.installOss(venvPepper)
460 }
461 }
462
463 //
464 // Test
465 //
466 def artifacts_dir = '_artifacts/'
467
468 if (common.checkContains('STACK_TEST', 'k8s')) {
469 stage('Run k8s conformance e2e tests') {
470 def image = TEST_K8S_CONFORMANCE_IMAGE
471 def output_file = image.replaceAll('/', '-') + '.output'
vrovachevff3e72d2018-01-25 16:14:43 +0400472 def target = 'ctl01*'
473 def conformance_output_file = 'conformance_test.tar'
Jakub Josefa63f9862018-01-11 17:58:38 +0100474
475 // run image
vrovachevff3e72d2018-01-25 16:14:43 +0400476 test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
Jakub Josefa63f9862018-01-11 17:58:38 +0100477
478 // collect output
479 sh "mkdir -p ${artifacts_dir}"
vrovachevff3e72d2018-01-25 16:14:43 +0400480 file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100481 writeFile file: "${artifacts_dir}${output_file}", text: file_content
482 sh "cat ${artifacts_dir}${output_file}"
483
484 // collect artifacts
485 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
vrovachevff3e72d2018-01-25 16:14:43 +0400486
487 // Copy test results
488 test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
Jakub Josefa63f9862018-01-11 17:58:38 +0100489 }
490 }
491
492 if (common.checkContains('STACK_TEST', 'openstack')) {
493 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
494 test.install_docker(venvPepper, TEST_TEMPEST_TARGET)
495 }
496 stage('Run OpenStack tests') {
497 test.runTempestTests(venvPepper, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
498 }
499
500 stage('Copy Tempest results to config node') {
501 test.copyTempestResults(venvPepper, TEST_TEMPEST_TARGET)
502 }
503
504 stage('Archive rally artifacts') {
505 test.archiveRallyArtifacts(venvPepper, TEST_TEMPEST_TARGET)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200506 }
Ales Komarek24097402017-05-22 16:28:10 +0200507 }
508
Ales Komarek24097402017-05-22 16:28:10 +0200509
Jakub Josefa63f9862018-01-11 17:58:38 +0100510 if (common.checkContains('STACK_TEST', 'ceph')) {
511 stage('Run infra tests') {
512 sleep(120)
513 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/"
514 salt.cmdRun(venvPepper, 'I@salt:master', cmd, false)
515 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper, 'I@salt:master', '/root/report.xml'))
516 junit(keepLongStdio: true, testResults: 'report.xml')
Martin Polreich46971102017-07-11 12:56:40 +0200517 }
518 }
519
Jakub Josefa63f9862018-01-11 17:58:38 +0100520 if (common.checkContains('STACK_TEST', 'opencontrail')) {
521 stage('Run opencontrail tests') {
522 def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
523 def report_dir = "/opt/opencontrail-test-report/"
524 def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
525 "cd ${opencontrail_tests_dir} && " +
526 "py.test --junit-xml=${report_dir}report.xml" +
527 " --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400528
Jakub Josefa63f9862018-01-11 17:58:38 +0100529 salt.runSaltProcessStep(venvPepper, 'cfg*', 'saltutil.refresh_pillar', [], null, true)
530 salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100531
Jakub Josefa63f9862018-01-11 17:58:38 +0100532 salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
533
534 writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
535 'I@opencontrail:test', "${report_dir}report.xml"))
536 junit(keepLongStdio: true, testResults: 'report.xml')
537 }
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100538 }
539
540
Jakub Josefa63f9862018-01-11 17:58:38 +0100541 stage('Finalize') {
542 if (common.checkContains('STACK_INSTALL', 'finalize')) {
543 salt.runSaltProcessStep(venvPepper, '*', 'state.apply', [], null, true)
544 }
545
546 outputsPretty = common.prettify(outputs)
547 print(outputsPretty)
548 writeFile(file: 'outputs.json', text: outputsPretty)
549 archiveArtifacts(artifacts: 'outputs.json')
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100550 }
551
Jakub Josefa63f9862018-01-11 17:58:38 +0100552 } catch (Throwable e) {
553 currentBuild.result = 'FAILURE'
554 throw e
555 } finally {
Jiri Broulikd01c42f2018-01-02 11:37:10 +0100556
Mikhail Ivanov3deb79a2017-12-06 17:44:47 +0400557
Jakub Josefa63f9862018-01-11 17:58:38 +0100558 //
559 // Clean
560 //
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400561
Jakub Josefa63f9862018-01-11 17:58:38 +0100562 if (common.validInputParam('STACK_NAME')) {
563 // send notification
564 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Ales Komarek24097402017-05-22 16:28:10 +0200565 }
566
Jakub Josefa63f9862018-01-11 17:58:38 +0100567 if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
568 stage('Trigger cleanup job') {
569 common.errorMsg('Stack cleanup job triggered')
570 build(job: STACK_CLEANUP_JOB, parameters: [
571 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
572 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
573 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
574 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
575 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
576 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
577 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
578 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
579 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
580 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
581 ])
582 }
583 } else {
584 if (currentBuild.result == 'FAILURE') {
585 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 +0300586
Jakub Josefa63f9862018-01-11 17:58:38 +0100587 if (common.validInputParam('SALT_MASTER_URL')) {
588 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
589 }
Ales Komarek24097402017-05-22 16:28:10 +0200590 }
591 }
592 }
593 }
594}