-
Notifications
You must be signed in to change notification settings - Fork 46
/
cloud-deploy-pipeline.groovy
766 lines (649 loc) · 37.4 KB
/
cloud-deploy-pipeline.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/**
*
* Launch stack and work with it
*
* Expected parameters:
* STACK_NAME Infrastructure stack name
* STACK_TEMPLATE File with stack template
* STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started
*
* STACK_TEMPLATE_URL URL to git repo with stack templates
* STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo
* STACK_TEMPLATE_BRANCH Stack templates repo branch
*
* STACK_DELETE Delete stack when finished (bool)
* STACK_REUSE Reuse existing stack (don't create one, only read outputs)
* STACK_INSTALL What should be installed (k8s, openstack, ...)
* STACK_TEST Run tests (bool)
* STACK_CLEANUP_JOB Name of job for deleting stack
*
* STACK_COMPUTE_COUNT Number of compute nodes to launch
* STACK_CLUSTER_NAME The name of cluster model to use
* STATIC_MGMT_NETWORK Check if model contains static IP address definitions for all nodes
*
* AWS_STACK_REGION CloudFormation AWS region
* AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
* AWS_SSH_KEY AWS key pair name (used for SSH access)
*
* HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
* HEAT_STACK_ZONE Heat stack availability zone
* HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
* OPENSTACK_API_URL OpenStack API address
* OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
* OPENSTACK_API_PROJECT OpenStack project to connect to
* OPENSTACK_API_CLIENT Versions of OpenStack python clients
* OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
* SLAVE_NODE Lable or node name where the job will be run
* SALT_MASTER_CREDENTIALS Credentials to the Salt API
* required for STACK_TYPE=physical
* SALT_MASTER_URL URL of Salt master
* BOOTSTRAP_EXTRA_REPO_PARAMS optional parameter to define a list of extra repos with parameters
* which have to be added during bootstrap.
* Format: repo 1, repo priority 1, repo pin 1; repo 2, repo priority 2, repo pin 2;
* SALT_VERSION Version of Salt which is going to be installed i.e. 'stable 2016.3' or 'stable 2017.7' etc.
*
* EXTRA_TARGET The value will be added to target nodes
* BATCH_SIZE Use batching for states, which may be targeted for huge amount of nodes. Format:
- 10 - number of nodes
- 10% - percentage of all targeted nodes
* DIST_UPGRADE_NODES Whether to run "apt-get dist-upgrade" on all nodes in cluster before deployment
* UPGRADE_SALTSTACK Whether to install recent versions of saltstack packages
*
* Test settings:
* TEST_K8S_API_SERVER Kubernetes API address
* TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
*
* TEST_DOCKER_INSTALL Install docker on the target if true
* TEST_TEMPEST_IMAGE Tempest image link
* TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
* TEST_TEMPEST_TARGET Salt target for tempest node
* TESTRAIL_REPORT Whether upload results to testrail or not
* TESTRAIL_REPORTER_IMAGE Docker image for testrail reporter
* TESTRAIL_QA_CREDENTIALS Credentials for upload to testrail
* TESTRAIL_MILESTONE Product version for tests
* TESTRAIL_PLAN Testrail test plan
* TESTRAIL_GROUP Testrail test group
* TESTRAIL_SUITE Testrail test suite
*
* optional parameters for overwriting soft params
* SALT_OVERRIDES YAML with overrides for Salt deployment
*
*/
common = new com.mirantis.mk.Common()
git = new com.mirantis.mk.Git()
openstack = new com.mirantis.mk.Openstack()
aws = new com.mirantis.mk.Aws()
orchestrate = new com.mirantis.mk.Orchestrate()
python = new com.mirantis.mk.Python()
salt = new com.mirantis.mk.Salt()
test = new com.mirantis.mk.Test()
debian = new com.mirantis.mk.Debian()
_MAX_PERMITTED_STACKS = 2
overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
// Define global variables
def venv
def venvPepper
def outputs = [:]
def ipRegex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
if (STACK_TYPE == 'aws') {
def aws_env_vars
} else if (STACK_TYPE == 'heat') {
def envParams
def openstackCloud
}
def slave_node = 'python'
if (common.validInputParam('SLAVE_NODE')) {
slave_node = SLAVE_NODE
}
def extra_tgt = ''
def extra_tgt_bckp = ''
if (common.validInputParam('EXTRA_TARGET')) {
extra_tgt = "${EXTRA_TARGET}"
}
def batch_size = ''
if (common.validInputParam('BATCH_SIZE')) {
batch_size = "${BATCH_SIZE}"
}
def upgrade_nodes = false
if (common.validInputParam('DIST_UPGRADE_NODES')) {
upgrade_nodes = "${DIST_UPGRADE_NODES}".toBoolean()
}
def upgrade_salt = false
if (common.validInputParam('UPGRADE_SALTSTACK')){
upgrade_salt = "${UPGRADE_SALTSTACK}".toBoolean()
}
timeout(time: 12, unit: 'HOURS') {
node(slave_node) {
try {
// Set build-specific variables
def workspace = common.getWorkspace()
venv = "${workspace}/venv"
venvPepper = "${workspace}/venvPepper"
if(common.validInputParam("STACK_DELETE") && STACK_DELETE.toBoolean()){
common.warningMsg("You running stack with STACK_DELETE option enabled, deployed stack will be removed at the end!")
}
//
// Prepare machines
//
stage ('Create infrastructure') {
outputs.put('stack_type', STACK_TYPE)
if (STACK_TYPE == 'heat') {
// value defaults
envParams = [
'cluster_zone': HEAT_STACK_ZONE,
'cluster_public_net': HEAT_STACK_PUBLIC_NET
]
if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
error("If you want to reuse existing stack you need to provide it's name")
}
if (STACK_REUSE.toBoolean() == false) {
// TODO(vsaienko): remove stack creation from this pipeline to separate job
// Allow to set custom stack name but user-id will be added anyway
// This will fix issue with cleanup when job is aborted by jenkins and
// still guarantee stack count per user.
def stackNameSuffix = "${JOB_NAME}-${BUILD_NUMBER}"
if (STACK_NAME != ''){
stackNameSuffix = STACK_NAME
}
wrap([$class: 'BuildUser']) {
if (env.BUILD_USER_ID) {
STACK_NAME = "${env.BUILD_USER_ID}-${stackNameSuffix}"
} else {
STACK_NAME = "jenkins-${stackNameSuffix}"
}
currentBuild.description = STACK_NAME
}
} else {
// In case name was copied with unicode zero-width space chars -
// remove them
STACK_NAME = STACK_NAME.trim().replaceAll("\\p{C}", "")
}
// no underscore in STACK_NAME
STACK_NAME = STACK_NAME.replaceAll('_', '-')
outputs.put('stack_name', STACK_NAME)
// set description
currentBuild.description = "${STACK_NAME}"
// get templates
git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
// create openstack env
openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
openstackCloud = openstack.createOpenstackEnv(venv,
OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
OPENSTACK_API_VERSION)
openstack.getKeystoneToken(openstackCloud, venv)
//
// Verify possibility of create stack for given user and stack type
//
wrap([$class: 'BuildUser']) {
if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}".replaceAll('_', '-'), venv)
if (existingStacks.size() >= _MAX_PERMITTED_STACKS) {
STACK_DELETE = "false"
throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
}
}
}
// launch stack
if (STACK_REUSE.toBoolean() == false) {
// set reclass repo in heat env
try {
envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
} catch (MissingPropertyException e) {
common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
}
// put reclass-system repo to branch/tag/ref. If empty will be used reclass pinned commit in AIO model.
if (common.validInputParam('RECLASS_SYSTEM_BRANCH')) {
common.infoMsg("Setting reclass-system repo to ${RECLASS_SYSTEM_BRANCH} branch/tag/ref")
envParams.put('cfg_reclass_system_branch', RECLASS_SYSTEM_BRANCH)
}
// put formulas revision - stable, testing or nightly
if (common.validInputParam('FORMULA_PKG_REVISION')) {
common.infoMsg("Setting formulas revision to ${FORMULA_PKG_REVISION}")
envParams.put('cfg_formula_pkg_revision', FORMULA_PKG_REVISION)
}
// put extra repo definitions
if (common.validInputParam('BOOTSTRAP_EXTRA_REPO_PARAMS')) {
common.infoMsg("Setting additional repo during bootstrap to ${BOOTSTRAP_EXTRA_REPO_PARAMS}")
envParams.put('cfg_bootstrap_extra_repo_params', BOOTSTRAP_EXTRA_REPO_PARAMS)
}
// put extra salt-formulas # FIXME: looks like some outdated logic. See #PROD-23127
if (common.validInputParam('EXTRA_FORMULAS')) {
common.infoMsg("Setting extra salt-formulas to ${EXTRA_FORMULAS}")
envParams.put('cfg_extra_formulas', EXTRA_FORMULAS)
}
// add cluster name if specified
if (common.validInputParam('STACK_CLUSTER_NAME')) {
common.infoMsg("Setting cluster_name to ${STACK_CLUSTER_NAME}")
envParams.put('cluster_name', STACK_CLUSTER_NAME)
}
if (common.validInputParam('STACK_COMPUTE_COUNT')) {
if (STACK_COMPUTE_COUNT.toInteger() > 0){
common.infoMsg("Setting cluster_node_count to ${STACK_COMPUTE_COUNT}")
envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
}
}
if (common.validInputParam('SALT_VERSION')) {
common.infoMsg("Setting salt version to ${SALT_VERSION}")
envParams.put('cfg_saltversion', SALT_VERSION)
}
// If stack wasn't removed by the same user which has created it,
// nova key pair won't be removed, so need to make sure that no
// key pair with the same name exists before creating the stack.
if (openstack.getKeyPair(openstackCloud, STACK_NAME, venv)){
try {
openstack.deleteKeyPair(openstackCloud, STACK_NAME, venv)
} catch (Exception e) {
common.errorMsg("Key pair failed to remove with error ${e.message}")
}
}
openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv)
}
// get SALT_MASTER_URL
saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
// check that saltMasterHost is valid
if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
throw new Exception("saltMasterHost is not a valid ip")
}
currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
SALT_MASTER_URL = "http://${saltMasterHost}:6969"
} else if (STACK_TYPE == 'aws') {
// setup environment
aws.setupVirtualEnv(venv)
// set aws_env_vars
aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
error("If you want to reuse existing stack you need to provide it's name")
}
if (STACK_REUSE.toBoolean() == false) {
// Don't allow to set custom stack name
wrap([$class: 'BuildUser']) {
if (env.BUILD_USER_ID) {
STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
} else {
STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
}
}
// no underscore in STACK_NAME
STACK_NAME = STACK_NAME.replaceAll('_', '-')
}
// set description
currentBuild.description = STACK_NAME
outputs.put('stack_name', STACK_NAME)
if (STACK_REUSE.toBoolean() == false) {
// get templates
git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
// start stack
def stack_params = [
"ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
"ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
]
def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
}
// wait for stack to be ready
aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
// get outputs
saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
// check that saltMasterHost is valid
if (!saltMasterHost || !saltMasterHost.matches(ipRegex)) {
common.errorMsg("saltMasterHost is not a valid ip, value is: ${saltMasterHost}")
throw new Exception("saltMasterHost is not a valid ip")
}
currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
SALT_MASTER_URL = "http://${saltMasterHost}:6969"
} else if (STACK_TYPE != 'physical') {
throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
}
outputs.put('salt_api', SALT_MASTER_URL)
// Setup virtualenv for pepper
python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
}
// Set up override params
if (common.validInputParam('SALT_OVERRIDES') && common.validInputParam('STACK_INSTALL')) {
stage('Set Salt overrides') {
salt.setSaltOverrides(venvPepper, SALT_OVERRIDES, '/srv/salt/reclass', extra_tgt)
}
}
//
// Install
//
if (!batch_size) {
// if no batch size provided get current worker threads and set batch size to 2/3 of it to avoid
// 'SaltReqTimeoutError: Message timed out' issue on Salt targets for large amount of nodes
// do not use toDouble/Double as it requires additional approved method
def workerThreads = salt.getWorkerThreads(venvPepper).toInteger()
batch_size = (workerThreads * 2 / 3).toString().tokenize('.')[0]
}
// Check if all minions are reachable and ready
salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': '*', batch: batch_size])
if (common.checkContains('STACK_INSTALL', 'core')) {
stage('Install core infrastructure') {
def staticMgmtNetwork = false
if (common.validInputParam('STATIC_MGMT_NETWORK')) {
staticMgmtNetwork = STATIC_MGMT_NETWORK.toBoolean()
}
orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
if (upgrade_salt) {
debian.upgradeSaltPackages(venvPepper, 'I@salt:master')
debian.upgradeSaltPackages(venvPepper, 'I@salt:minion and not I@salt:master')
}
if (common.checkContains('STACK_INSTALL', 'kvm')) {
if (upgrade_nodes) {
debian.osUpgradeNode(venvPepper, 'I@salt:control', 'dist-upgrade', 30, 20, batch_size)
salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'I@salt:control', wait: 60, timeout: 10])
}
orchestrate.installInfraKvm(venvPepper, extra_tgt)
orchestrate.installFoundationInfra(venvPepper, staticMgmtNetwork, extra_tgt, batch_size)
}
orchestrate.validateFoundationInfra(venvPepper, extra_tgt)
}
if (upgrade_nodes) {
debian.osUpgradeNode(venvPepper, 'not ( I@salt:master or I@salt:control )', 'dist-upgrade', false, 30, 10, batch_size)
salt.checkTargetMinionsReady(['saltId': venvPepper, 'target': 'not ( I@salt:master or I@salt:control )', wait: 60, timeout: 10])
}
}
stage('Install infra') {
if (common.checkContains('STACK_INSTALL', 'core') ||
common.checkContains('STACK_INSTALL', 'openstack') ||
common.checkContains('STACK_INSTALL', 'cicd')) {
orchestrate.installInfra(venvPepper, extra_tgt)
}
}
if (common.validInputParam('STACK_INSTALL')) {
stage('Install Orchestrated Apps'){
orchestrate.OrchestrateApplications(venvPepper, "I@salt:master ${extra_tgt}", "orchestration.deploy.applications")
}
}
// install k8s
if (common.checkContains('STACK_INSTALL', 'k8s')) {
extra_tgt_bckp = extra_tgt
extra_tgt = 'and not kdt* and not I@salt:master ' + extra_tgt_bckp
stage('Install Kubernetes infra') {
if (STACK_TYPE == 'aws') {
// configure kubernetes_control_address - save loadbalancer
def awsOutputs = aws.getOutputs(venv, aws_env_vars, STACK_NAME)
common.prettyPrint(awsOutputs)
if (awsOutputs.containsKey('ControlLoadBalancer')) {
salt.runSaltProcessStep(venvPepper, "I@salt:master ${extra_tgt}", 'reclass.cluster_meta_set', ['kubernetes_control_address', awsOutputs['ControlLoadBalancer']], null, true)
outputs.put('kubernetes_apiserver', 'https://' + awsOutputs['ControlLoadBalancer'])
}
}
// ensure certificates are generated properly
salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
}
if (common.checkContains('STACK_INSTALL', 'contrail')) {
stage('Install Contrail control') {
orchestrate.installContrailNetwork(venvPepper, extra_tgt)
}
}
stage('Install Kubernetes control') {
orchestrate.installKubernetesControl(venvPepper, extra_tgt)
if (common.checkContains('STACK_INSTALL', 'contrail')) {
orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
}
// collect artifacts (kubeconfig)
writeFile(file: 'kubeconfig', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config'))
archiveArtifacts(artifacts: 'kubeconfig')
}
if (common.checkContains('STACK_INSTALL', 'contrail')) {
stage('Install Contrail compute') {
orchestrate.installContrailCompute(venvPepper, extra_tgt)
}
}
stage('Install Kubernetes computes') {
if (common.validInputParam('STACK_COMPUTE_COUNT')) {
if (STACK_COMPUTE_COUNT > 0) {
if (STACK_TYPE == 'aws') {
// get stack info
def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
//update autoscaling group
aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
// wait for computes to boot up
aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
sleep(60)
} else if (STACK_TYPE == 'heat') {
envParams.put('cluster_node_count', STACK_COMPUTE_COUNT)
openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, "update")
sleep(60)
}
}
}
orchestrate.installKubernetesCompute(venvPepper, extra_tgt)
// Setup kubernetes addons for opencontrail. More info in the definition of the func.
orchestrate.setupKubeAddonForContrail(venvPepper, extra_tgt)
}
orchestrate.installKubernetesClient(venvPepper, extra_tgt)
extra_tgt = extra_tgt_bckp
}
// install kdt (drivetrain on k8s) cluster
if (common.checkContains('STACK_INSTALL', 'kdt')){
extra_tgt_bckp = extra_tgt
extra_tgt = 'and kdt* ' + extra_tgt_bckp
stage('Install Kubernetes infra for kdt') {
// ensure certificates are generated properly
salt.runSaltProcessStep(venvPepper, "I@kubernetes:* ${extra_tgt}", 'saltutil.refresh_pillar', [], null, true)
salt.enforceState(venvPepper, "I@kubernetes:* ${extra_tgt}", ['salt.minion.cert'], true)
}
stage('Install Kubernetes control for kdt') {
salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'kubernetes.pool.images'])
orchestrate.installKubernetesControl(venvPepper, extra_tgt)
salt.enforceStateWithTest([saltId: venvPepper, target: "I@kubernetes:master ${extra_tgt}", state: 'nginx.server'])
// collect artifacts (kubeconfig)
writeFile(file: 'kubeconfig-kdt', text: salt.getFileContent(venvPepper, "I@kubernetes:master and *01* ${extra_tgt}", '/etc/kubernetes/admin-kube-config'))
archiveArtifacts(artifacts: 'kubeconfig-kdt')
}
orchestrate.installKubernetesClient(venvPepper, extra_tgt)
extra_tgt = extra_tgt_bckp
}
// install ceph
if (common.checkContains('STACK_INSTALL', 'ceph')) {
stage('Install Ceph MONs') {
orchestrate.installCephMon(venvPepper, "I@ceph:mon ${extra_tgt}", extra_tgt)
}
stage('Install Ceph OSDs') {
orchestrate.installCephOsd(venvPepper, "I@ceph:osd ${extra_tgt}", true, extra_tgt)
}
stage('Install Ceph clients') {
orchestrate.installCephClient(venvPepper, extra_tgt)
}
}
// install docker swarm
if (common.validInputParam('STACK_INSTALL')) {
orchestrate.installDockerSwarm(venvPepper, extra_tgt)
}
// install openstack
if (common.checkContains('STACK_INSTALL', 'openstack')) {
// install control, tests, ...
stage('Install OpenStack control') {
orchestrate.installOpenstackControl(venvPepper, extra_tgt)
}
// Workaround for PROD-17765 issue to prevent crashes of keystone.role_present state.
// More details: https://mirantis.jira.com/browse/PROD-17765
salt.restartSaltMinion(venvPepper, "I@keystone:client ${extra_tgt}")
salt.minionsReachable(venvPepper, 'I@salt:master', "I@keystone:client ${extra_tgt}", null, 10, 6)
stage('Install OpenStack network') {
if (common.checkContains('STACK_INSTALL', 'contrail')) {
orchestrate.installContrailNetwork(venvPepper, extra_tgt)
orchestrate.checkContrailApiReadiness(venvPepper, extra_tgt)
} else if (common.checkContains('STACK_INSTALL', 'ovs')) {
orchestrate.installOpenstackNetwork(venvPepper, extra_tgt)
}
// Wait for network to come up, 150s should be enough
common.retry(10, 15) {
salt.cmdRun(venvPepper, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack network list')
}
}
if (salt.testTarget(venvPepper, "I@ironic:conductor ${extra_tgt}")){
stage('Install OpenStack Ironic conductor') {
orchestrate.installIronicConductor(venvPepper, extra_tgt)
}
}
if (salt.testTarget(venvPepper, "I@manila:share ${extra_tgt}")){
stage('Install OpenStack Manila data and share') {
orchestrate.installManilaShare(venvPepper, extra_tgt)
}
}
stage('Install OpenStack compute') {
orchestrate.installOpenstackCompute(venvPepper, extra_tgt, batch_size)
if (common.checkContains('STACK_INSTALL', 'contrail')) {
orchestrate.installContrailCompute(venvPepper, extra_tgt)
orchestrate.installBackup(venvPepper, 'contrail', extra_tgt)
}
}
}
// connect ceph
if (common.checkContains('STACK_INSTALL', 'ceph')) {
stage('Connect Ceph') {
orchestrate.connectCeph(venvPepper, extra_tgt)
}
}
if (common.checkContains('STACK_INSTALL', 'cicd')) {
stage('Install Cicd') {
extra_tgt_bckp = extra_tgt
extra_tgt = 'and I@_param:drivetrain_role:cicd ' + extra_tgt_bckp
orchestrate.installCicd(venvPepper, extra_tgt)
extra_tgt = extra_tgt_bckp
}
}
if (common.checkContains('STACK_INSTALL', 'kdt')) {
stage('Install Cicd on kdt') {
extra_tgt_bckp = extra_tgt
extra_tgt = 'and kdt* ' + extra_tgt_bckp
orchestrate.installCicd(venvPepper, extra_tgt)
extra_tgt = extra_tgt_bckp
}
}
if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
stage('Install StackLight v1') {
orchestrate.installStacklightv1Control(venvPepper, extra_tgt)
orchestrate.installStacklightv1Client(venvPepper, extra_tgt)
}
}
if (common.checkContains('STACK_INSTALL', 'stacklight')) {
stage('Install StackLight') {
orchestrate.installStacklight(venvPepper, extra_tgt)
}
}
//
// Test
//
def artifacts_dir = '_artifacts/'
if (common.checkContains('STACK_TEST', 'k8s')) {
stage('Run k8s conformance e2e tests') {
def image = TEST_K8S_CONFORMANCE_IMAGE
def autodetect = AUTODETECT
def ctl_target = 'I@kubernetes:master'
firstTarget = salt.getFirstMinion(venvPepper, ctl_target)
def containerd_enabled = salt.getPillar(
venvPepper, firstTarget, "kubernetes:common:containerd:enabled"
)["return"][0].values()[0].toBoolean()
if (containerd_enabled) {
def config = ['master': venvPepper,
'target': firstTarget,
'junitResults': true,
'autodetect': autodetect,
'image': image]
test.executeConformance(config)
} else {
def output_file = image.replaceAll('/', '-') + '.output'
def target = "I@keystone:server:role:primary ${extra_tgt}"
def conformance_output_file = 'conformance_test.tar'
// run image
test.runConformanceTests(venvPepper, target, TEST_K8S_API_SERVER, image)
// collect output
sh "mkdir -p ${artifacts_dir}"
file_content = salt.getFileContent(venvPepper, target, '/tmp/' + output_file)
writeFile file: "${artifacts_dir}${output_file}", text: file_content
sh "cat ${artifacts_dir}${output_file}"
// collect artifacts
archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
// Copy test results
test.CopyConformanceResults(venvPepper, target, artifacts_dir, conformance_output_file)
}
}
}
if (common.checkContains('STACK_TEST', 'opencontrail')) {
stage('Run opencontrail tests') {
def opencontrail_tests_dir = "/opt/opencontrail_test/fuel-plugin-contrail/plugin_test/vapor/"
def report_dir = "/opt/opencontrail-test-report/"
def cmd = ". ${opencontrail_tests_dir}exports.sh && " +
"cd ${opencontrail_tests_dir} && " +
"py.test --junit-xml=${report_dir}report.xml" +
" --html=${report_dir}report.html -v vapor/tests/ -k 'not destructive' "
salt.runSaltProcessStep(venvPepper, 'I@salt:master', 'saltutil.refresh_pillar', [], null, true)
salt.enforceState(venvPepper, 'I@opencontrail:test' , 'opencontrail.test' , true)
salt.cmdRun(venvPepper, 'I@opencontrail:test', cmd, false)
writeFile(file: 'report.xml', text: salt.getFileContent(venvPepper,
'I@opencontrail:test', "${report_dir}report.xml"))
junit(keepLongStdio: true, testResults: 'report.xml')
}
}
stage('Finalize') {
if (common.checkContains('STACK_INSTALL', 'finalize')) {
def gluster_compound = "I@glusterfs:server ${extra_tgt}"
def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
// Enforce highstate asynchronous only on the nodes which are not glusterfs servers
salt.enforceHighstate(venvPepper, '* and not ' + gluster_compound + ' and not ' + salt_ca_compound, batch_size)
// Iterate over nonempty set of gluster servers and apply highstates one by one
// TODO: switch to batch once salt 2017.7+ would be used
def saltcaMinions = salt.getMinionsSorted(venvPepper, salt_ca_compound)
if ( !saltcaMinions.isEmpty() ) {
for ( target in saltcaMinions ) {
salt.enforceHighstate(venvPepper, target)
}
}
def glusterMinions = salt.getMinionsSorted(venvPepper, gluster_compound)
if ( !glusterMinions.isEmpty() ) {
for ( target in glusterMinions ) {
salt.enforceHighstate(venvPepper, target)
}
}
}
outputsPretty = common.prettify(outputs)
print(outputsPretty)
writeFile(file: 'outputs.json', text: outputsPretty)
archiveArtifacts(artifacts: 'outputs.json')
}
} catch (Throwable e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
//
// Clean
//
if (common.validInputParam('STACK_NAME')) {
// send notification
common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
}
if (common.validInputParam('STACK_DELETE') && STACK_DELETE.toBoolean() == true) {
stage('Trigger cleanup job') {
common.errorMsg('Stack cleanup job triggered')
build(job: STACK_CLEANUP_JOB, parameters: [
[$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
[$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
[$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
])
}
} else {
if (currentBuild.result == 'FAILURE') {
common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
if (common.validInputParam('SALT_MASTER_URL')) {
common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
}
}
}
}
}
}