blob: cb6b2f85fbab3e1ba61a8824e31e3e161c5bb35b [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
712def verifyAPIs(pepperEnv) {
713 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)
916 salt.runSaltProcessStep(pepperEnv, target, 'service.stop', ['keepalived'], null, true)
917 salt.runSaltProcessStep(pepperEnv, target, 'service.stop', ['haproxy'], null, true)
918 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
919 def generalTarget = 'dbs'
920 liveSnapshot(pepperEnv, target, generalTarget)
921 }
922 if (REBOOT.toBoolean()) {
923 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
924 // one by one update
925 for (t in targetHosts) {
926 updatePkgs(pepperEnv, t)
927 highstate(pepperEnv, t)
928 }
929 } else {
930 updatePkgs(pepperEnv, target)
931 highstate(pepperEnv, target)
932 }
933 verifyGalera(pepperEnv)
934 }
935 }
936
937 if (updates.contains("ntw")) {
938 def target = NTW_TARGET
939 if (salt.testTarget(pepperEnv, target)) {
940 backupContrail(pepperEnv)
941 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
942 def generalTarget = 'ntw'
943 liveSnapshot(pepperEnv, target, generalTarget)
944 }
945 if (PER_NODE.toBoolean()) {
946 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
947 for (t in targetHosts) {
948 updatePkgs(pepperEnv, t, 'contrail')
949 highstate(pepperEnv, t)
950 verifyContrail(pepperEnv, t)
951 }
952 } else {
953 updatePkgs(pepperEnv, target, 'contrail')
954 highstate(pepperEnv, target)
955 verifyContrail(pepperEnv, target)
956 }
957 }
958 }
959
960 if (updates.contains("nal")) {
961 def target = NAL_TARGET
962 if (salt.testTarget(pepperEnv, target)) {
963 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
964 def generalTarget = 'nal'
965 liveSnapshot(pepperEnv, target, generalTarget)
966 }
967 if (PER_NODE.toBoolean()) {
968 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
969 for (t in targetHosts) {
970 updatePkgs(pepperEnv, t, 'contrail')
971 highstate(pepperEnv, t)
972 }
973 } else {
974 updatePkgs(pepperEnv, target, 'contrail')
975 highstate(pepperEnv, target)
976 }
977 verifyContrail(pepperEnv, target)
978 }
979 }
980
981 if (updates.contains("gtw-virtual")) {
982 def target = GTW_TARGET
983 if (salt.testTarget(pepperEnv, target)) {
984 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
985 def generalTarget = 'gtw'
986 liveSnapshot(pepperEnv, target, generalTarget)
987 }
988 if (PER_NODE.toBoolean()) {
989 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
990 for (t in targetHosts) {
991 updatePkgs(pepperEnv, t)
992 highstate(pepperEnv, t)
993 }
994 } else {
995 updatePkgs(pepperEnv, target)
996 highstate(pepperEnv, target)
997 }
998 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
999 }
1000 }
1001
1002 if (updates.contains("cmn")) {
1003 def target = CMN_TARGET
1004 if (salt.testTarget(pepperEnv, target)) {
1005 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1006 def generalTarget = 'cmn'
1007 liveSnapshot(pepperEnv, target, generalTarget)
1008 } else {
Jiri Broulik906e9972018-03-26 16:12:00 +02001009 backupCeph(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001010 }
1011 if (PER_NODE.toBoolean()) {
1012 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1013 for (t in targetHosts) {
1014 updatePkgs(pepperEnv, t)
1015 highstate(pepperEnv, t)
1016 }
1017 } else {
1018 updatePkgs(pepperEnv, target)
1019 highstate(pepperEnv, target)
1020 }
1021 verifyCeph(pepperEnv, target, 'mon@')
1022 }
1023 }
1024
1025 if (updates.contains("rgw")) {
1026 def target = RGW_TARGET
1027 if (salt.testTarget(pepperEnv, target)) {
1028 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1029 def generalTarget = 'rgw'
1030 liveSnapshot(pepperEnv, target, generalTarget)
1031 }
1032 if (PER_NODE.toBoolean()) {
1033 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1034 for (t in targetHosts) {
1035 updatePkgs(pepperEnv, t)
1036 highstate(pepperEnv, t)
1037 }
1038 } else {
1039 updatePkgs(pepperEnv, target)
1040 highstate(pepperEnv, target)
1041 }
1042 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1043 }
1044 }
1045
1046 if (updates.contains("log")) {
1047 def target = LOG_TARGET
1048 if (salt.testTarget(pepperEnv, target)) {
1049 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1050 def generalTarget = 'log'
1051 liveSnapshot(pepperEnv, target, generalTarget)
1052 }
1053 if (PER_NODE.toBoolean()) {
1054 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1055 for (t in targetHosts) {
1056 updatePkgs(pepperEnv, t)
1057 highstate(pepperEnv, t)
1058 }
1059 } else {
1060 updatePkgs(pepperEnv, target)
1061 highstate(pepperEnv, target)
1062 }
1063 }
1064 }
1065
1066 if (updates.contains("mon")) {
1067 def target = MON_TARGET
1068 if (salt.testTarget(pepperEnv, target)) {
1069 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1070 def generalTarget = 'mon'
1071 liveSnapshot(pepperEnv, target, generalTarget)
1072 }
1073 if (PER_NODE.toBoolean()) {
1074 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1075 for (t in targetHosts) {
1076 updatePkgs(pepperEnv, t)
1077 highstate(pepperEnv, t)
1078 }
1079 } else {
1080 updatePkgs(pepperEnv, target)
1081 highstate(pepperEnv, target)
1082 }
1083 }
1084 }
1085
1086 if (updates.contains("mtr")) {
1087 def target = MTR_TARGET
1088 if (salt.testTarget(pepperEnv, target)) {
1089 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1090 def generalTarget = 'mtr'
1091 liveSnapshot(pepperEnv, target, generalTarget)
1092 }
1093 if (PER_NODE.toBoolean()) {
1094 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1095 for (t in targetHosts) {
1096 updatePkgs(pepperEnv, t)
1097 highstate(pepperEnv, t)
1098 }
1099 } else {
1100 updatePkgs(pepperEnv, target)
1101 highstate(pepperEnv, target)
1102 }
1103 }
1104 }
1105
1106 if (updates.contains("cid")) {
1107 def target = CID_TARGET
1108 if (salt.testTarget(pepperEnv, target)) {
1109 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1110 def generalTarget = 'cid'
1111 liveSnapshot(pepperEnv, target, generalTarget)
1112 }
1113 updatePkgs(pepperEnv, target, 'cicd')
1114 highstate(pepperEnv, target)
1115 verifyService(pepperEnv, target, 'docker')
1116 }
1117 }
1118
1119 //
1120 //physical machines update CMP_TARGET
1121 //
1122 if (updates.contains("cmp")) {
1123 def target = CMP_TARGET
1124 if (salt.testTarget(pepperEnv, target)) {
1125 if (PER_NODE.toBoolean()) {
1126 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1127 for (t in targetHosts) {
1128 updatePkgs(pepperEnv, t)
1129 highstate(pepperEnv, t)
1130 }
1131 } else {
1132 updatePkgs(pepperEnv, target)
1133 highstate(pepperEnv, target)
1134 }
1135 verifyService(pepperEnv, target, 'nova-compute')
1136 }
1137 }
1138
1139 if (updates.contains("kvm")) {
1140 def target = KVM_TARGET
1141 if (salt.testTarget(pepperEnv, target)) {
1142 if (PER_NODE.toBoolean()) {
1143 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1144 for (t in targetHosts) {
1145 updatePkgs(pepperEnv, t)
1146 highstate(pepperEnv, t)
1147 }
1148 } else {
1149 updatePkgs(pepperEnv, target, target)
1150 highstate(pepperEnv, target)
1151 }
1152 verifyService(pepperEnv, target, 'libvirt-bin')
1153 }
1154 }
1155
1156 if (updates.contains("osd")) {
1157 def target = CEPH_OSD_TARGET
1158 if (salt.testTarget(pepperEnv, target)) {
1159 if (PER_NODE.toBoolean()) {
1160 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1161 for (t in targetHosts) {
1162 updatePkgs(pepperEnv, t)
1163 highstate(pepperEnv, t)
1164 }
1165 } else {
1166 updatePkgs(pepperEnv, target)
1167 highstate(pepperEnv, target)
1168 }
1169 verifyCephOsds(pepperEnv, target)
1170 }
1171 }
1172
1173 if (updates.contains("gtw-physical")) {
1174 def target = GTW_TARGET
1175 if (salt.testTarget(pepperEnv, target)) {
1176 if (PER_NODE.toBoolean()) {
1177 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1178 for (t in targetHosts) {
1179 updatePkgs(pepperEnv, t)
1180 highstate(pepperEnv, t)
1181 }
1182 } else {
1183 updatePkgs(pepperEnv, target)
1184 highstate(pepperEnv, target)
1185 }
1186 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1187 }
1188 }
1189
1190 /*
1191 * Rollback section
1192 */
Jiri Broulik906e9972018-03-26 16:12:00 +02001193 /* if (rollbacks.contains("cfg")) {
Jiri Broulik60dcab32018-03-08 17:42:06 +01001194 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1195 stage('ROLLBACK_CFG') {
1196 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."
1197 //rollbackSaltMaster(pepperEnv, 'I@salt:master')
1198 //finishSaltMasterRollback(pepperEnv, 'I@salt:master')
1199 }
1200 }
1201 } */
1202
1203 if (rollbacks.contains("ctl")) {
1204 def target = CTL_TARGET
1205 if (salt.testTarget(pepperEnv, target)) {
1206 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1207 rollback(pepperEnv, target, 'ctl')
1208 verifyAPIs(pepperEnv, target)
1209 } else {
1210 removeNode(pepperEnv, target, 'ctl')
1211 }
1212 }
1213 }
1214
1215 if (rollbacks.contains("prx")) {
1216 def target = PRX_TARGET
1217 if (salt.testTarget(pepperEnv, target)) {
1218 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1219 rollback(pepperEnv, target, 'prx')
1220 verifyService(pepperEnv, target, 'nginx')
1221 } else {
1222 removeNode(pepperEnv, target, 'prx')
1223 }
1224 }
1225 }
1226
1227 if (rollbacks.contains("msg")) {
1228 def target = MSG_TARGET
1229 if (salt.testTarget(pepperEnv, target)) {
1230 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1231 rollback(pepperEnv, target, 'msg')
1232 salt.enforceState(pepperEnv, target, 'rabbitmq')
1233 verifyService(pepperEnv, target, 'rabbitmq-server')
1234 } else {
1235 removeNode(pepperEnv, target, 'msg')
1236 }
1237 }
1238 }
1239
1240 if (rollbacks.contains("dbs")) {
1241 def target = DBS_TARGET
1242 if (salt.testTarget(pepperEnv, target)) {
1243 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1244 rollback(pepperEnv, target, 'dbs')
1245 clusterGalera(pepperEnv)
1246 verifyGalera(pepperEnv)
1247 } else {
1248 removeNode(pepperEnv, target, 'dbs')
1249 }
1250 }
1251 }
1252
1253 if (rollbacks.contains("ntw")) {
1254 def target = NTW_TARGET
1255 if (salt.testTarget(pepperEnv, target)) {
1256 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1257 rollback(pepperEnv, target, 'ntw')
1258 verifyContrail(pepperEnv, target)
1259 } else {
1260 removeNode(pepperEnv, target, 'ntw')
1261 }
1262 }
1263 }
1264
1265 if (rollbacks.contains("nal")) {
1266 def target = NAL_TARGET
1267 if (salt.testTarget(pepperEnv, target)) {
1268 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1269 rollback(pepperEnv, target, 'nal')
1270 verifyContrail(pepperEnv, target)
1271 } else {
1272 removeNode(pepperEnv, target, 'nal')
1273 }
1274 }
1275 }
1276
1277 if (rollbacks.contains("gtw-virtual")) {
1278 def target = GTW_TARGET
1279 if (salt.testTarget(pepperEnv, target)) {
1280 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1281 rollback(pepperEnv, target, 'gtw')
1282 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1283 } else {
1284 removeNode(pepperEnv, target, 'gtw')
1285 }
1286 }
1287 }
1288
1289 if (rollbacks.contains("cmn")) {
1290 def target = CMN_TARGET
1291 if (salt.testTarget(pepperEnv, target)) {
1292 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1293 rollback(pepperEnv, target, 'cmn')
1294 verifyCeph(pepperEnv, target, 'mon@')
1295 } else {
1296 removeNode(pepperEnv, target, 'cmn')
1297 }
1298 }
1299 }
1300
1301 if (rollbacks.contains("rgw")) {
1302 def target = RGW_TARGET
1303 if (salt.testTarget(pepperEnv, target)) {
1304 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1305 rollback(pepperEnv, target, 'rgw')
1306 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1307 } else {
1308 removeNode(pepperEnv, target, 'rgw')
1309 }
1310 }
1311 }
1312
1313 if (rollbacks.contains("log")) {
1314 def target = LOG_TARGET
1315 if (salt.testTarget(pepperEnv, target)) {
1316 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1317 rollback(pepperEnv, target, 'log')
1318 } else {
1319 removeNode(pepperEnv, target, 'log')
1320 }
1321 }
1322 }
1323
1324 if (rollbacks.contains("mon")) {
1325 def target = MON_TARGET
1326 if (salt.testTarget(pepperEnv, target)) {
1327 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1328 rollback(pepperEnv, target, 'mon')
1329 } else {
1330 removeNode(pepperEnv, target, 'mon')
1331 }
1332 }
1333 }
1334
1335 if (rollbacks.contains("mtr")) {
1336 def target = MTR_TARGET
1337 if (salt.testTarget(pepperEnv, target)) {
1338 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1339 rollback(pepperEnv, target, 'mtr')
1340 } else {
1341 removeNode(pepperEnv, target, 'mtr')
1342 }
1343 }
1344 }
1345 /*
1346 if (ROLLBACK_CID.toBoolean()) {
1347 def target = 'cid*'
1348 if (salt.testTarget(pepperEnv, target)) {
1349 stage('ROLLBACK_CID') {
1350 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."
1351 }
1352 }
1353 } */
1354
1355 //
1356 //physical machines rollback CMP_TARGET
1357 //
1358 if (rollbacks.contains("cmp")) {
1359 def target = CMP_TARGET
1360 if (salt.testTarget(pepperEnv, target)) {
1361 if (PER_NODE.toBoolean()) {
1362 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1363 for (t in targetHosts) {
1364 rollbackPkgs(pepperEnv, t)
1365 highstate(pepperEnv, t)
1366 }
1367 } else {
1368 rollbackPkgs(pepperEnv, target, target)
1369 highstate(pepperEnv, target)
1370 }
1371 verifyService(pepperEnv, target, 'nova-compute')
1372 }
1373 }
1374
1375 if (rollbacks.contains("kvm")) {
1376 def target = KVM_TARGET
1377 if (salt.testTarget(pepperEnv, target)) {
1378 if (PER_NODE.toBoolean()) {
1379 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1380 for (t in targetHosts) {
1381 rollbackPkgs(pepperEnv, t)
1382 highstate(pepperEnv, t)
1383 }
1384 } else {
1385 rollbackPkgs(pepperEnv, target, target)
1386 highstate(pepperEnv, target)
1387 }
1388 verifyService(pepperEnv, target, 'libvirt-bin')
1389 }
1390 }
1391
1392 if (rollbacks.contains("osd")) {
1393 def target = CEPH_OSD_TARGET
1394 if (salt.testTarget(pepperEnv, target)) {
1395 if (PER_NODE.toBoolean()) {
1396 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1397 for (t in targetHosts) {
1398 rollbackPkgs(pepperEnv, t)
1399 highstate(pepperEnv, t)
1400 }
1401 } else {
1402 rollbackPkgs(pepperEnv, target, target)
1403 highstate(pepperEnv, target)
1404 }
1405 verifyCephOsds(pepperEnv, target)
1406 }
1407 }
1408
1409 if (rollbacks.contains("gtw-physical")) {
1410 def target = GTW_TARGET
1411 if (salt.testTarget(pepperEnv, target)) {
1412 if (PER_NODE.toBoolean()) {
1413 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1414 for (t in targetHosts) {
1415 rollbackPkgs(pepperEnv, t)
1416 highstate(pepperEnv, t)
1417 }
1418 } else {
1419 rollbackPkgs(pepperEnv, target, target)
1420 highstate(pepperEnv, target)
1421 }
1422 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1423 }
1424 }
1425
1426 /*
1427 * Merge snapshots section
1428 */
1429 if (merges.contains("cfg")) {
1430 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1431 mergeSnapshot(pepperEnv, 'I@salt:master')
1432 }
1433 }
1434
1435 if (merges.contains("ctl")) {
1436 if (salt.testTarget(pepperEnv, CTL_TARGET)) {
1437 mergeSnapshot(pepperEnv, CTL_TARGET, 'ctl')
Jiri Broulik906e9972018-03-26 16:12:00 +02001438 verifyService(pepperEnv, CTL_TARGET, 'nova-api')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001439 }
1440 }
1441
1442 if (merges.contains("prx")) {
1443 if (salt.testTarget(pepperEnv, PRX_TARGET)) {
1444 mergeSnapshot(pepperEnv, PRX_TARGET, 'prx')
Jiri Broulik906e9972018-03-26 16:12:00 +02001445 verifyService(pepperEnv, PRX_TARGET, 'nginx')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001446 }
1447 }
1448
1449 if (merges.contains("msg")) {
1450 if (salt.testTarget(pepperEnv, MSG_TARGET)) {
1451 mergeSnapshot(pepperEnv, MSG_TARGET, 'msg')
Jiri Broulik906e9972018-03-26 16:12:00 +02001452 verifyService(pepperEnv, MSG_TARGET, 'rabbitmq-server')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001453 }
1454 }
1455
1456 if (merges.contains("dbs")) {
1457 if (salt.testTarget(pepperEnv, DBS_TARGET)) {
1458 mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs')
Jiri Broulik906e9972018-03-26 16:12:00 +02001459 verifyGalera(pepperEnv)
1460 backupGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001461 }
1462 }
1463
1464 if (merges.contains("ntw")) {
1465 if (salt.testTarget(pepperEnv, NTW_TARGET)) {
1466 mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001467 verifyContrail(pepperEnv, NTW_TARGET)
1468 backupContrail(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001469 }
1470 }
1471
1472 if (merges.contains("nal")) {
1473 if (salt.testTarget(pepperEnv, NAL_TARGET)) {
1474 mergeSnapshot(pepperEnv, NAL_TARGET, 'nal')
Jiri Broulik906e9972018-03-26 16:12:00 +02001475 verifyContrail(pepperEnv, NAL_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001476 }
1477 }
1478
1479 if (merges.contains("gtw-virtual")) {
1480 if (salt.testTarget(pepperEnv, GTW_TARGET)) {
1481 mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001482 verifyService(pepperEnv, GTW_TARGET, 'neutron-dhcp-agent')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001483 }
1484 }
1485
1486 if (merges.contains("cmn")) {
1487 if (salt.testTarget(pepperEnv, CMN_TARGET)) {
1488 mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn')
Jiri Broulik906e9972018-03-26 16:12:00 +02001489 verifyCeph(pepperEnv, CMN_TARGET, 'mon@')
1490 backupCeph(pepperEnv, CMN_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001491 }
1492 }
1493
1494 if (merges.contains("rgw")) {
1495 if (salt.testTarget(pepperEnv, RGW_TARGET)) {
1496 mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001497 verifyCeph(pepperEnv, RGW_TARGET, 'radosgw@rgw.')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001498 }
1499 }
1500
1501 if (merges.contains("log")) {
1502 if (salt.testTarget(pepperEnv, LOG_TARGET)) {
1503 mergeSnapshot(pepperEnv, LOG_TARGET. 'log')
1504 }
1505 }
1506
1507 if (merges.contains("mon")) {
1508 if (salt.testTarget(pepperEnv, MON_TARGET)) {
1509 mergeSnapshot(pepperEnv, MON_TARGET, 'mon')
1510 }
1511 }
1512
1513 if (merges.contains("mtr")) {
1514 if (salt.testTarget(pepperEnv, MTR_TARGET)) {
1515 mergeSnapshot(pepperEnv, MTR_TARGET, 'mtr')
1516 }
1517 }
1518
1519 if (merges.contains("cid")) {
1520 if (salt.testTarget(pepperEnv, CID_TARGET)) {
1521 mergeSnapshot(pepperEnv, CID_TARGET, 'cid')
Jiri Broulik906e9972018-03-26 16:12:00 +02001522 verifyService(pepperEnv, CID_TARGET, 'docker')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001523 }
1524 }
1525
1526 if (RESTORE_GALERA.toBoolean()) {
1527 restoreGalera(pepperEnv)
Jiri Broulik906e9972018-03-26 16:12:00 +02001528 verifyGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001529 }
1530
1531 if (RESTORE_CONTRAIL_DB.toBoolean()) {
1532 restoreContrailDb(pepperEnv)
Jiri Broulik906e9972018-03-26 16:12:00 +02001533 // verification is already present in restore pipelines
Jiri Broulik60dcab32018-03-08 17:42:06 +01001534 }
1535
1536 } catch (Throwable e) {
1537 // If there was an error or exception thrown, the build failed
1538 currentBuild.result = "FAILURE"
1539 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
1540 throw e
1541 }
1542 }
1543}