blob: e24911268b049d03ec75bfe44cb8a681578fe6f1 [file] [log] [blame]
Jiri Broulik60dcab32018-03-08 17:42:06 +01001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
7 * SNAPSHOT_NAME Snapshot name
8 * CFG_NODE_PROVIDER Physical machine name hosting Salt-Master VM (ex. kvm01*)
9 * INTERACTIVE Ask interactive questions during pipeline run (bool)
10 * PER_NODE Target nodes will be managed one by one (bool)
11 * ROLLBACK_BY_REDEPLOY Omit taking live snapshots. Rollback is planned to be done by redeployment (bool)
12 * STOP_SERVICES Stop API services before update (bool)
13 * TARGET_UPDATES Comma separated list of nodes to update (Valid values are cfg,ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cid,cmp,kvm,osd,gtw-physical)
Jiri Broulik906e9972018-03-26 16:12:00 +020014 * TARGET_ROLLBACKS Comma separated list of nodes to rollback (Valid values are ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cmp,kvm,osd,gtw-physical)
15 * TARGET_MERGES Comma separated list of nodes to merge (Valid values are cfg,ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cid)
Jiri Broulik60dcab32018-03-08 17:42:06 +010016 * CTL_TARGET Salt targeted CTL nodes (ex. ctl*)
17 * PRX_TARGET Salt targeted PRX nodes (ex. prx*)
18 * MSG_TARGET Salt targeted MSG nodes (ex. msg*)
19 * DBS_TARGET Salt targeted DBS nodes (ex. dbs*)
20 * LOG_TARGET Salt targeted LOG nodes (ex. log*)
21 * MON_TARGET Salt targeted MON nodes (ex. mon*)
22 * MTR_TARGET Salt targeted MTR nodes (ex. mtr*)
23 * NTW_TARGET Salt targeted NTW nodes (ex. ntw*)
24 * NAL_TARGET Salt targeted NAL nodes (ex. nal*)
25 * CMN_TARGET Salt targeted CMN nodes (ex. cmn*)
26 * RGW_TARGET Salt targeted RGW nodes (ex. rgw*)
27 * CID_TARGET Salt targeted CID nodes (ex. cid*)
28 * CMP_TARGET Salt targeted physical compute nodes (ex. cmp001*)
29 * KVM_TARGET Salt targeted physical KVM nodes (ex. kvm01*)
30 * CEPH_OSD_TARGET Salt targeted physical Ceph OSD nodes (ex. osd001*)
Jiri Broulik906e9972018-03-26 16:12:00 +020031 * GTW_TARGET Salt targeted physical or virtual GTW nodes (ex. gtw01*)
Jiri Broulik60dcab32018-03-08 17:42:06 +010032 * REBOOT Reboot nodes after update (bool)
Jiri Broulik906e9972018-03-26 16:12:00 +020033 * ROLLBACK_PKG_VERSIONS Space separated list of pkgs=versions to rollback to on physical targeted machines (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
34 * PURGE_PKGS Space separated list of pkgs=versions to be purged on physical targeted machines (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
35 * REMOVE_PKGS Space separated list of pkgs=versions to be removed on physical targeted machines (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
Jiri Broulik60dcab32018-03-08 17:42:06 +010036 * RESTORE_GALERA Restore Galera DB (bool)
37 * RESTORE_CONTRAIL_DB Restore Cassandra and Zookeeper DBs for OpenContrail (bool)
38 *
39**/
40def common = new com.mirantis.mk.Common()
41def salt = new com.mirantis.mk.Salt()
42def python = new com.mirantis.mk.Python()
43def virsh = new com.mirantis.mk.Virsh()
44
45def updates = TARGET_UPDATES.tokenize(",").collect{it -> it.trim()}
46def rollbacks = TARGET_ROLLBACKS.tokenize(",").collect{it -> it.trim()}
47def merges = TARGET_MERGES.tokenize(",").collect{it -> it.trim()}
48
49def pepperEnv = "pepperEnv"
50def minions
51def result
52def packages
53def command
54def commandKwargs
55
56def updatePkgs(pepperEnv, target, targetType="", targetPackages="") {
57 def salt = new com.mirantis.mk.Salt()
58 def common = new com.mirantis.mk.Common()
59 def commandKwargs
60 def distUpgrade
61 def pkgs
62 def out
63
64 salt.enforceState(pepperEnv, target, 'linux.system.repo')
65
66 stage("List package upgrades") {
67 common.infoMsg("Listing all the packages that have a new update available on ${target}")
68 pkgs = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.list_upgrades', [], null, true))
69 if(targetPackages != "" && targetPackages != "*"){
70 common.infoMsg("Note that only the ${targetPackages} would be installed from the above list of available updates on the ${target}")
71 }
72 }
73
74 if (INTERACTIVE.toBoolean()) {
75 stage("Confirm live package upgrades on ${target}") {
76 if (targetPackages=="") {
77 def userInput = input(
78 id: 'userInput', message: 'Insert package names for update', parameters: [
79 [$class: 'TextParameterDefinition', defaultValue: pkgs.keySet().join(",").toString(), description: 'Package names (or *)', name: 'packages']
80 ])
81 if (userInput!= "" && userInput!= "*") {
82 targetPackages = userInput
83 }
84 } else {
85 input message: "Approve live package upgrades on ${target} nodes?"
86 }
87 }
88 } else {
89 targetPackages = pkgs.keySet().join(",").toString()
90 }
91
92 if (targetPackages != "") {
93 // list installed versions of pkgs that will be upgraded
94 def installedPkgs = []
95 def newPkgs = []
96 def targetPkgList = targetPackages.tokenize(',')
97 for (pkg in targetPkgList) {
98 def version
99 try {
100 def pkgsDetails = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.info_installed', [pkg], null, true))
101 version = pkgsDetails.get(pkg).get('version')
102 } catch (Exception er) {
103 common.infoMsg("${pkg} not installed yet")
104 }
105 if (version?.trim()) {
106 installedPkgs.add(pkg + '=' + version)
107 } else {
108 newPkgs.add(pkg)
109 }
110 }
111 common.warningMsg("the following list of pkgs will be upgraded")
112 common.warningMsg(installedPkgs.join(" "))
113 common.warningMsg("the following list of pkgs will be newly installed")
114 common.warningMsg(newPkgs.join(" "))
115 // set variables
116 command = "pkg.install"
117 packages = targetPackages
118 commandKwargs = ['only_upgrade': 'true','force_yes': 'true']
119
120 }else {
121 command = "pkg.upgrade"
122 commandKwargs = ['dist_upgrade': 'true']
123 distUpgrade = true
124 packages = null
125 }
126
127 // todo exception to cfg or cicd
128 stage("stop services on ${target}") {
129 if ((STOP_SERVICES.toBoolean()) && (targetType != 'cicd')) {
130 if (targetType == 'contrail') {
131 stopContrailServices(pepperEnv, target)
132 } else {
133 def probe = salt.getFirstMinion(pepperEnv, "${target}")
134 stopServices(pepperEnv, probe, target)
135 }
136 }
137 }
138
139 stage('Apply package upgrades') {
140 // salt master pkg
141 if (targetType == 'I@salt:master') {
142 common.warningMsg('salt-master pkg upgrade, rerun the pipeline if disconnected')
143 salt.runSaltProcessStep(pepperEnv, target, 'pkg.install', ['salt-master'], null, true, 5)
144 salt.minionsReachable(pepperEnv, 'I@salt:master', '*')
145 }
146 // salt minion pkg
147 salt.runSaltProcessStep(pepperEnv, target, 'pkg.install', ['salt-minion'], null, true, 5)
148 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
149 common.infoMsg('Performing pkg upgrades ... ')
150 common.retry(3){
151 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, true, packages, commandKwargs)
152 salt.printSaltCommandResult(out)
153 }
154 def osRelease = salt.getGrain(pepperEnv, target, 'lsb_distrib_codename')
155 if (osRelease.toString().toLowerCase().contains('trusty')) {
156 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --force-yes -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
157 } else {
158 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q -f --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
159 }
160 if (out.toString().contains('errors:')) {
161 try {
162 if (packages?.trim()) {
163 packages = packages.replaceAll(',', ' ')
164 common.retry(3){
165 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install ' + packages])
166 }
167 } else {
168 if (distUpgrade) {
169 common.retry(3){
170 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' dist-upgrade'])
171 }
172 } else {
173 common.retry(3){
174 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' upgrade'])
175 }
176 } }
177 if (out.toString().contains('E: ')) {
178 common.errorMsg(out)
179 if (INTERACTIVE.toBoolean()) {
180 input message: "Pkgs update failed to be updated on ${target}. Please fix it manually."
181 } else {
182 salt.printSaltCommandResult(out)
183 throw new Exception("Pkgs update failed")
184 }
185 }
186 } catch (Exception e) {
187 common.errorMsg(out)
188 common.errorMsg(e)
189 if (INTERACTIVE.toBoolean()) {
190 input message: "Pkgs update failed to be updated on ${target}. Please fix it manually."
191 } else {
192 throw new Exception("Pkgs update failed")
193 }
194 }
195 }
196 }
197}
198
199def rollbackPkgs(pepperEnv, target, targetType = "", targetPackages="") {
200 def salt = new com.mirantis.mk.Salt()
201 def common = new com.mirantis.mk.Common()
202 def probe = salt.getFirstMinion(pepperEnv, "${target}")
203 def distUpgrade
204 def pkgs
205 def out
206
207 salt.enforceState(pepperEnv, target, 'linux.system.repo')
208
209 if (ROLLBACK_PKG_VERSIONS == "") {
210 stage("List package upgrades") {
211 common.infoMsg("Listing all the packages that have a new update available on ${target}")
212 pkgs = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.list_upgrades', [], null, true))
213 if(targetPackages != "" && targetPackages != "*"){
214 common.infoMsg("Note that only the ${targetPackages} would be installed from the above list of available updates on the ${target}")
215 }
216 }
217
218 if (INTERACTIVE.toBoolean()) {
219 stage("Confirm live package upgrades on ${target}") {
220 if(targetPackages==""){
221 timeout(time: 2, unit: 'HOURS') {
222 def userInput = input(
223 id: 'userInput', message: 'Insert package names for update', parameters: [
224 [$class: 'TextParameterDefinition', defaultValue: pkgs.keySet().join(",").toString(), description: 'Package names (or *)', name: 'packages']
225 ])
226 if(userInput!= "" && userInput!= "*"){
227 targetPackages = userInput
228 }
229 }
230 }else{
231 timeout(time: 2, unit: 'HOURS') {
232 input message: "Approve live package upgrades on ${target} nodes?"
233 }
234 }
235 }
236 } else {
237 targetPackages = pkgs.keySet().join(",").toString()
238 }
239 } else {
240 targetPackages = ROLLBACK_PKG_VERSIONS
241 }
242
243 if (targetPackages != "") {
244 // set variables
245 packages = targetPackages
246 } else {
247 distUpgrade = true
248 packages = null
249 }
250
251 stage("stop services on ${target}") {
252 try {
253 if (INTERACTIVE.toBoolean()) {
254 input message: "Click PROCEED to interactively stop services on ${target}. Otherwise click ABORT to skip stopping them and continue."
255 }
256 } catch (Exception er) {
257 common.infoMsg('skipping stopping services')
258 return
259 }
260 if (STOP_SERVICES.toBoolean()) {
261 stopServices(pepperEnv, probe, target)
262 }
263 }
264
265 stage('Apply package downgrades') {
266 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
267 common.infoMsg('Performing pkgs purge/remove ... ')
268 try {
269 if (PURGE_PKGS != "") {
270 def purgePackages = PURGE_PKGS.replaceAll(',', ' ')
271 common.retry(3){
272 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' purge ' + purgePackages])
273 }
274 }
275 if (REMOVE_PKGS != "") {
276 def removePackages = REMOVE_PKGS.replaceAll(',', ' ')
277 common.retry(3){
278 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' remove ' + removePackages])
279 }
280 }
281 if (out.toString().contains('E: ')) {
282 common.errorMsg(out)
283 if (INTERACTIVE.toBoolean()) {
284 input message: "Pkgs ${packages} purge failed on ${target}. Please fix it manually."
285 } else {
286 salt.printSaltCommandResult(out)
287 throw new Exception("Pkgs {packages} purge failed")
288 }
289 }
290 } catch (Exception e) {
291 common.errorMsg(out)
292 common.errorMsg(e)
293 if (INTERACTIVE.toBoolean()) {
294 input message: "Pkgs {packages} purge on ${target}. Please fix it manually."
295 } else {
296 throw new Exception("Pkgs {packages} purge failed")
297 }
298 }
299
300 common.infoMsg('Performing pkg downgrades ... ')
301 try {
302 packages = packages.replaceAll(',', ' ')
303 if (packages?.trim()) {
304 packages = packages.replaceAll(',', ' ')
305 common.retry(3){
306 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install salt-minion'], null, true, 5)
307 }
308 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
309 common.retry(3){
310 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install ' + packages])
311 }
312 } else {
313 if (distUpgrade) {
314 common.retry(3){
315 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' dist-upgrade'])
316 }
317 } else {
318 common.retry(3){
319 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' upgrade'])
320 }
321 }
322 }
323 if (out.toString().contains('E: ')) {
324 common.errorMsg(out)
325 if (INTERACTIVE.toBoolean()) {
326 input message: "Pkgs rollback failed on ${target}. Please fix it manually."
327 } else {
328 salt.printSaltCommandResult(out)
329 throw new Exception("Pkgs rollback failed")
330 }
331 }
332 } catch (Exception e) {
333 common.errorMsg(out)
334 common.errorMsg(e)
335 if (INTERACTIVE.toBoolean()) {
336 input message: "Pkgs rollback failed on ${target}. Please fix it manually."
337 } else {
338 throw new Exception("Pkgs rollback failed")
339 }
340 }
341 }
342}
343
344def getCfgNodeProvider(pepperEnv, master_name) {
345 def salt = new com.mirantis.mk.Salt()
346 def common = new com.mirantis.mk.Common()
347 if (!CFG_NODE_PROVIDER?.trim()) {
348 kvms = salt.getMinions(pepperEnv, 'I@salt:control')
349 for (kvm in kvms) {
350 try {
351 vms = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, kvm, 'virt.list_active_vms', [], null, true))
352 if (vms.toString().contains(master_name)) {
353 CFG_NODE_PROVIDER = kvm
354 //break
355 }
356 } catch (Exception er) {
357 common.infoMsg("${master_name} not present on ${kvm}")
358 }
359 }
360 }
361}
362
363/*
364def rollbackSaltMaster(pepperEnv, target, path='/var/lib/libvirt/images') {
365 def salt = new com.mirantis.mk.Salt()
366 def common = new com.mirantis.mk.Common()
367 try {
368 input message: "PART1 - Are you sure to rollback ${target}? To rollback click on PROCEED. To skip rollback PART1 click on ABORT."
369 } catch (Exception er) {
370 common.infoMsg("skipping rollback of ${target}")
371 return
372 }
373 def domain = salt.getDomainName(pepperEnv)
374 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
375 getCfgNodeProvider(pepperEnv, master)
376 try {
377 try {
378 salt.getReturnValues(salt.cmdRun(pepperEnv, CFG_NODE_PROVIDER, "ls -la ${path}/${master}.${domain}.xml"))
379 common.errorMsg('Pipeline is about to disconnect from salt-api. You will have to rerun the pipeline with ROLLBACK_CFG checked and skip PART1 to finish rollback.')
380 salt.cmdRun(pepperEnv, CFG_NODE_PROVIDER, "virsh destroy ${master}.${domain}; virsh define ${path}/${master}.${domain}.xml; virsh start ${master}.${domain} ")
381 } catch (Exception er) {
382 common.errorMsg(er)
383 input message: "Rollback for ${target} failed. Rollback manually."
384 }
385 } catch (Exception er) {
386 common.errorMsg(er)
387 input message: "Rollback for ${target} failed. Rollback manually."
388 }
389}
390
391def finishSaltMasterRollback(pepperEnv, target, path='/var/lib/libvirt/images') {
392 def salt = new com.mirantis.mk.Salt()
393 def common = new com.mirantis.mk.Common()
394 def virsh = new com.mirantis.mk.Virsh()
395 try {
396 input message: "PART2 - Are you sure to finalize ${target} rollback? Click on PROCEED. To skip rollback click on ABORT."
397 } catch (Exception er) {
398 common.infoMsg("skipping finalize rollback of ${target}")
399 return
400 }
401 salt.minionsReachable(pepperEnv, 'I@salt:master', '*')
402 def domain = salt.getDomainName(pepperEnv)
403 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
404 getCfgNodeProvider(pepperEnv, master)
405 try {
406 virsh.liveSnapshotAbsent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME, path)
407 // purge and setup previous repos
408 salt.enforceState(pepperEnv, target, 'linux.system.repo')
409 } catch (Exception e) {
410 common.errorMsg(e)
411 input message: "Check what failed after ${target} rollback. Do you want to PROCEED?"
412 }
413}*/
414
415def stopServices(pepperEnv, probe, target) {
416 def openstack = new com.mirantis.mk.Openstack()
417 def services = []
418 services.add('keepalived')
419 services.add('nginx')
420 services.add('haproxy')
421 services.add('nova-api')
422 services.add('cinder')
423 services.add('glance')
424 services.add('heat')
425 services.add('neutron')
426 services.add('apache2')
427 services.add('rabbitmq-server')
428 if (INTERACTIVE.toBoolean()) {
429 openstack.stopServices(pepperEnv, probe, target, services, true)
430 } else {
431 openstack.stopServices(pepperEnv, probe, target, services)
432 }
433}
434
435// must be stopped separately due to OC on Trusty
436def stopContrailServices(pepperEnv, target) {
437 def salt = new com.mirantis.mk.Salt()
438 def common = new com.mirantis.mk.Common()
439 def services = []
440 services.add('keepalived')
441 services.add('haproxy')
442 services.add('supervisor-control')
443 services.add('supervisor-config')
444 services.add('supervisor-database')
445 services.add('zookeeper')
446 services.add('ifmap-server')
447 for (s in services) {
448 try {
449 salt.runSaltProcessStep(pepperEnv, target, 'service.stop', [s], null, true)
450 } catch (Exception er) {
451 common.infoMsg(er)
452 }
453 }
454}
455
456def highstate(pepperEnv, target) {
457 def salt = new com.mirantis.mk.Salt()
458 def common = new com.mirantis.mk.Common()
459
460 stage("Apply highstate on ${target} nodes") {
461 try {
462 common.retry(3){
463 //salt.enforceHighstate(pepperEnv, target)
464 }
465 } catch (Exception e) {
466 common.errorMsg(e)
467 if (INTERACTIVE.toBoolean()) {
468 input message: "Highstate failed on ${target}. Fix it manually or run rollback on ${target}."
469 } else {
470 throw new Exception("highstate failed")
471 }
472 }
473 }
474 // optionally reboot
475 if (REBOOT.toBoolean()) {
476 stage("Reboot ${target} nodes") {
477 salt.runSaltProcessStep(pepperEnv, target, 'system.reboot', null, null, true, 5)
478 sleep(10)
479 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
480 }
481 }
482}
483
484def rollback(pepperEnv, tgt, generalTarget) {
485 def common = new com.mirantis.mk.Common()
486 try {
487 if (INTERACTIVE.toBoolean()) {
488 input message: "Are you sure to rollback ${generalTarget}? To rollback click on PROCEED. To skip rollback click on ABORT."
489 }
490 } catch (Exception er) {
491 common.infoMsg('skipping rollback')
492 return
493 }
494 try {
495 rollbackLiveSnapshot(pepperEnv, tgt, generalTarget)
496 } catch (Exception err) {
497 common.errorMsg(err)
498 if (INTERACTIVE.toBoolean()) {
499 input message: "Rollback for ${tgt} failed please fix it manually before clicking PROCEED."
500 } else {
501 throw new Exception("Rollback failed for ${tgt}")
502 }
503 }
504}
505
506def liveSnapshot(pepperEnv, tgt, generalTarget) {
507 def salt = new com.mirantis.mk.Salt()
508 def common = new com.mirantis.mk.Common()
509 def virsh = new com.mirantis.mk.Virsh()
510 def domain = salt.getDomainName(pepperEnv)
511 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
512 common.warningMsg(target_hosts)
513 //def nodeCount = 1
514 for (t in target_hosts) {
515 def target = salt.stripDomainName(t)
516 def nodeCount = target[4]
517 common.warningMsg(nodeCount)
518 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
519 virsh.liveSnapshotPresent(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
520 //nodeCount++
521 }
522}
523
524def mergeSnapshot(pepperEnv, tgt, generalTarget='') {
525 def salt = new com.mirantis.mk.Salt()
526 def virsh = new com.mirantis.mk.Virsh()
527 def domain = salt.getDomainName(pepperEnv)
528 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
529 def nodeCount = 1
530 for (t in target_hosts) {
531 if (tgt == 'I@salt:master') {
532 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
533 getCfgNodeProvider(pepperEnv, master)
534 virsh.liveSnapshotMerge(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME)
535 } else {
536 def target = salt.stripDomainName(t)
537 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
538 virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
539 }
540 nodeCount++
541 }
Jiri Broulik906e9972018-03-26 16:12:00 +0200542 salt.minionsReachable(pepperEnv, 'I@salt:master', tgt)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100543}
544
545
546
547def rollbackLiveSnapshot(pepperEnv, tgt, generalTarget) {
548 def salt = new com.mirantis.mk.Salt()
549 def virsh = new com.mirantis.mk.Virsh()
550 def common = new com.mirantis.mk.Common()
551 def domain = salt.getDomainName(pepperEnv)
552 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
553 // first destroy all vms
554 def nodeCount = 1
555 for (t in target_hosts) {
556 def target = salt.stripDomainName(t)
557 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
558 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
559 nodeCount++
560 }
561 nodeCount = 1
562 // rollback vms
563 for (t in target_hosts) {
564 def target = salt.stripDomainName(t)
565 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
566 virsh.liveSnapshotRollback(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
567 nodeCount++
568 }
569 try {
570 salt.minionsReachable(pepperEnv, 'I@salt:master', tgt)
571 // purge and setup previous repos
572 salt.enforceState(pepperEnv, tgt, 'linux.system.repo')
573 } catch (Exception e) {
574 common.errorMsg(e)
575 if (INTERACTIVE.toBoolean()) {
576 input message: "Salt state linux.system.repo on ${tgt} failed. Do you want to PROCEED?."
577 } else {
578 throw new Exception("Salt state linux.system.repo on ${tgt} failed")
579 }
580 }
581}
582
583def removeNode(pepperEnv, tgt, generalTarget) {
584 def salt = new com.mirantis.mk.Salt()
585 def virsh = new com.mirantis.mk.Virsh()
586 def common = new com.mirantis.mk.Common()
587 def domain = salt.getDomainName(pepperEnv)
588 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
589 // first destroy all vms
590 def nodeCount = 1
591 for (t in target_hosts) {
592 def target = salt.stripDomainName(t)
593 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
594 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
595 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.undefine', ["${target}.${domain}"], null, true)
596 try {
597 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
598 } catch (Exception e) {
599 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
600 }
601 nodeCount++
602 }
603}
604
Jiri Broulik906e9972018-03-26 16:12:00 +0200605def saltMasterBackup(pepperEnv) {
606 def salt = new com.mirantis.mk.Salt()
607 salt.enforceState(pepperEnv, 'I@salt:master', 'backupninja')
608 salt.cmdRun(pepperEnv, 'I@salt:master', "su root -c 'backupninja -n --run /etc/backup.d/200.backup.rsync'")
609}
610
Jiri Broulik60dcab32018-03-08 17:42:06 +0100611def backupCeph(pepperEnv, tgt) {
612 def salt = new com.mirantis.mk.Salt()
613 salt.enforceState(pepperEnv, 'I@ceph:backup:server', 'ceph.backup')
614 salt.enforceState(pepperEnv, "I@ceph:backup:client and ${tgt}", 'ceph.backup')
615 salt.cmdRun(pepperEnv, "I@ceph:backup:client and ${tgt}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh -s'")
616}
617
618def backupGalera(pepperEnv) {
619 def salt = new com.mirantis.mk.Salt()
620 salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup'])
621 salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client'])
622 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
623 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh -s -f'")
624}
625
626// cluster galera - wsrep_cluster_size
627def clusterGalera(pepperEnv) {
628 def salt = new com.mirantis.mk.Salt()
629 def common = new com.mirantis.mk.Common()
630 try {
631 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'])
632 } catch (Exception er) {
633 common.warningMsg('Mysql service already stopped')
634 }
635 try {
636 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'])
637 } catch (Exception er) {
638 common.warningMsg('Mysql service already stopped')
639 }
640 try {
641 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
642 } catch (Exception er) {
643 common.warningMsg('Files are not present')
644 }
645 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
646 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'])
647 // wait until mysql service on galera master is up
648 try {
649 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
650 } catch (Exception er) {
651 if (INTERACTIVE.toBoolean()) {
652 input message: "Database is not running please fix it first and only then click on PROCEED."
653 } else {
654 throw new Exception("Database is not running correctly")
655 }
656 }
657 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'])
658}
659
660def restoreGalera(pepperEnv) {
661 def salt = new com.mirantis.mk.Salt()
662 def common = new com.mirantis.mk.Common()
663 def openstack = new com.mirantis.mk.Openstack()
664 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "rm -rf /var/lib/mysql/*")
665 openstack.restoreGaleraDb(pepperEnv)
666}
667
668def backupZookeeper(pepperEnv) {
669 def salt = new com.mirantis.mk.Salt()
670 def common = new com.mirantis.mk.Common()
671 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
672 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
673 try {
674 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh -s'")
675 } catch (Exception er) {
676 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
677 }
678}
679
680def backupCassandra(pepperEnv) {
681 def salt = new com.mirantis.mk.Salt()
682 def common = new com.mirantis.mk.Common()
683
684 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
685 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
686 try {
687 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh -s'")
688 } catch (Exception er) {
689 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
690 }
691}
692
693def backupContrail(pepperEnv) {
694 backupZookeeper(pepperEnv)
695 backupCassandra(pepperEnv)
696}
697
698// cassandra and zookeeper
699def restoreContrailDb(pepperEnv) {
700 def salt = new com.mirantis.mk.Salt()
701 def common = new com.mirantis.mk.Common()
702 build job: "deploy-zookeeper-restore", parameters: [
703 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
704 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
705 ]
706 build job: "deploy-cassandra-db-restore", parameters: [
707 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
708 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
709 ]
710}
711
Jiri Broulikd2dd5632018-03-27 15:44:56 +0200712def verifyAPIs(pepperEnv, target) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100713 def salt = new com.mirantis.mk.Salt()
714 def common = new com.mirantis.mk.Common()
715 salt.cmdRun(pepperEnv, target, '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
716
717}
718
719def verifyGalera(pepperEnv) {
720 def salt = new com.mirantis.mk.Salt()
721 def common = new com.mirantis.mk.Common()
722 def out = salt.getReturnValues(salt.cmdRun(pepperEnv, 'I@galera:master', 'salt-call mysql.status | grep -A1 wsrep_cluster_size'))
723
724 if ((!out.toString().contains('wsrep_cluster_size')) || (out.toString().contains('0'))) {
725 if (INTERACTIVE.toBoolean()) {
726 input message: "Galera is not working as expected. Please check it and fix it first before clicking on PROCEED."
727 } else {
728 common.errorMsg(out)
729 throw new Exception("Galera is not working as expected")
730 }
731 }
732}
733
734def verifyContrail(pepperEnv, target) {
735 def salt = new com.mirantis.mk.Salt()
736 def common = new com.mirantis.mk.Common()
737 salt.commandStatus(pepperEnv, target, "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
738}
739
740
741def verifyService(pepperEnv, target, service) {
742 def salt = new com.mirantis.mk.Salt()
743 def common = new com.mirantis.mk.Common()
744 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
745 for (t in targetHosts) {
746 try {
747 salt.commandStatus(pepperEnv, t, "service ${service} status", 'running')
748 } catch (Exception er) {
749 common.errorMsg(er)
750 if (INTERACTIVE.toBoolean()) {
751 input message: "${service} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
752 } else {
753 throw new Exception("${service} service is not running correctly on ${t}")
754 }
755 }
756 }
757}
758
759def verifyCeph(pepperEnv, target, type) {
760 def salt = new com.mirantis.mk.Salt()
761 def common = new com.mirantis.mk.Common()
762 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
763 for (t in targetHosts) {
764 def hostname = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname'))
765 try {
766 salt.commandStatus(pepperEnv, t, "systemctl status ceph-${type}${hostname}", 'running')
767 } catch (Exception er) {
768 common.errorMsg(er)
769 if (INTERACTIVE.toBoolean()) {
770 input message: "Ceph-${type}${hostname} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
771 } else {
772 throw new Exception("Ceph-${type}${hostname} service is not running correctly on ${t}")
773 }
774 }
775 }
776}
777
778def verifyCephOsds(pepperEnv, target) {
779 def salt = new com.mirantis.mk.Salt()
780 def common = new com.mirantis.mk.Common()
781 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
782 for (t in targetHosts) {
783 def osd_ids = []
784 // get list of osd disks of the host
785 salt.runSaltProcessStep(pepperEnv, t, 'saltutil.sync_grains', [], null, true, 5)
786 def cephGrain = salt.getGrain(pepperEnv, t, 'ceph')
787 if(cephGrain['return'].isEmpty()){
788 throw new Exception("Ceph salt grain cannot be found!")
789 }
790 common.print(cephGrain)
791 def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk']
792 for (i in ceph_disks) {
793 def osd_id = i.getKey().toString()
794 osd_ids.add('osd.' + osd_id)
795 print("Will check osd." + osd_id)
796 }
797 for (i in osd_ids) {
798 try {
799 salt.commandStatus(pepperEnv, t, "ceph osd tree | grep -w ${i}", 'up')
800 } catch (Exception er) {
801 common.errorMsg(er)
802 if (INTERACTIVE.toBoolean()) {
803 input message: "Ceph ${i} is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
804 } else {
805 throw new Exception("Ceph ${i} is not running correctly on ${t}")
806 }
807 }
808 }
809 }
810}
811
812
813timeout(time: 12, unit: 'HOURS') {
814 node() {
815 try {
816
817 stage('Setup virtualenv for Pepper') {
818 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
819 }
820
821 // TODO, add possibility to update just specific components like kernel, openstack, contrail, ovs, rabbitmq, galera, etc.
822
823 /*
824 * Update section
825 */
826 if (updates.contains("cfg")) {
827 def target = 'I@salt:master'
828 if (salt.testTarget(pepperEnv, target)) {
829 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
830 getCfgNodeProvider(pepperEnv, master)
831 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
832 virsh.liveSnapshotPresent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME)
Jiri Broulik906e9972018-03-26 16:12:00 +0200833 } else {
834 saltMasterBackup(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100835 }
836 if (PER_NODE.toBoolean()) {
837 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
838 for (t in targetHosts) {
839 updatePkgs(pepperEnv, t, target)
840 highstate(pepperEnv, t)
841 }
842 } else {
843 updatePkgs(pepperEnv, target)
844 highstate(pepperEnv, target)
845 }
846 }
847 }
848
849 if (updates.contains("ctl")) {
850 def target = CTL_TARGET
851 if (salt.testTarget(pepperEnv, target)) {
852 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
853 def generalTarget = 'ctl'
854 liveSnapshot(pepperEnv, target, generalTarget)
855 }
856 if (PER_NODE.toBoolean()) {
857 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
858 for (t in targetHosts) {
859 updatePkgs(pepperEnv, t)
860 highstate(pepperEnv, t)
861 }
862 } else {
863 updatePkgs(pepperEnv, target)
864 highstate(pepperEnv, target)
865 }
866 verifyAPIs(pepperEnv, target)
867 }
868 }
869
870 if (updates.contains("prx")) {
871 def target = PRX_TARGET
872 if (salt.testTarget(pepperEnv, target)) {
873 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
874 def generalTarget = 'prx'
875 liveSnapshot(pepperEnv, target, generalTarget)
876 }
877 if (PER_NODE.toBoolean()) {
878 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
879 for (t in targetHosts) {
880 updatePkgs(pepperEnv, t)
881 highstate(pepperEnv, t)
882 }
883 } else {
884 updatePkgs(pepperEnv, target)
885 highstate(pepperEnv, target)
886 }
887 verifyService(pepperEnv, target, 'nginx')
888 }
889 }
890
891 if (updates.contains("msg")) {
892 def target = MSG_TARGET
893 if (salt.testTarget(pepperEnv, target)) {
894 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
895 def generalTarget = 'msg'
896 liveSnapshot(pepperEnv, target, generalTarget)
897 }
898 if (PER_NODE.toBoolean()) {
899 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
900 for (t in targetHosts) {
901 updatePkgs(pepperEnv, t)
902 highstate(pepperEnv, t)
903 }
904 } else {
905 updatePkgs(pepperEnv, target, target)
906 highstate(pepperEnv, target)
907 }
908 verifyService(pepperEnv, target, 'rabbitmq-server')
909 }
910 }
911
912 if (updates.contains("dbs")) {
913 def target = DBS_TARGET
914 if (salt.testTarget(pepperEnv, target)) {
915 backupGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100916 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
917 def generalTarget = 'dbs'
918 liveSnapshot(pepperEnv, target, generalTarget)
919 }
Jiri Broulikd2dd5632018-03-27 15:44:56 +0200920 if (REBOOT.toBoolean() || PER_NODE.toBoolean()) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100921 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
922 // one by one update
923 for (t in targetHosts) {
924 updatePkgs(pepperEnv, t)
925 highstate(pepperEnv, t)
926 }
927 } else {
928 updatePkgs(pepperEnv, target)
929 highstate(pepperEnv, target)
930 }
931 verifyGalera(pepperEnv)
932 }
933 }
934
935 if (updates.contains("ntw")) {
936 def target = NTW_TARGET
937 if (salt.testTarget(pepperEnv, target)) {
938 backupContrail(pepperEnv)
939 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
940 def generalTarget = 'ntw'
941 liveSnapshot(pepperEnv, target, generalTarget)
942 }
943 if (PER_NODE.toBoolean()) {
944 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
945 for (t in targetHosts) {
946 updatePkgs(pepperEnv, t, 'contrail')
947 highstate(pepperEnv, t)
948 verifyContrail(pepperEnv, t)
949 }
950 } else {
951 updatePkgs(pepperEnv, target, 'contrail')
952 highstate(pepperEnv, target)
953 verifyContrail(pepperEnv, target)
954 }
955 }
956 }
957
958 if (updates.contains("nal")) {
959 def target = NAL_TARGET
960 if (salt.testTarget(pepperEnv, target)) {
961 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
962 def generalTarget = 'nal'
963 liveSnapshot(pepperEnv, target, generalTarget)
964 }
965 if (PER_NODE.toBoolean()) {
966 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
967 for (t in targetHosts) {
968 updatePkgs(pepperEnv, t, 'contrail')
969 highstate(pepperEnv, t)
970 }
971 } else {
972 updatePkgs(pepperEnv, target, 'contrail')
973 highstate(pepperEnv, target)
974 }
975 verifyContrail(pepperEnv, target)
976 }
977 }
978
979 if (updates.contains("gtw-virtual")) {
980 def target = GTW_TARGET
981 if (salt.testTarget(pepperEnv, target)) {
982 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
983 def generalTarget = 'gtw'
984 liveSnapshot(pepperEnv, target, generalTarget)
985 }
986 if (PER_NODE.toBoolean()) {
987 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
988 for (t in targetHosts) {
989 updatePkgs(pepperEnv, t)
990 highstate(pepperEnv, t)
991 }
992 } else {
993 updatePkgs(pepperEnv, target)
994 highstate(pepperEnv, target)
995 }
996 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
997 }
998 }
999
1000 if (updates.contains("cmn")) {
1001 def target = CMN_TARGET
1002 if (salt.testTarget(pepperEnv, target)) {
1003 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1004 def generalTarget = 'cmn'
1005 liveSnapshot(pepperEnv, target, generalTarget)
1006 } else {
Jiri Broulik906e9972018-03-26 16:12:00 +02001007 backupCeph(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001008 }
1009 if (PER_NODE.toBoolean()) {
1010 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1011 for (t in targetHosts) {
1012 updatePkgs(pepperEnv, t)
1013 highstate(pepperEnv, t)
1014 }
1015 } else {
1016 updatePkgs(pepperEnv, target)
1017 highstate(pepperEnv, target)
1018 }
1019 verifyCeph(pepperEnv, target, 'mon@')
1020 }
1021 }
1022
1023 if (updates.contains("rgw")) {
1024 def target = RGW_TARGET
1025 if (salt.testTarget(pepperEnv, target)) {
1026 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1027 def generalTarget = 'rgw'
1028 liveSnapshot(pepperEnv, target, generalTarget)
1029 }
1030 if (PER_NODE.toBoolean()) {
1031 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1032 for (t in targetHosts) {
1033 updatePkgs(pepperEnv, t)
1034 highstate(pepperEnv, t)
1035 }
1036 } else {
1037 updatePkgs(pepperEnv, target)
1038 highstate(pepperEnv, target)
1039 }
1040 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1041 }
1042 }
1043
1044 if (updates.contains("log")) {
1045 def target = LOG_TARGET
1046 if (salt.testTarget(pepperEnv, target)) {
1047 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1048 def generalTarget = 'log'
1049 liveSnapshot(pepperEnv, target, generalTarget)
1050 }
1051 if (PER_NODE.toBoolean()) {
1052 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1053 for (t in targetHosts) {
1054 updatePkgs(pepperEnv, t)
1055 highstate(pepperEnv, t)
1056 }
1057 } else {
1058 updatePkgs(pepperEnv, target)
1059 highstate(pepperEnv, target)
1060 }
1061 }
1062 }
1063
1064 if (updates.contains("mon")) {
1065 def target = MON_TARGET
1066 if (salt.testTarget(pepperEnv, target)) {
1067 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1068 def generalTarget = 'mon'
1069 liveSnapshot(pepperEnv, target, generalTarget)
1070 }
1071 if (PER_NODE.toBoolean()) {
1072 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1073 for (t in targetHosts) {
1074 updatePkgs(pepperEnv, t)
1075 highstate(pepperEnv, t)
1076 }
1077 } else {
1078 updatePkgs(pepperEnv, target)
1079 highstate(pepperEnv, target)
1080 }
1081 }
1082 }
1083
1084 if (updates.contains("mtr")) {
1085 def target = MTR_TARGET
1086 if (salt.testTarget(pepperEnv, target)) {
1087 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1088 def generalTarget = 'mtr'
1089 liveSnapshot(pepperEnv, target, generalTarget)
1090 }
1091 if (PER_NODE.toBoolean()) {
1092 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1093 for (t in targetHosts) {
1094 updatePkgs(pepperEnv, t)
1095 highstate(pepperEnv, t)
1096 }
1097 } else {
1098 updatePkgs(pepperEnv, target)
1099 highstate(pepperEnv, target)
1100 }
1101 }
1102 }
1103
1104 if (updates.contains("cid")) {
1105 def target = CID_TARGET
1106 if (salt.testTarget(pepperEnv, target)) {
1107 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1108 def generalTarget = 'cid'
1109 liveSnapshot(pepperEnv, target, generalTarget)
1110 }
1111 updatePkgs(pepperEnv, target, 'cicd')
1112 highstate(pepperEnv, target)
1113 verifyService(pepperEnv, target, 'docker')
1114 }
1115 }
1116
1117 //
1118 //physical machines update CMP_TARGET
1119 //
1120 if (updates.contains("cmp")) {
1121 def target = CMP_TARGET
1122 if (salt.testTarget(pepperEnv, target)) {
1123 if (PER_NODE.toBoolean()) {
1124 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1125 for (t in targetHosts) {
1126 updatePkgs(pepperEnv, t)
1127 highstate(pepperEnv, t)
1128 }
1129 } else {
1130 updatePkgs(pepperEnv, target)
1131 highstate(pepperEnv, target)
1132 }
1133 verifyService(pepperEnv, target, 'nova-compute')
1134 }
1135 }
1136
1137 if (updates.contains("kvm")) {
1138 def target = KVM_TARGET
1139 if (salt.testTarget(pepperEnv, target)) {
1140 if (PER_NODE.toBoolean()) {
1141 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1142 for (t in targetHosts) {
1143 updatePkgs(pepperEnv, t)
1144 highstate(pepperEnv, t)
1145 }
1146 } else {
1147 updatePkgs(pepperEnv, target, target)
1148 highstate(pepperEnv, target)
1149 }
1150 verifyService(pepperEnv, target, 'libvirt-bin')
1151 }
1152 }
1153
1154 if (updates.contains("osd")) {
1155 def target = CEPH_OSD_TARGET
1156 if (salt.testTarget(pepperEnv, target)) {
1157 if (PER_NODE.toBoolean()) {
1158 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1159 for (t in targetHosts) {
1160 updatePkgs(pepperEnv, t)
1161 highstate(pepperEnv, t)
1162 }
1163 } else {
1164 updatePkgs(pepperEnv, target)
1165 highstate(pepperEnv, target)
1166 }
1167 verifyCephOsds(pepperEnv, target)
1168 }
1169 }
1170
1171 if (updates.contains("gtw-physical")) {
1172 def target = GTW_TARGET
1173 if (salt.testTarget(pepperEnv, target)) {
1174 if (PER_NODE.toBoolean()) {
1175 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1176 for (t in targetHosts) {
1177 updatePkgs(pepperEnv, t)
1178 highstate(pepperEnv, t)
1179 }
1180 } else {
1181 updatePkgs(pepperEnv, target)
1182 highstate(pepperEnv, target)
1183 }
1184 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1185 }
1186 }
1187
1188 /*
1189 * Rollback section
1190 */
Jiri Broulik906e9972018-03-26 16:12:00 +02001191 /* if (rollbacks.contains("cfg")) {
Jiri Broulik60dcab32018-03-08 17:42:06 +01001192 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1193 stage('ROLLBACK_CFG') {
1194 input message: "To rollback CFG nodes run the following commands on kvm nodes hosting the CFG nodes: virsh destroy cfg0X.domain; virsh define /var/lib/libvirt/images/cfg0X.domain.xml; virsh start cfg0X.domain; virsh snapshot-delete cfg0X.domain --metadata ${SNAPSHOT_NAME}; rm /var/lib/libvirt/images/cfg0X.domain.${SNAPSHOT_NAME}.qcow2; rm /var/lib/libvirt/images/cfg0X.domain.xml; At the end restart 'docker' service on all cicd nodes and run 'linux.system.repo' Salt states on cicd nodes. After running the previous commands current pipeline job will be killed."
1195 //rollbackSaltMaster(pepperEnv, 'I@salt:master')
1196 //finishSaltMasterRollback(pepperEnv, 'I@salt:master')
1197 }
1198 }
1199 } */
1200
1201 if (rollbacks.contains("ctl")) {
1202 def target = CTL_TARGET
1203 if (salt.testTarget(pepperEnv, target)) {
1204 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1205 rollback(pepperEnv, target, 'ctl')
1206 verifyAPIs(pepperEnv, target)
1207 } else {
1208 removeNode(pepperEnv, target, 'ctl')
1209 }
1210 }
1211 }
1212
1213 if (rollbacks.contains("prx")) {
1214 def target = PRX_TARGET
1215 if (salt.testTarget(pepperEnv, target)) {
1216 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1217 rollback(pepperEnv, target, 'prx')
1218 verifyService(pepperEnv, target, 'nginx')
1219 } else {
1220 removeNode(pepperEnv, target, 'prx')
1221 }
1222 }
1223 }
1224
1225 if (rollbacks.contains("msg")) {
1226 def target = MSG_TARGET
1227 if (salt.testTarget(pepperEnv, target)) {
1228 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1229 rollback(pepperEnv, target, 'msg')
1230 salt.enforceState(pepperEnv, target, 'rabbitmq')
1231 verifyService(pepperEnv, target, 'rabbitmq-server')
1232 } else {
1233 removeNode(pepperEnv, target, 'msg')
1234 }
1235 }
1236 }
1237
1238 if (rollbacks.contains("dbs")) {
1239 def target = DBS_TARGET
1240 if (salt.testTarget(pepperEnv, target)) {
1241 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1242 rollback(pepperEnv, target, 'dbs')
1243 clusterGalera(pepperEnv)
1244 verifyGalera(pepperEnv)
1245 } else {
1246 removeNode(pepperEnv, target, 'dbs')
1247 }
1248 }
1249 }
1250
1251 if (rollbacks.contains("ntw")) {
1252 def target = NTW_TARGET
1253 if (salt.testTarget(pepperEnv, target)) {
1254 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1255 rollback(pepperEnv, target, 'ntw')
1256 verifyContrail(pepperEnv, target)
1257 } else {
1258 removeNode(pepperEnv, target, 'ntw')
1259 }
1260 }
1261 }
1262
1263 if (rollbacks.contains("nal")) {
1264 def target = NAL_TARGET
1265 if (salt.testTarget(pepperEnv, target)) {
1266 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1267 rollback(pepperEnv, target, 'nal')
1268 verifyContrail(pepperEnv, target)
1269 } else {
1270 removeNode(pepperEnv, target, 'nal')
1271 }
1272 }
1273 }
1274
1275 if (rollbacks.contains("gtw-virtual")) {
1276 def target = GTW_TARGET
1277 if (salt.testTarget(pepperEnv, target)) {
1278 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1279 rollback(pepperEnv, target, 'gtw')
1280 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1281 } else {
1282 removeNode(pepperEnv, target, 'gtw')
1283 }
1284 }
1285 }
1286
1287 if (rollbacks.contains("cmn")) {
1288 def target = CMN_TARGET
1289 if (salt.testTarget(pepperEnv, target)) {
1290 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1291 rollback(pepperEnv, target, 'cmn')
1292 verifyCeph(pepperEnv, target, 'mon@')
1293 } else {
1294 removeNode(pepperEnv, target, 'cmn')
1295 }
1296 }
1297 }
1298
1299 if (rollbacks.contains("rgw")) {
1300 def target = RGW_TARGET
1301 if (salt.testTarget(pepperEnv, target)) {
1302 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1303 rollback(pepperEnv, target, 'rgw')
1304 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1305 } else {
1306 removeNode(pepperEnv, target, 'rgw')
1307 }
1308 }
1309 }
1310
1311 if (rollbacks.contains("log")) {
1312 def target = LOG_TARGET
1313 if (salt.testTarget(pepperEnv, target)) {
1314 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1315 rollback(pepperEnv, target, 'log')
1316 } else {
1317 removeNode(pepperEnv, target, 'log')
1318 }
1319 }
1320 }
1321
1322 if (rollbacks.contains("mon")) {
1323 def target = MON_TARGET
1324 if (salt.testTarget(pepperEnv, target)) {
1325 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1326 rollback(pepperEnv, target, 'mon')
1327 } else {
1328 removeNode(pepperEnv, target, 'mon')
1329 }
1330 }
1331 }
1332
1333 if (rollbacks.contains("mtr")) {
1334 def target = MTR_TARGET
1335 if (salt.testTarget(pepperEnv, target)) {
1336 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1337 rollback(pepperEnv, target, 'mtr')
1338 } else {
1339 removeNode(pepperEnv, target, 'mtr')
1340 }
1341 }
1342 }
1343 /*
1344 if (ROLLBACK_CID.toBoolean()) {
1345 def target = 'cid*'
1346 if (salt.testTarget(pepperEnv, target)) {
1347 stage('ROLLBACK_CID') {
1348 input message: "To rollback CICD nodes run the following commands on kvm nodes hosting the cicd nodes: virsh destroy cid0X.domain; virsh define /var/lib/libvirt/images/cid0X.domain.xml; virsh start cid0X.domain; virsh snapshot-delete cid0X.domain --metadata ${SNAPSHOT_NAME}; rm /var/lib/libvirt/images/cid0X.domain.${SNAPSHOT_NAME}.qcow2; rm /var/lib/libvirt/images/cid0X.domain.xml; At the end restart 'docker' service on all cicd nodes and run 'linux.system.repo' Salt states on cicd nodes. After running the previous commands current pipeline job will be killed."
1349 }
1350 }
1351 } */
1352
1353 //
1354 //physical machines rollback CMP_TARGET
1355 //
1356 if (rollbacks.contains("cmp")) {
1357 def target = CMP_TARGET
1358 if (salt.testTarget(pepperEnv, target)) {
1359 if (PER_NODE.toBoolean()) {
1360 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1361 for (t in targetHosts) {
1362 rollbackPkgs(pepperEnv, t)
1363 highstate(pepperEnv, t)
1364 }
1365 } else {
1366 rollbackPkgs(pepperEnv, target, target)
1367 highstate(pepperEnv, target)
1368 }
1369 verifyService(pepperEnv, target, 'nova-compute')
1370 }
1371 }
1372
1373 if (rollbacks.contains("kvm")) {
1374 def target = KVM_TARGET
1375 if (salt.testTarget(pepperEnv, target)) {
1376 if (PER_NODE.toBoolean()) {
1377 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1378 for (t in targetHosts) {
1379 rollbackPkgs(pepperEnv, t)
1380 highstate(pepperEnv, t)
1381 }
1382 } else {
1383 rollbackPkgs(pepperEnv, target, target)
1384 highstate(pepperEnv, target)
1385 }
1386 verifyService(pepperEnv, target, 'libvirt-bin')
1387 }
1388 }
1389
1390 if (rollbacks.contains("osd")) {
1391 def target = CEPH_OSD_TARGET
1392 if (salt.testTarget(pepperEnv, target)) {
1393 if (PER_NODE.toBoolean()) {
1394 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1395 for (t in targetHosts) {
1396 rollbackPkgs(pepperEnv, t)
1397 highstate(pepperEnv, t)
1398 }
1399 } else {
1400 rollbackPkgs(pepperEnv, target, target)
1401 highstate(pepperEnv, target)
1402 }
1403 verifyCephOsds(pepperEnv, target)
1404 }
1405 }
1406
1407 if (rollbacks.contains("gtw-physical")) {
1408 def target = GTW_TARGET
1409 if (salt.testTarget(pepperEnv, target)) {
1410 if (PER_NODE.toBoolean()) {
1411 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1412 for (t in targetHosts) {
1413 rollbackPkgs(pepperEnv, t)
1414 highstate(pepperEnv, t)
1415 }
1416 } else {
1417 rollbackPkgs(pepperEnv, target, target)
1418 highstate(pepperEnv, target)
1419 }
1420 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1421 }
1422 }
1423
1424 /*
1425 * Merge snapshots section
1426 */
1427 if (merges.contains("cfg")) {
1428 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1429 mergeSnapshot(pepperEnv, 'I@salt:master')
1430 }
1431 }
1432
1433 if (merges.contains("ctl")) {
1434 if (salt.testTarget(pepperEnv, CTL_TARGET)) {
1435 mergeSnapshot(pepperEnv, CTL_TARGET, 'ctl')
Jiri Broulik906e9972018-03-26 16:12:00 +02001436 verifyService(pepperEnv, CTL_TARGET, 'nova-api')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001437 }
1438 }
1439
1440 if (merges.contains("prx")) {
1441 if (salt.testTarget(pepperEnv, PRX_TARGET)) {
1442 mergeSnapshot(pepperEnv, PRX_TARGET, 'prx')
Jiri Broulik906e9972018-03-26 16:12:00 +02001443 verifyService(pepperEnv, PRX_TARGET, 'nginx')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001444 }
1445 }
1446
1447 if (merges.contains("msg")) {
1448 if (salt.testTarget(pepperEnv, MSG_TARGET)) {
1449 mergeSnapshot(pepperEnv, MSG_TARGET, 'msg')
Jiri Broulik906e9972018-03-26 16:12:00 +02001450 verifyService(pepperEnv, MSG_TARGET, 'rabbitmq-server')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001451 }
1452 }
1453
1454 if (merges.contains("dbs")) {
1455 if (salt.testTarget(pepperEnv, DBS_TARGET)) {
1456 mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs')
Jiri Broulik906e9972018-03-26 16:12:00 +02001457 verifyGalera(pepperEnv)
1458 backupGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001459 }
1460 }
1461
1462 if (merges.contains("ntw")) {
1463 if (salt.testTarget(pepperEnv, NTW_TARGET)) {
1464 mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001465 verifyContrail(pepperEnv, NTW_TARGET)
1466 backupContrail(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001467 }
1468 }
1469
1470 if (merges.contains("nal")) {
1471 if (salt.testTarget(pepperEnv, NAL_TARGET)) {
1472 mergeSnapshot(pepperEnv, NAL_TARGET, 'nal')
Jiri Broulik906e9972018-03-26 16:12:00 +02001473 verifyContrail(pepperEnv, NAL_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001474 }
1475 }
1476
1477 if (merges.contains("gtw-virtual")) {
1478 if (salt.testTarget(pepperEnv, GTW_TARGET)) {
1479 mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001480 verifyService(pepperEnv, GTW_TARGET, 'neutron-dhcp-agent')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001481 }
1482 }
1483
1484 if (merges.contains("cmn")) {
1485 if (salt.testTarget(pepperEnv, CMN_TARGET)) {
1486 mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn')
Jiri Broulik906e9972018-03-26 16:12:00 +02001487 verifyCeph(pepperEnv, CMN_TARGET, 'mon@')
1488 backupCeph(pepperEnv, CMN_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001489 }
1490 }
1491
1492 if (merges.contains("rgw")) {
1493 if (salt.testTarget(pepperEnv, RGW_TARGET)) {
1494 mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001495 verifyCeph(pepperEnv, RGW_TARGET, 'radosgw@rgw.')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001496 }
1497 }
1498
1499 if (merges.contains("log")) {
1500 if (salt.testTarget(pepperEnv, LOG_TARGET)) {
1501 mergeSnapshot(pepperEnv, LOG_TARGET. 'log')
1502 }
1503 }
1504
1505 if (merges.contains("mon")) {
1506 if (salt.testTarget(pepperEnv, MON_TARGET)) {
1507 mergeSnapshot(pepperEnv, MON_TARGET, 'mon')
1508 }
1509 }
1510
1511 if (merges.contains("mtr")) {
1512 if (salt.testTarget(pepperEnv, MTR_TARGET)) {
1513 mergeSnapshot(pepperEnv, MTR_TARGET, 'mtr')
1514 }
1515 }
1516
1517 if (merges.contains("cid")) {
1518 if (salt.testTarget(pepperEnv, CID_TARGET)) {
1519 mergeSnapshot(pepperEnv, CID_TARGET, 'cid')
Jiri Broulik906e9972018-03-26 16:12:00 +02001520 verifyService(pepperEnv, CID_TARGET, 'docker')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001521 }
1522 }
1523
1524 if (RESTORE_GALERA.toBoolean()) {
1525 restoreGalera(pepperEnv)
Jiri Broulik906e9972018-03-26 16:12:00 +02001526 verifyGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001527 }
1528
1529 if (RESTORE_CONTRAIL_DB.toBoolean()) {
1530 restoreContrailDb(pepperEnv)
Jiri Broulik906e9972018-03-26 16:12:00 +02001531 // verification is already present in restore pipelines
Jiri Broulik60dcab32018-03-08 17:42:06 +01001532 }
1533
1534 } catch (Throwable e) {
1535 // If there was an error or exception thrown, the build failed
1536 currentBuild.result = "FAILURE"
1537 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
1538 throw e
1539 }
1540 }
1541}