blob: a8b2c71232436daab55754fdf2124a97e1d89b5d [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)
14 * TARGET_ROLLBACKS Comma separated list of nodes to update (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 update (Valid values are cfg,ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cid)
16 * 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*)
31 * GTW_TARGET Salt targeted physical GTW nodes (ex. gtw01*)
32 * REBOOT Reboot nodes after update (bool)
33 * ROLLBACK_PKG_VERSIONS Space separated list of pkgs=versions to rollback to (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
34 * PURGE_PKGS Space separated list of pkgs=versions to be purged (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
35 * REMOVE_PKGS Space separated list of pkgs=versions to be removed (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
36 * 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 }
542}
543
544
545
546def rollbackLiveSnapshot(pepperEnv, tgt, generalTarget) {
547 def salt = new com.mirantis.mk.Salt()
548 def virsh = new com.mirantis.mk.Virsh()
549 def common = new com.mirantis.mk.Common()
550 def domain = salt.getDomainName(pepperEnv)
551 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
552 // first destroy all vms
553 def nodeCount = 1
554 for (t in target_hosts) {
555 def target = salt.stripDomainName(t)
556 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
557 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
558 nodeCount++
559 }
560 nodeCount = 1
561 // rollback vms
562 for (t in target_hosts) {
563 def target = salt.stripDomainName(t)
564 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
565 virsh.liveSnapshotRollback(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
566 nodeCount++
567 }
568 try {
569 salt.minionsReachable(pepperEnv, 'I@salt:master', tgt)
570 // purge and setup previous repos
571 salt.enforceState(pepperEnv, tgt, 'linux.system.repo')
572 } catch (Exception e) {
573 common.errorMsg(e)
574 if (INTERACTIVE.toBoolean()) {
575 input message: "Salt state linux.system.repo on ${tgt} failed. Do you want to PROCEED?."
576 } else {
577 throw new Exception("Salt state linux.system.repo on ${tgt} failed")
578 }
579 }
580}
581
582def removeNode(pepperEnv, tgt, generalTarget) {
583 def salt = new com.mirantis.mk.Salt()
584 def virsh = new com.mirantis.mk.Virsh()
585 def common = new com.mirantis.mk.Common()
586 def domain = salt.getDomainName(pepperEnv)
587 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
588 // first destroy all vms
589 def nodeCount = 1
590 for (t in target_hosts) {
591 def target = salt.stripDomainName(t)
592 def nodeProvider = salt.getNodeProvider(pepperEnv, "${generalTarget}0${nodeCount}")
593 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
594 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.undefine', ["${target}.${domain}"], null, true)
595 try {
596 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
597 } catch (Exception e) {
598 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
599 }
600 nodeCount++
601 }
602}
603
604def backupCeph(pepperEnv, tgt) {
605 def salt = new com.mirantis.mk.Salt()
606 salt.enforceState(pepperEnv, 'I@ceph:backup:server', 'ceph.backup')
607 salt.enforceState(pepperEnv, "I@ceph:backup:client and ${tgt}", 'ceph.backup')
608 salt.cmdRun(pepperEnv, "I@ceph:backup:client and ${tgt}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh -s'")
609}
610
611def backupGalera(pepperEnv) {
612 def salt = new com.mirantis.mk.Salt()
613 salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup'])
614 salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client'])
615 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
616 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh -s -f'")
617}
618
619// cluster galera - wsrep_cluster_size
620def clusterGalera(pepperEnv) {
621 def salt = new com.mirantis.mk.Salt()
622 def common = new com.mirantis.mk.Common()
623 try {
624 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'])
625 } catch (Exception er) {
626 common.warningMsg('Mysql service already stopped')
627 }
628 try {
629 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'])
630 } catch (Exception er) {
631 common.warningMsg('Mysql service already stopped')
632 }
633 try {
634 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
635 } catch (Exception er) {
636 common.warningMsg('Files are not present')
637 }
638 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
639 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'])
640 // wait until mysql service on galera master is up
641 try {
642 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
643 } catch (Exception er) {
644 if (INTERACTIVE.toBoolean()) {
645 input message: "Database is not running please fix it first and only then click on PROCEED."
646 } else {
647 throw new Exception("Database is not running correctly")
648 }
649 }
650 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'])
651}
652
653def restoreGalera(pepperEnv) {
654 def salt = new com.mirantis.mk.Salt()
655 def common = new com.mirantis.mk.Common()
656 def openstack = new com.mirantis.mk.Openstack()
657 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "rm -rf /var/lib/mysql/*")
658 openstack.restoreGaleraDb(pepperEnv)
659}
660
661def backupZookeeper(pepperEnv) {
662 def salt = new com.mirantis.mk.Salt()
663 def common = new com.mirantis.mk.Common()
664 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
665 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
666 try {
667 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh -s'")
668 } catch (Exception er) {
669 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
670 }
671}
672
673def backupCassandra(pepperEnv) {
674 def salt = new com.mirantis.mk.Salt()
675 def common = new com.mirantis.mk.Common()
676
677 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
678 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
679 try {
680 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh -s'")
681 } catch (Exception er) {
682 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
683 }
684}
685
686def backupContrail(pepperEnv) {
687 backupZookeeper(pepperEnv)
688 backupCassandra(pepperEnv)
689}
690
691// cassandra and zookeeper
692def restoreContrailDb(pepperEnv) {
693 def salt = new com.mirantis.mk.Salt()
694 def common = new com.mirantis.mk.Common()
695 build job: "deploy-zookeeper-restore", parameters: [
696 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
697 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
698 ]
699 build job: "deploy-cassandra-db-restore", parameters: [
700 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
701 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
702 ]
703}
704
705def verifyAPIs(pepperEnv) {
706 def salt = new com.mirantis.mk.Salt()
707 def common = new com.mirantis.mk.Common()
708 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')
709
710}
711
712def verifyGalera(pepperEnv) {
713 def salt = new com.mirantis.mk.Salt()
714 def common = new com.mirantis.mk.Common()
715 def out = salt.getReturnValues(salt.cmdRun(pepperEnv, 'I@galera:master', 'salt-call mysql.status | grep -A1 wsrep_cluster_size'))
716
717 if ((!out.toString().contains('wsrep_cluster_size')) || (out.toString().contains('0'))) {
718 if (INTERACTIVE.toBoolean()) {
719 input message: "Galera is not working as expected. Please check it and fix it first before clicking on PROCEED."
720 } else {
721 common.errorMsg(out)
722 throw new Exception("Galera is not working as expected")
723 }
724 }
725}
726
727def verifyContrail(pepperEnv, target) {
728 def salt = new com.mirantis.mk.Salt()
729 def common = new com.mirantis.mk.Common()
730 salt.commandStatus(pepperEnv, target, "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
731}
732
733
734def verifyService(pepperEnv, target, service) {
735 def salt = new com.mirantis.mk.Salt()
736 def common = new com.mirantis.mk.Common()
737 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
738 for (t in targetHosts) {
739 try {
740 salt.commandStatus(pepperEnv, t, "service ${service} status", 'running')
741 } catch (Exception er) {
742 common.errorMsg(er)
743 if (INTERACTIVE.toBoolean()) {
744 input message: "${service} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
745 } else {
746 throw new Exception("${service} service is not running correctly on ${t}")
747 }
748 }
749 }
750}
751
752def verifyCeph(pepperEnv, target, type) {
753 def salt = new com.mirantis.mk.Salt()
754 def common = new com.mirantis.mk.Common()
755 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
756 for (t in targetHosts) {
757 def hostname = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname'))
758 try {
759 salt.commandStatus(pepperEnv, t, "systemctl status ceph-${type}${hostname}", 'running')
760 } catch (Exception er) {
761 common.errorMsg(er)
762 if (INTERACTIVE.toBoolean()) {
763 input message: "Ceph-${type}${hostname} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
764 } else {
765 throw new Exception("Ceph-${type}${hostname} service is not running correctly on ${t}")
766 }
767 }
768 }
769}
770
771def verifyCephOsds(pepperEnv, target) {
772 def salt = new com.mirantis.mk.Salt()
773 def common = new com.mirantis.mk.Common()
774 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
775 for (t in targetHosts) {
776 def osd_ids = []
777 // get list of osd disks of the host
778 salt.runSaltProcessStep(pepperEnv, t, 'saltutil.sync_grains', [], null, true, 5)
779 def cephGrain = salt.getGrain(pepperEnv, t, 'ceph')
780 if(cephGrain['return'].isEmpty()){
781 throw new Exception("Ceph salt grain cannot be found!")
782 }
783 common.print(cephGrain)
784 def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk']
785 for (i in ceph_disks) {
786 def osd_id = i.getKey().toString()
787 osd_ids.add('osd.' + osd_id)
788 print("Will check osd." + osd_id)
789 }
790 for (i in osd_ids) {
791 try {
792 salt.commandStatus(pepperEnv, t, "ceph osd tree | grep -w ${i}", 'up')
793 } catch (Exception er) {
794 common.errorMsg(er)
795 if (INTERACTIVE.toBoolean()) {
796 input message: "Ceph ${i} is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
797 } else {
798 throw new Exception("Ceph ${i} is not running correctly on ${t}")
799 }
800 }
801 }
802 }
803}
804
805
806timeout(time: 12, unit: 'HOURS') {
807 node() {
808 try {
809
810 stage('Setup virtualenv for Pepper') {
811 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
812 }
813
814 // TODO, add possibility to update just specific components like kernel, openstack, contrail, ovs, rabbitmq, galera, etc.
815
816 /*
817 * Update section
818 */
819 if (updates.contains("cfg")) {
820 def target = 'I@salt:master'
821 if (salt.testTarget(pepperEnv, target)) {
822 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
823 getCfgNodeProvider(pepperEnv, master)
824 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
825 virsh.liveSnapshotPresent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME)
826 }
827 if (PER_NODE.toBoolean()) {
828 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
829 for (t in targetHosts) {
830 updatePkgs(pepperEnv, t, target)
831 highstate(pepperEnv, t)
832 }
833 } else {
834 updatePkgs(pepperEnv, target)
835 highstate(pepperEnv, target)
836 }
837 }
838 }
839
840 if (updates.contains("ctl")) {
841 def target = CTL_TARGET
842 if (salt.testTarget(pepperEnv, target)) {
843 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
844 def generalTarget = 'ctl'
845 liveSnapshot(pepperEnv, target, generalTarget)
846 }
847 if (PER_NODE.toBoolean()) {
848 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
849 for (t in targetHosts) {
850 updatePkgs(pepperEnv, t)
851 highstate(pepperEnv, t)
852 }
853 } else {
854 updatePkgs(pepperEnv, target)
855 highstate(pepperEnv, target)
856 }
857 verifyAPIs(pepperEnv, target)
858 }
859 }
860
861 if (updates.contains("prx")) {
862 def target = PRX_TARGET
863 if (salt.testTarget(pepperEnv, target)) {
864 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
865 def generalTarget = 'prx'
866 liveSnapshot(pepperEnv, target, generalTarget)
867 }
868 if (PER_NODE.toBoolean()) {
869 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
870 for (t in targetHosts) {
871 updatePkgs(pepperEnv, t)
872 highstate(pepperEnv, t)
873 }
874 } else {
875 updatePkgs(pepperEnv, target)
876 highstate(pepperEnv, target)
877 }
878 verifyService(pepperEnv, target, 'nginx')
879 }
880 }
881
882 if (updates.contains("msg")) {
883 def target = MSG_TARGET
884 if (salt.testTarget(pepperEnv, target)) {
885 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
886 def generalTarget = 'msg'
887 liveSnapshot(pepperEnv, target, generalTarget)
888 }
889 if (PER_NODE.toBoolean()) {
890 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
891 for (t in targetHosts) {
892 updatePkgs(pepperEnv, t)
893 highstate(pepperEnv, t)
894 }
895 } else {
896 updatePkgs(pepperEnv, target, target)
897 highstate(pepperEnv, target)
898 }
899 verifyService(pepperEnv, target, 'rabbitmq-server')
900 }
901 }
902
903 if (updates.contains("dbs")) {
904 def target = DBS_TARGET
905 if (salt.testTarget(pepperEnv, target)) {
906 backupGalera(pepperEnv)
907 salt.runSaltProcessStep(pepperEnv, target, 'service.stop', ['keepalived'], null, true)
908 salt.runSaltProcessStep(pepperEnv, target, 'service.stop', ['haproxy'], null, true)
909 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
910 def generalTarget = 'dbs'
911 liveSnapshot(pepperEnv, target, generalTarget)
912 }
913 if (REBOOT.toBoolean()) {
914 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
915 // one by one update
916 for (t in targetHosts) {
917 updatePkgs(pepperEnv, t)
918 highstate(pepperEnv, t)
919 }
920 } else {
921 updatePkgs(pepperEnv, target)
922 highstate(pepperEnv, target)
923 }
924 verifyGalera(pepperEnv)
925 }
926 }
927
928 if (updates.contains("ntw")) {
929 def target = NTW_TARGET
930 if (salt.testTarget(pepperEnv, target)) {
931 backupContrail(pepperEnv)
932 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
933 def generalTarget = 'ntw'
934 liveSnapshot(pepperEnv, target, generalTarget)
935 }
936 if (PER_NODE.toBoolean()) {
937 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
938 for (t in targetHosts) {
939 updatePkgs(pepperEnv, t, 'contrail')
940 highstate(pepperEnv, t)
941 verifyContrail(pepperEnv, t)
942 }
943 } else {
944 updatePkgs(pepperEnv, target, 'contrail')
945 highstate(pepperEnv, target)
946 verifyContrail(pepperEnv, target)
947 }
948 }
949 }
950
951 if (updates.contains("nal")) {
952 def target = NAL_TARGET
953 if (salt.testTarget(pepperEnv, target)) {
954 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
955 def generalTarget = 'nal'
956 liveSnapshot(pepperEnv, target, generalTarget)
957 }
958 if (PER_NODE.toBoolean()) {
959 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
960 for (t in targetHosts) {
961 updatePkgs(pepperEnv, t, 'contrail')
962 highstate(pepperEnv, t)
963 }
964 } else {
965 updatePkgs(pepperEnv, target, 'contrail')
966 highstate(pepperEnv, target)
967 }
968 verifyContrail(pepperEnv, target)
969 }
970 }
971
972 if (updates.contains("gtw-virtual")) {
973 def target = GTW_TARGET
974 if (salt.testTarget(pepperEnv, target)) {
975 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
976 def generalTarget = 'gtw'
977 liveSnapshot(pepperEnv, target, generalTarget)
978 }
979 if (PER_NODE.toBoolean()) {
980 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
981 for (t in targetHosts) {
982 updatePkgs(pepperEnv, t)
983 highstate(pepperEnv, t)
984 }
985 } else {
986 updatePkgs(pepperEnv, target)
987 highstate(pepperEnv, target)
988 }
989 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
990 }
991 }
992
993 if (updates.contains("cmn")) {
994 def target = CMN_TARGET
995 if (salt.testTarget(pepperEnv, target)) {
996 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
997 def generalTarget = 'cmn'
998 liveSnapshot(pepperEnv, target, generalTarget)
999 } else {
1000 backupCeph(pepperEnv)
1001 }
1002 if (PER_NODE.toBoolean()) {
1003 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1004 for (t in targetHosts) {
1005 updatePkgs(pepperEnv, t)
1006 highstate(pepperEnv, t)
1007 }
1008 } else {
1009 updatePkgs(pepperEnv, target)
1010 highstate(pepperEnv, target)
1011 }
1012 verifyCeph(pepperEnv, target, 'mon@')
1013 }
1014 }
1015
1016 if (updates.contains("rgw")) {
1017 def target = RGW_TARGET
1018 if (salt.testTarget(pepperEnv, target)) {
1019 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1020 def generalTarget = 'rgw'
1021 liveSnapshot(pepperEnv, target, generalTarget)
1022 }
1023 if (PER_NODE.toBoolean()) {
1024 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1025 for (t in targetHosts) {
1026 updatePkgs(pepperEnv, t)
1027 highstate(pepperEnv, t)
1028 }
1029 } else {
1030 updatePkgs(pepperEnv, target)
1031 highstate(pepperEnv, target)
1032 }
1033 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1034 }
1035 }
1036
1037 if (updates.contains("log")) {
1038 def target = LOG_TARGET
1039 if (salt.testTarget(pepperEnv, target)) {
1040 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1041 def generalTarget = 'log'
1042 liveSnapshot(pepperEnv, target, generalTarget)
1043 }
1044 if (PER_NODE.toBoolean()) {
1045 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1046 for (t in targetHosts) {
1047 updatePkgs(pepperEnv, t)
1048 highstate(pepperEnv, t)
1049 }
1050 } else {
1051 updatePkgs(pepperEnv, target)
1052 highstate(pepperEnv, target)
1053 }
1054 }
1055 }
1056
1057 if (updates.contains("mon")) {
1058 def target = MON_TARGET
1059 if (salt.testTarget(pepperEnv, target)) {
1060 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1061 def generalTarget = 'mon'
1062 liveSnapshot(pepperEnv, target, generalTarget)
1063 }
1064 if (PER_NODE.toBoolean()) {
1065 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1066 for (t in targetHosts) {
1067 updatePkgs(pepperEnv, t)
1068 highstate(pepperEnv, t)
1069 }
1070 } else {
1071 updatePkgs(pepperEnv, target)
1072 highstate(pepperEnv, target)
1073 }
1074 }
1075 }
1076
1077 if (updates.contains("mtr")) {
1078 def target = MTR_TARGET
1079 if (salt.testTarget(pepperEnv, target)) {
1080 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1081 def generalTarget = 'mtr'
1082 liveSnapshot(pepperEnv, target, generalTarget)
1083 }
1084 if (PER_NODE.toBoolean()) {
1085 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1086 for (t in targetHosts) {
1087 updatePkgs(pepperEnv, t)
1088 highstate(pepperEnv, t)
1089 }
1090 } else {
1091 updatePkgs(pepperEnv, target)
1092 highstate(pepperEnv, target)
1093 }
1094 }
1095 }
1096
1097 if (updates.contains("cid")) {
1098 def target = CID_TARGET
1099 if (salt.testTarget(pepperEnv, target)) {
1100 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1101 def generalTarget = 'cid'
1102 liveSnapshot(pepperEnv, target, generalTarget)
1103 }
1104 updatePkgs(pepperEnv, target, 'cicd')
1105 highstate(pepperEnv, target)
1106 verifyService(pepperEnv, target, 'docker')
1107 }
1108 }
1109
1110 //
1111 //physical machines update CMP_TARGET
1112 //
1113 if (updates.contains("cmp")) {
1114 def target = CMP_TARGET
1115 if (salt.testTarget(pepperEnv, target)) {
1116 if (PER_NODE.toBoolean()) {
1117 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1118 for (t in targetHosts) {
1119 updatePkgs(pepperEnv, t)
1120 highstate(pepperEnv, t)
1121 }
1122 } else {
1123 updatePkgs(pepperEnv, target)
1124 highstate(pepperEnv, target)
1125 }
1126 verifyService(pepperEnv, target, 'nova-compute')
1127 }
1128 }
1129
1130 if (updates.contains("kvm")) {
1131 def target = KVM_TARGET
1132 if (salt.testTarget(pepperEnv, target)) {
1133 if (PER_NODE.toBoolean()) {
1134 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1135 for (t in targetHosts) {
1136 updatePkgs(pepperEnv, t)
1137 highstate(pepperEnv, t)
1138 }
1139 } else {
1140 updatePkgs(pepperEnv, target, target)
1141 highstate(pepperEnv, target)
1142 }
1143 verifyService(pepperEnv, target, 'libvirt-bin')
1144 }
1145 }
1146
1147 if (updates.contains("osd")) {
1148 def target = CEPH_OSD_TARGET
1149 if (salt.testTarget(pepperEnv, target)) {
1150 if (PER_NODE.toBoolean()) {
1151 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1152 for (t in targetHosts) {
1153 updatePkgs(pepperEnv, t)
1154 highstate(pepperEnv, t)
1155 }
1156 } else {
1157 updatePkgs(pepperEnv, target)
1158 highstate(pepperEnv, target)
1159 }
1160 verifyCephOsds(pepperEnv, target)
1161 }
1162 }
1163
1164 if (updates.contains("gtw-physical")) {
1165 def target = GTW_TARGET
1166 if (salt.testTarget(pepperEnv, target)) {
1167 if (PER_NODE.toBoolean()) {
1168 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1169 for (t in targetHosts) {
1170 updatePkgs(pepperEnv, t)
1171 highstate(pepperEnv, t)
1172 }
1173 } else {
1174 updatePkgs(pepperEnv, target)
1175 highstate(pepperEnv, target)
1176 }
1177 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1178 }
1179 }
1180
1181 /*
1182 * Rollback section
1183 */
1184 /* if (rollbacks.contains("ctl")) {
1185 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1186 stage('ROLLBACK_CFG') {
1187 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."
1188 //rollbackSaltMaster(pepperEnv, 'I@salt:master')
1189 //finishSaltMasterRollback(pepperEnv, 'I@salt:master')
1190 }
1191 }
1192 } */
1193
1194 if (rollbacks.contains("ctl")) {
1195 def target = CTL_TARGET
1196 if (salt.testTarget(pepperEnv, target)) {
1197 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1198 rollback(pepperEnv, target, 'ctl')
1199 verifyAPIs(pepperEnv, target)
1200 } else {
1201 removeNode(pepperEnv, target, 'ctl')
1202 }
1203 }
1204 }
1205
1206 if (rollbacks.contains("prx")) {
1207 def target = PRX_TARGET
1208 if (salt.testTarget(pepperEnv, target)) {
1209 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1210 rollback(pepperEnv, target, 'prx')
1211 verifyService(pepperEnv, target, 'nginx')
1212 } else {
1213 removeNode(pepperEnv, target, 'prx')
1214 }
1215 }
1216 }
1217
1218 if (rollbacks.contains("msg")) {
1219 def target = MSG_TARGET
1220 if (salt.testTarget(pepperEnv, target)) {
1221 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1222 rollback(pepperEnv, target, 'msg')
1223 salt.enforceState(pepperEnv, target, 'rabbitmq')
1224 verifyService(pepperEnv, target, 'rabbitmq-server')
1225 } else {
1226 removeNode(pepperEnv, target, 'msg')
1227 }
1228 }
1229 }
1230
1231 if (rollbacks.contains("dbs")) {
1232 def target = DBS_TARGET
1233 if (salt.testTarget(pepperEnv, target)) {
1234 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1235 rollback(pepperEnv, target, 'dbs')
1236 clusterGalera(pepperEnv)
1237 verifyGalera(pepperEnv)
1238 } else {
1239 removeNode(pepperEnv, target, 'dbs')
1240 }
1241 }
1242 }
1243
1244 if (rollbacks.contains("ntw")) {
1245 def target = NTW_TARGET
1246 if (salt.testTarget(pepperEnv, target)) {
1247 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1248 rollback(pepperEnv, target, 'ntw')
1249 verifyContrail(pepperEnv, target)
1250 } else {
1251 removeNode(pepperEnv, target, 'ntw')
1252 }
1253 }
1254 }
1255
1256 if (rollbacks.contains("nal")) {
1257 def target = NAL_TARGET
1258 if (salt.testTarget(pepperEnv, target)) {
1259 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1260 rollback(pepperEnv, target, 'nal')
1261 verifyContrail(pepperEnv, target)
1262 } else {
1263 removeNode(pepperEnv, target, 'nal')
1264 }
1265 }
1266 }
1267
1268 if (rollbacks.contains("gtw-virtual")) {
1269 def target = GTW_TARGET
1270 if (salt.testTarget(pepperEnv, target)) {
1271 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1272 rollback(pepperEnv, target, 'gtw')
1273 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1274 } else {
1275 removeNode(pepperEnv, target, 'gtw')
1276 }
1277 }
1278 }
1279
1280 if (rollbacks.contains("cmn")) {
1281 def target = CMN_TARGET
1282 if (salt.testTarget(pepperEnv, target)) {
1283 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1284 rollback(pepperEnv, target, 'cmn')
1285 verifyCeph(pepperEnv, target, 'mon@')
1286 } else {
1287 removeNode(pepperEnv, target, 'cmn')
1288 }
1289 }
1290 }
1291
1292 if (rollbacks.contains("rgw")) {
1293 def target = RGW_TARGET
1294 if (salt.testTarget(pepperEnv, target)) {
1295 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1296 rollback(pepperEnv, target, 'rgw')
1297 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1298 } else {
1299 removeNode(pepperEnv, target, 'rgw')
1300 }
1301 }
1302 }
1303
1304 if (rollbacks.contains("log")) {
1305 def target = LOG_TARGET
1306 if (salt.testTarget(pepperEnv, target)) {
1307 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1308 rollback(pepperEnv, target, 'log')
1309 } else {
1310 removeNode(pepperEnv, target, 'log')
1311 }
1312 }
1313 }
1314
1315 if (rollbacks.contains("mon")) {
1316 def target = MON_TARGET
1317 if (salt.testTarget(pepperEnv, target)) {
1318 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1319 rollback(pepperEnv, target, 'mon')
1320 } else {
1321 removeNode(pepperEnv, target, 'mon')
1322 }
1323 }
1324 }
1325
1326 if (rollbacks.contains("mtr")) {
1327 def target = MTR_TARGET
1328 if (salt.testTarget(pepperEnv, target)) {
1329 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1330 rollback(pepperEnv, target, 'mtr')
1331 } else {
1332 removeNode(pepperEnv, target, 'mtr')
1333 }
1334 }
1335 }
1336 /*
1337 if (ROLLBACK_CID.toBoolean()) {
1338 def target = 'cid*'
1339 if (salt.testTarget(pepperEnv, target)) {
1340 stage('ROLLBACK_CID') {
1341 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."
1342 }
1343 }
1344 } */
1345
1346 //
1347 //physical machines rollback CMP_TARGET
1348 //
1349 if (rollbacks.contains("cmp")) {
1350 def target = CMP_TARGET
1351 if (salt.testTarget(pepperEnv, target)) {
1352 if (PER_NODE.toBoolean()) {
1353 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1354 for (t in targetHosts) {
1355 rollbackPkgs(pepperEnv, t)
1356 highstate(pepperEnv, t)
1357 }
1358 } else {
1359 rollbackPkgs(pepperEnv, target, target)
1360 highstate(pepperEnv, target)
1361 }
1362 verifyService(pepperEnv, target, 'nova-compute')
1363 }
1364 }
1365
1366 if (rollbacks.contains("kvm")) {
1367 def target = KVM_TARGET
1368 if (salt.testTarget(pepperEnv, target)) {
1369 if (PER_NODE.toBoolean()) {
1370 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1371 for (t in targetHosts) {
1372 rollbackPkgs(pepperEnv, t)
1373 highstate(pepperEnv, t)
1374 }
1375 } else {
1376 rollbackPkgs(pepperEnv, target, target)
1377 highstate(pepperEnv, target)
1378 }
1379 verifyService(pepperEnv, target, 'libvirt-bin')
1380 }
1381 }
1382
1383 if (rollbacks.contains("osd")) {
1384 def target = CEPH_OSD_TARGET
1385 if (salt.testTarget(pepperEnv, target)) {
1386 if (PER_NODE.toBoolean()) {
1387 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1388 for (t in targetHosts) {
1389 rollbackPkgs(pepperEnv, t)
1390 highstate(pepperEnv, t)
1391 }
1392 } else {
1393 rollbackPkgs(pepperEnv, target, target)
1394 highstate(pepperEnv, target)
1395 }
1396 verifyCephOsds(pepperEnv, target)
1397 }
1398 }
1399
1400 if (rollbacks.contains("gtw-physical")) {
1401 def target = GTW_TARGET
1402 if (salt.testTarget(pepperEnv, target)) {
1403 if (PER_NODE.toBoolean()) {
1404 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1405 for (t in targetHosts) {
1406 rollbackPkgs(pepperEnv, t)
1407 highstate(pepperEnv, t)
1408 }
1409 } else {
1410 rollbackPkgs(pepperEnv, target, target)
1411 highstate(pepperEnv, target)
1412 }
1413 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1414 }
1415 }
1416
1417 /*
1418 * Merge snapshots section
1419 */
1420 if (merges.contains("cfg")) {
1421 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1422 mergeSnapshot(pepperEnv, 'I@salt:master')
1423 }
1424 }
1425
1426 if (merges.contains("ctl")) {
1427 if (salt.testTarget(pepperEnv, CTL_TARGET)) {
1428 mergeSnapshot(pepperEnv, CTL_TARGET, 'ctl')
1429 }
1430 }
1431
1432 if (merges.contains("prx")) {
1433 if (salt.testTarget(pepperEnv, PRX_TARGET)) {
1434 mergeSnapshot(pepperEnv, PRX_TARGET, 'prx')
1435 }
1436 }
1437
1438 if (merges.contains("msg")) {
1439 if (salt.testTarget(pepperEnv, MSG_TARGET)) {
1440 mergeSnapshot(pepperEnv, MSG_TARGET, 'msg')
1441 }
1442 }
1443
1444 if (merges.contains("dbs")) {
1445 if (salt.testTarget(pepperEnv, DBS_TARGET)) {
1446 mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs')
1447 }
1448 }
1449
1450 if (merges.contains("ntw")) {
1451 if (salt.testTarget(pepperEnv, NTW_TARGET)) {
1452 mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw')
1453 }
1454 }
1455
1456 if (merges.contains("nal")) {
1457 if (salt.testTarget(pepperEnv, NAL_TARGET)) {
1458 mergeSnapshot(pepperEnv, NAL_TARGET, 'nal')
1459 }
1460 }
1461
1462 if (merges.contains("gtw-virtual")) {
1463 if (salt.testTarget(pepperEnv, GTW_TARGET)) {
1464 mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw')
1465 }
1466 }
1467
1468 if (merges.contains("cmn")) {
1469 if (salt.testTarget(pepperEnv, CMN_TARGET)) {
1470 mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn')
1471 }
1472 }
1473
1474 if (merges.contains("rgw")) {
1475 if (salt.testTarget(pepperEnv, RGW_TARGET)) {
1476 mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw')
1477 }
1478 }
1479
1480 if (merges.contains("log")) {
1481 if (salt.testTarget(pepperEnv, LOG_TARGET)) {
1482 mergeSnapshot(pepperEnv, LOG_TARGET. 'log')
1483 }
1484 }
1485
1486 if (merges.contains("mon")) {
1487 if (salt.testTarget(pepperEnv, MON_TARGET)) {
1488 mergeSnapshot(pepperEnv, MON_TARGET, 'mon')
1489 }
1490 }
1491
1492 if (merges.contains("mtr")) {
1493 if (salt.testTarget(pepperEnv, MTR_TARGET)) {
1494 mergeSnapshot(pepperEnv, MTR_TARGET, 'mtr')
1495 }
1496 }
1497
1498 if (merges.contains("cid")) {
1499 if (salt.testTarget(pepperEnv, CID_TARGET)) {
1500 mergeSnapshot(pepperEnv, CID_TARGET, 'cid')
1501 }
1502 }
1503
1504 if (RESTORE_GALERA.toBoolean()) {
1505 restoreGalera(pepperEnv)
1506 }
1507
1508 if (RESTORE_CONTRAIL_DB.toBoolean()) {
1509 restoreContrailDb(pepperEnv)
1510 }
1511
1512 } catch (Throwable e) {
1513 // If there was an error or exception thrown, the build failed
1514 currentBuild.result = "FAILURE"
1515 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
1516 throw e
1517 }
1518 }
1519}