blob: fd7e6ff4a7a9186ff0a422ffa3c41d85f2df7f74 [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)
Jiri Broulikba6d85d2018-04-05 13:29:07 +020013 * TARGET_KERNEL_UPDATES Comma separated list of nodes to update kernel if newer version is available (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_REBOOT Comma separated list of nodes to reboot after update or physical machine rollback (Valid values are cfg,ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cid,cmp,kvm,osd,gtw-physical)
15 * TARGET_HIGHSTATE Comma separated list of nodes to run Salt Highstate on after update or physical machine rollback (Valid values are cfg,ctl,prx,msg,dbs,log,mon,mtr,ntw,nal,gtw-virtual,cmn,rgw,cid,cmp,kvm,osd,gtw-physical)
Jiri Broulik60dcab32018-03-08 17:42:06 +010016 * 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 +020017 * 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)
Jiri Broulik5dac8d82018-03-29 13:34:39 +020018 * TARGET_SNAPSHOT_MERGES Comma separated list of nodes to merge live snapshot for (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 +010019 * CTL_TARGET Salt targeted CTL nodes (ex. ctl*)
20 * PRX_TARGET Salt targeted PRX nodes (ex. prx*)
21 * MSG_TARGET Salt targeted MSG nodes (ex. msg*)
22 * DBS_TARGET Salt targeted DBS nodes (ex. dbs*)
23 * LOG_TARGET Salt targeted LOG nodes (ex. log*)
24 * MON_TARGET Salt targeted MON nodes (ex. mon*)
25 * MTR_TARGET Salt targeted MTR nodes (ex. mtr*)
26 * NTW_TARGET Salt targeted NTW nodes (ex. ntw*)
27 * NAL_TARGET Salt targeted NAL nodes (ex. nal*)
28 * CMN_TARGET Salt targeted CMN nodes (ex. cmn*)
29 * RGW_TARGET Salt targeted RGW nodes (ex. rgw*)
30 * CID_TARGET Salt targeted CID nodes (ex. cid*)
31 * CMP_TARGET Salt targeted physical compute nodes (ex. cmp001*)
32 * KVM_TARGET Salt targeted physical KVM nodes (ex. kvm01*)
33 * CEPH_OSD_TARGET Salt targeted physical Ceph OSD nodes (ex. osd001*)
Jiri Broulik906e9972018-03-26 16:12:00 +020034 * GTW_TARGET Salt targeted physical or virtual GTW nodes (ex. gtw01*)
Jiri Broulik906e9972018-03-26 16:12:00 +020035 * 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)
36 * PURGE_PKGS Space separated list of pkgs=versions to be purged on physical targeted machines (ex. pkg_name1=pkg_version1 pkg_name2=pkg_version2)
37 * 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 +010038 * RESTORE_GALERA Restore Galera DB (bool)
39 * RESTORE_CONTRAIL_DB Restore Cassandra and Zookeeper DBs for OpenContrail (bool)
40 *
41**/
42def common = new com.mirantis.mk.Common()
43def salt = new com.mirantis.mk.Salt()
44def python = new com.mirantis.mk.Python()
45def virsh = new com.mirantis.mk.Virsh()
46
47def updates = TARGET_UPDATES.tokenize(",").collect{it -> it.trim()}
48def rollbacks = TARGET_ROLLBACKS.tokenize(",").collect{it -> it.trim()}
Jiri Broulik5dac8d82018-03-29 13:34:39 +020049def merges = TARGET_SNAPSHOT_MERGES.tokenize(",").collect{it -> it.trim()}
Jiri Broulik7ba05e42018-04-06 11:39:25 +020050def reboots = TARGET_REBOOT.tokenize(",").collect{it -> it.trim()}
Jiri Broulik60dcab32018-03-08 17:42:06 +010051
52def pepperEnv = "pepperEnv"
53def minions
54def result
55def packages
56def command
57def commandKwargs
58
59def updatePkgs(pepperEnv, target, targetType="", targetPackages="") {
60 def salt = new com.mirantis.mk.Salt()
61 def common = new com.mirantis.mk.Common()
Jiri Broulikba6d85d2018-04-05 13:29:07 +020062 def kernelUpdates = TARGET_KERNEL_UPDATES.tokenize(",").collect{it -> it.trim()}
63 def distUpgrade = false
Jiri Broulik60dcab32018-03-08 17:42:06 +010064 def commandKwargs
Jiri Broulik60dcab32018-03-08 17:42:06 +010065 def pkgs
66 def out
67
68 salt.enforceState(pepperEnv, target, 'linux.system.repo')
69
70 stage("List package upgrades") {
71 common.infoMsg("Listing all the packages that have a new update available on ${target}")
Jiri Broulikba6d85d2018-04-05 13:29:07 +020072 if (kernelUpdates.contains(targetType)) {
73 pkgs = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.list_upgrades', [], null, true))
74 } else {
75 pkgs = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.list_upgrades', ['dist_upgrade=False'], null, true))
76 }
Jiri Broulik60dcab32018-03-08 17:42:06 +010077 if(targetPackages != "" && targetPackages != "*"){
78 common.infoMsg("Note that only the ${targetPackages} would be installed from the above list of available updates on the ${target}")
79 }
80 }
81
82 if (INTERACTIVE.toBoolean()) {
83 stage("Confirm live package upgrades on ${target}") {
84 if (targetPackages=="") {
85 def userInput = input(
86 id: 'userInput', message: 'Insert package names for update', parameters: [
87 [$class: 'TextParameterDefinition', defaultValue: pkgs.keySet().join(",").toString(), description: 'Package names (or *)', name: 'packages']
88 ])
89 if (userInput!= "" && userInput!= "*") {
90 targetPackages = userInput
91 }
92 } else {
93 input message: "Approve live package upgrades on ${target} nodes?"
94 }
95 }
96 } else {
97 targetPackages = pkgs.keySet().join(",").toString()
98 }
99
100 if (targetPackages != "") {
101 // list installed versions of pkgs that will be upgraded
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200102 if (targetType == 'kvm' || targetType == 'cmp' || targetType == 'osd' || targetType == 'gtw-physical') {
103 def installedPkgs = []
104 def newPkgs = []
105 def targetPkgList = targetPackages.tokenize(',')
106 for (pkg in targetPkgList) {
107 def version
108 try {
109 def pkgsDetails = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.info_installed', [pkg], null, true))
110 version = pkgsDetails.get(pkg).get('version')
111 } catch (Exception er) {
112 common.infoMsg("${pkg} not installed yet")
113 }
114 if (version?.trim()) {
115 installedPkgs.add(pkg + '=' + version)
116 } else {
117 newPkgs.add(pkg)
118 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100119 }
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200120 common.warningMsg("the following list of pkgs will be upgraded")
121 common.warningMsg(installedPkgs.join(" "))
122 common.warningMsg("the following list of pkgs will be newly installed")
123 common.warningMsg(newPkgs.join(" "))
Jiri Broulik60dcab32018-03-08 17:42:06 +0100124 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100125 // set variables
126 command = "pkg.install"
127 packages = targetPackages
128 commandKwargs = ['only_upgrade': 'true','force_yes': 'true']
129
130 }else {
131 command = "pkg.upgrade"
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200132 if (kernelUpdates.contains(targetType)) {
133 commandKwargs = ['dist_upgrade': 'true']
134 distUpgrade = true
135 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100136 packages = null
137 }
138
Jiri Broulik60dcab32018-03-08 17:42:06 +0100139 stage("stop services on ${target}") {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200140 if ((STOP_SERVICES.toBoolean()) && (targetType != 'cid')) {
141 if (targetType == 'ntw' || targetType == 'nal') {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200142 contrailServices(pepperEnv, target, 'stop')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100143 } else {
144 def probe = salt.getFirstMinion(pepperEnv, "${target}")
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200145 services(pepperEnv, probe, target, 'stop')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100146 }
147 }
148 }
149
150 stage('Apply package upgrades') {
151 // salt master pkg
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200152 if (targetType == 'cfg') {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100153 common.warningMsg('salt-master pkg upgrade, rerun the pipeline if disconnected')
154 salt.runSaltProcessStep(pepperEnv, target, 'pkg.install', ['salt-master'], null, true, 5)
155 salt.minionsReachable(pepperEnv, 'I@salt:master', '*')
156 }
157 // salt minion pkg
158 salt.runSaltProcessStep(pepperEnv, target, 'pkg.install', ['salt-minion'], null, true, 5)
159 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
160 common.infoMsg('Performing pkg upgrades ... ')
161 common.retry(3){
162 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, true, packages, commandKwargs)
163 salt.printSaltCommandResult(out)
164 }
165 def osRelease = salt.getGrain(pepperEnv, target, 'lsb_distrib_codename')
166 if (osRelease.toString().toLowerCase().contains('trusty')) {
167 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --force-yes -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
168 } else {
169 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q -f --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
170 }
171 if (out.toString().contains('errors:')) {
172 try {
173 if (packages?.trim()) {
174 packages = packages.replaceAll(',', ' ')
175 common.retry(3){
176 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install ' + packages])
177 }
178 } else {
179 if (distUpgrade) {
180 common.retry(3){
181 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' dist-upgrade'])
182 }
183 } else {
184 common.retry(3){
185 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' upgrade'])
186 }
187 } }
188 if (out.toString().contains('E: ')) {
189 common.errorMsg(out)
190 if (INTERACTIVE.toBoolean()) {
191 input message: "Pkgs update failed to be updated on ${target}. Please fix it manually."
192 } else {
193 salt.printSaltCommandResult(out)
194 throw new Exception("Pkgs update failed")
195 }
196 }
197 } catch (Exception e) {
198 common.errorMsg(out)
199 common.errorMsg(e)
200 if (INTERACTIVE.toBoolean()) {
201 input message: "Pkgs update failed to be updated on ${target}. Please fix it manually."
202 } else {
203 throw new Exception("Pkgs update failed")
204 }
205 }
206 }
207 }
208}
209
210def rollbackPkgs(pepperEnv, target, targetType = "", targetPackages="") {
211 def salt = new com.mirantis.mk.Salt()
212 def common = new com.mirantis.mk.Common()
213 def probe = salt.getFirstMinion(pepperEnv, "${target}")
214 def distUpgrade
215 def pkgs
216 def out
217
218 salt.enforceState(pepperEnv, target, 'linux.system.repo')
219
220 if (ROLLBACK_PKG_VERSIONS == "") {
221 stage("List package upgrades") {
222 common.infoMsg("Listing all the packages that have a new update available on ${target}")
223 pkgs = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, target, 'pkg.list_upgrades', [], null, true))
224 if(targetPackages != "" && targetPackages != "*"){
225 common.infoMsg("Note that only the ${targetPackages} would be installed from the above list of available updates on the ${target}")
226 }
227 }
228
229 if (INTERACTIVE.toBoolean()) {
230 stage("Confirm live package upgrades on ${target}") {
231 if(targetPackages==""){
232 timeout(time: 2, unit: 'HOURS') {
233 def userInput = input(
234 id: 'userInput', message: 'Insert package names for update', parameters: [
235 [$class: 'TextParameterDefinition', defaultValue: pkgs.keySet().join(",").toString(), description: 'Package names (or *)', name: 'packages']
236 ])
237 if(userInput!= "" && userInput!= "*"){
238 targetPackages = userInput
239 }
240 }
241 }else{
242 timeout(time: 2, unit: 'HOURS') {
243 input message: "Approve live package upgrades on ${target} nodes?"
244 }
245 }
246 }
247 } else {
248 targetPackages = pkgs.keySet().join(",").toString()
249 }
250 } else {
251 targetPackages = ROLLBACK_PKG_VERSIONS
252 }
253
254 if (targetPackages != "") {
255 // set variables
256 packages = targetPackages
257 } else {
258 distUpgrade = true
259 packages = null
260 }
261
262 stage("stop services on ${target}") {
263 try {
264 if (INTERACTIVE.toBoolean()) {
265 input message: "Click PROCEED to interactively stop services on ${target}. Otherwise click ABORT to skip stopping them and continue."
266 }
267 } catch (Exception er) {
268 common.infoMsg('skipping stopping services')
269 return
270 }
271 if (STOP_SERVICES.toBoolean()) {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200272 services(pepperEnv, probe, target, 'stop')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100273 }
274 }
275
276 stage('Apply package downgrades') {
277 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" '
278 common.infoMsg('Performing pkgs purge/remove ... ')
279 try {
280 if (PURGE_PKGS != "") {
281 def purgePackages = PURGE_PKGS.replaceAll(',', ' ')
282 common.retry(3){
283 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' purge ' + purgePackages])
284 }
285 }
286 if (REMOVE_PKGS != "") {
287 def removePackages = REMOVE_PKGS.replaceAll(',', ' ')
288 common.retry(3){
289 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' remove ' + removePackages])
290 }
291 }
292 if (out.toString().contains('E: ')) {
293 common.errorMsg(out)
294 if (INTERACTIVE.toBoolean()) {
295 input message: "Pkgs ${packages} purge failed on ${target}. Please fix it manually."
296 } else {
297 salt.printSaltCommandResult(out)
298 throw new Exception("Pkgs {packages} purge failed")
299 }
300 }
301 } catch (Exception e) {
302 common.errorMsg(out)
303 common.errorMsg(e)
304 if (INTERACTIVE.toBoolean()) {
305 input message: "Pkgs {packages} purge on ${target}. Please fix it manually."
306 } else {
307 throw new Exception("Pkgs {packages} purge failed")
308 }
309 }
310
311 common.infoMsg('Performing pkg downgrades ... ')
312 try {
313 packages = packages.replaceAll(',', ' ')
314 if (packages?.trim()) {
315 packages = packages.replaceAll(',', ' ')
316 common.retry(3){
317 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install salt-minion'], null, true, 5)
318 }
319 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
320 common.retry(3){
321 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' install ' + packages])
322 }
323 } else {
324 if (distUpgrade) {
325 common.retry(3){
326 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' dist-upgrade'])
327 }
328 } else {
329 common.retry(3){
330 out = salt.runSaltProcessStep(pepperEnv, target, 'cmd.run', [args + ' upgrade'])
331 }
332 }
333 }
334 if (out.toString().contains('E: ')) {
335 common.errorMsg(out)
336 if (INTERACTIVE.toBoolean()) {
337 input message: "Pkgs rollback failed on ${target}. Please fix it manually."
338 } else {
339 salt.printSaltCommandResult(out)
340 throw new Exception("Pkgs rollback failed")
341 }
342 }
343 } catch (Exception e) {
344 common.errorMsg(out)
345 common.errorMsg(e)
346 if (INTERACTIVE.toBoolean()) {
347 input message: "Pkgs rollback failed on ${target}. Please fix it manually."
348 } else {
349 throw new Exception("Pkgs rollback failed")
350 }
351 }
352 }
353}
354
Jiri Broulik827d0112018-04-25 16:00:07 +0200355def getNodeProvider(pepperEnv, nodeName, type='') {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100356 def salt = new com.mirantis.mk.Salt()
357 def common = new com.mirantis.mk.Common()
Jiri Broulik827d0112018-04-25 16:00:07 +0200358 def kvms = salt.getMinions(pepperEnv, 'I@salt:control')
359 for (kvm in kvms) {
360 try {
361 vms = salt.getReturnValues(salt.runSaltProcessStep(pepperEnv, kvm, 'virt.list_domains', [], null, true))
362 if (vms.toString().contains(nodeName)) {
363 if (type == 'master' && !CFG_NODE_PROVIDER?.trim()) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100364 CFG_NODE_PROVIDER = kvm
Jiri Broulik827d0112018-04-25 16:00:07 +0200365 } else {
366 return kvm
Jiri Broulik60dcab32018-03-08 17:42:06 +0100367 //break
368 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100369 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100370 } catch (Exception er) {
Jiri Broulik827d0112018-04-25 16:00:07 +0200371 common.infoMsg("${nodeName} not present on ${kvm}")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100372 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100373 }
374}
375
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200376def services(pepperEnv, probe, target, action='stop') {
377 def services = ["keepalived","haproxy","nginx","nova-api","cinder","glance","heat","neutron","apache2","rabbitmq-server"]
378 if (action == 'stop') {
379 def openstack = new com.mirantis.mk.Openstack()
380 openstack.stopServices(pepperEnv, probe, target, services, INTERACTIVE.toBoolean())
Jiri Broulik60dcab32018-03-08 17:42:06 +0100381 } else {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200382 def salt = new com.mirantis.mk.Salt()
383 for (s in services) {
384 def outputServicesStr = salt.getReturnValues(salt.cmdRun(pepperEnv, "${probe}*", "service --status-all | grep ${s} | awk \'{print \$4}\'"))
385 def servicesList = outputServicesStr.tokenize("\n").init() //init() returns the items from the Iterable excluding the last item
386 if (servicesList) {
387 for (name in servicesList) {
388 if (!name.contains('Salt command')) {
389 salt.runSaltProcessStep(pepperEnv, "${target}*", 'service.start', ["${name}"])
390 }
391 }
392 }
393 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100394 }
395}
396
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200397// must be treated separately due to OC on Trusty
398def contrailServices(pepperEnv, target, action='stop') {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100399 def salt = new com.mirantis.mk.Salt()
400 def common = new com.mirantis.mk.Common()
401 def services = []
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200402 if (action == 'stop') {
403 services.add('supervisor-control')
404 services.add('supervisor-config')
405 services.add('supervisor-database')
406 services.add('zookeeper')
407 services.add('ifmap-server')
408 services.add('haproxy')
409 services.add('keepalived')
410 } else {
411 services.add('keepalived')
412 services.add('haproxy')
413 services.add('ifmap-server')
414 services.add('zookeeper')
415 services.add('supervisor-database')
416 services.add('supervisor-config')
417 services.add('supervisor-control')
418 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100419 for (s in services) {
420 try {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200421 salt.runSaltProcessStep(pepperEnv, target, "service.${action}", [s], null, true)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100422 } catch (Exception er) {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200423 common.warningMsg(er)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100424 }
425 }
426}
427
Jiri Broulik059d2df2018-06-15 14:03:34 +0200428def periodicCheck(pepperEnv, target, maxRetries=50) {
429 def salt = new com.mirantis.mk.Salt()
430 def common = new com.mirantis.mk.Common()
431 def count = 0
432 while(count < maxRetries) {
433 try {
434 sleep(10)
435 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
436 break
437 } catch (Exception e) {
438 common.warningMsg("${target} not ready yet. Waiting ...")
439 }
440 count++
441 }
442}
443
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200444def highstate(pepperEnv, target, type) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100445 def salt = new com.mirantis.mk.Salt()
446 def common = new com.mirantis.mk.Common()
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200447 def highstates = TARGET_HIGHSTATE.tokenize(",").collect{it -> it.trim()}
448 def reboots = TARGET_REBOOT.tokenize(",").collect{it -> it.trim()}
449 // optionally run highstate
450 if (highstates.contains(type)) {
451 stage("Apply highstate on ${target} nodes") {
452 try {
453 common.retry(3){
454 salt.enforceHighstate(pepperEnv, target)
455 }
456 } catch (Exception e) {
457 common.errorMsg(e)
458 if (INTERACTIVE.toBoolean()) {
459 input message: "Highstate failed on ${target}. Fix it manually or run rollback on ${target}."
460 } else {
461 throw new Exception("highstate failed")
462 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100463 }
464 }
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200465 } else if (!reboots.contains(type) && STOP_SERVICES.toBoolean() && type != 'cid') {
466 if (type == 'ntw' || type == 'nal') {
467 contrailServices(pepperEnv, target, 'start')
468 } else {
469 def probe = salt.getFirstMinion(pepperEnv, "${target}")
470 services(pepperEnv, probe, target, 'start')
471 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100472 }
473 // optionally reboot
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200474 if (reboots.contains(type)) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100475 stage("Reboot ${target} nodes") {
Jiri Broulik059d2df2018-06-15 14:03:34 +0200476 if (type == 'cfg') {
477 try {
478 salt.runSaltProcessStep(pepperEnv, target, 'system.reboot', null, null, true, 5)
479 } catch (Exception e) {
480 periodicCheck(pepperEnv, target)
481 }
482 } else {
483 salt.runSaltProcessStep(pepperEnv, target, 'system.reboot', null, null, true, 5)
484 sleep 10
485 salt.minionsReachable(pepperEnv, 'I@salt:master', target)
486 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100487 }
488 }
489}
490
491def rollback(pepperEnv, tgt, generalTarget) {
492 def common = new com.mirantis.mk.Common()
493 try {
494 if (INTERACTIVE.toBoolean()) {
495 input message: "Are you sure to rollback ${generalTarget}? To rollback click on PROCEED. To skip rollback click on ABORT."
496 }
497 } catch (Exception er) {
498 common.infoMsg('skipping rollback')
499 return
500 }
501 try {
502 rollbackLiveSnapshot(pepperEnv, tgt, generalTarget)
503 } catch (Exception err) {
504 common.errorMsg(err)
505 if (INTERACTIVE.toBoolean()) {
506 input message: "Rollback for ${tgt} failed please fix it manually before clicking PROCEED."
507 } else {
508 throw new Exception("Rollback failed for ${tgt}")
509 }
510 }
511}
512
513def liveSnapshot(pepperEnv, tgt, generalTarget) {
514 def salt = new com.mirantis.mk.Salt()
515 def common = new com.mirantis.mk.Common()
516 def virsh = new com.mirantis.mk.Virsh()
517 def domain = salt.getDomainName(pepperEnv)
518 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
519 common.warningMsg(target_hosts)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100520 for (t in target_hosts) {
521 def target = salt.stripDomainName(t)
Jiri Broulik827d0112018-04-25 16:00:07 +0200522 def nodeProvider = getNodeProvider(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100523 virsh.liveSnapshotPresent(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100524 }
525}
526
527def mergeSnapshot(pepperEnv, tgt, generalTarget='') {
528 def salt = new com.mirantis.mk.Salt()
529 def virsh = new com.mirantis.mk.Virsh()
530 def domain = salt.getDomainName(pepperEnv)
531 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100532 for (t in target_hosts) {
533 if (tgt == 'I@salt:master') {
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200534 def master = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname'))
Jiri Broulik827d0112018-04-25 16:00:07 +0200535 getNodeProvider(pepperEnv, master, 'master')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100536 virsh.liveSnapshotMerge(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME)
537 } else {
538 def target = salt.stripDomainName(t)
Jiri Broulik827d0112018-04-25 16:00:07 +0200539 def nodeProvider = getNodeProvider(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100540 virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
541 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100542 }
Jiri Broulik906e9972018-03-26 16:12:00 +0200543 salt.minionsReachable(pepperEnv, 'I@salt:master', tgt)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100544}
545
546
547
548def rollbackLiveSnapshot(pepperEnv, tgt, generalTarget) {
549 def salt = new com.mirantis.mk.Salt()
550 def virsh = new com.mirantis.mk.Virsh()
551 def common = new com.mirantis.mk.Common()
552 def domain = salt.getDomainName(pepperEnv)
553 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
554 // first destroy all vms
Jiri Broulik60dcab32018-03-08 17:42:06 +0100555 for (t in target_hosts) {
556 def target = salt.stripDomainName(t)
Jiri Broulik827d0112018-04-25 16:00:07 +0200557 def nodeProvider = getNodeProvider(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100558 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100559 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100560 // rollback vms
561 for (t in target_hosts) {
562 def target = salt.stripDomainName(t)
Jiri Broulik827d0112018-04-25 16:00:07 +0200563 def nodeProvider = getNodeProvider(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100564 virsh.liveSnapshotRollback(pepperEnv, nodeProvider, target, SNAPSHOT_NAME)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100565 }
566 try {
567 salt.minionsReachable(pepperEnv, 'I@salt:master', tgt)
568 // purge and setup previous repos
569 salt.enforceState(pepperEnv, tgt, 'linux.system.repo')
570 } catch (Exception e) {
571 common.errorMsg(e)
572 if (INTERACTIVE.toBoolean()) {
573 input message: "Salt state linux.system.repo on ${tgt} failed. Do you want to PROCEED?."
574 } else {
575 throw new Exception("Salt state linux.system.repo on ${tgt} failed")
576 }
577 }
578}
579
580def removeNode(pepperEnv, tgt, generalTarget) {
581 def salt = new com.mirantis.mk.Salt()
582 def virsh = new com.mirantis.mk.Virsh()
583 def common = new com.mirantis.mk.Common()
584 def domain = salt.getDomainName(pepperEnv)
585 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
586 // first destroy all vms
Jiri Broulik60dcab32018-03-08 17:42:06 +0100587 for (t in target_hosts) {
588 def target = salt.stripDomainName(t)
Jiri Broulik827d0112018-04-25 16:00:07 +0200589 def nodeProvider = getNodeProvider(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100590 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true)
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200591 //salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.undefine', ["${target}.${domain}"], null, true)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100592 try {
593 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
594 } catch (Exception e) {
595 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
596 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100597 }
598}
599
Jiri Broulik906e9972018-03-26 16:12:00 +0200600def saltMasterBackup(pepperEnv) {
601 def salt = new com.mirantis.mk.Salt()
602 salt.enforceState(pepperEnv, 'I@salt:master', 'backupninja')
603 salt.cmdRun(pepperEnv, 'I@salt:master', "su root -c 'backupninja -n --run /etc/backup.d/200.backup.rsync'")
604}
605
Jiri Broulik60dcab32018-03-08 17:42:06 +0100606def backupCeph(pepperEnv, tgt) {
607 def salt = new com.mirantis.mk.Salt()
608 salt.enforceState(pepperEnv, 'I@ceph:backup:server', 'ceph.backup')
609 salt.enforceState(pepperEnv, "I@ceph:backup:client and ${tgt}", 'ceph.backup')
610 salt.cmdRun(pepperEnv, "I@ceph:backup:client and ${tgt}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh -s'")
611}
612
613def backupGalera(pepperEnv) {
614 def salt = new com.mirantis.mk.Salt()
615 salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup'])
616 salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client'])
617 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
618 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh -s -f'")
619}
620
621// cluster galera - wsrep_cluster_size
622def clusterGalera(pepperEnv) {
623 def salt = new com.mirantis.mk.Salt()
624 def common = new com.mirantis.mk.Common()
625 try {
626 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'])
627 } catch (Exception er) {
628 common.warningMsg('Mysql service already stopped')
629 }
630 try {
631 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'])
632 } catch (Exception er) {
633 common.warningMsg('Mysql service already stopped')
634 }
635 try {
636 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
637 } catch (Exception er) {
638 common.warningMsg('Files are not present')
639 }
640 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
641 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'])
642 // wait until mysql service on galera master is up
643 try {
644 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
645 } catch (Exception er) {
646 if (INTERACTIVE.toBoolean()) {
647 input message: "Database is not running please fix it first and only then click on PROCEED."
648 } else {
649 throw new Exception("Database is not running correctly")
650 }
651 }
652 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'])
653}
654
655def restoreGalera(pepperEnv) {
656 def salt = new com.mirantis.mk.Salt()
657 def common = new com.mirantis.mk.Common()
658 def openstack = new com.mirantis.mk.Openstack()
659 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "rm -rf /var/lib/mysql/*")
660 openstack.restoreGaleraDb(pepperEnv)
661}
662
663def backupZookeeper(pepperEnv) {
664 def salt = new com.mirantis.mk.Salt()
665 def common = new com.mirantis.mk.Common()
666 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
667 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
668 try {
669 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh -s'")
670 } catch (Exception er) {
671 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
672 }
673}
674
675def backupCassandra(pepperEnv) {
676 def salt = new com.mirantis.mk.Salt()
677 def common = new com.mirantis.mk.Common()
678
679 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
680 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
681 try {
682 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh -s'")
683 } catch (Exception er) {
684 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
685 }
686}
687
688def backupContrail(pepperEnv) {
689 backupZookeeper(pepperEnv)
690 backupCassandra(pepperEnv)
691}
692
693// cassandra and zookeeper
694def restoreContrailDb(pepperEnv) {
695 def salt = new com.mirantis.mk.Salt()
696 def common = new com.mirantis.mk.Common()
697 build job: "deploy-zookeeper-restore", parameters: [
698 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
699 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
700 ]
701 build job: "deploy-cassandra-db-restore", parameters: [
702 [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS],
703 [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL]
704 ]
705}
706
Jiri Broulikd2dd5632018-03-27 15:44:56 +0200707def verifyAPIs(pepperEnv, target) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100708 def salt = new com.mirantis.mk.Salt()
709 def common = new com.mirantis.mk.Common()
Jiri Broulikad606d02018-03-28 14:22:43 +0200710 def out = 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')
711 if (out.toString().toLowerCase().contains('error')) {
712 common.errorMsg(out)
713 if (INTERACTIVE.toBoolean()) {
714 input message: "APIs are not working as expected. Please fix it manually."
715 } else {
716 throw new Exception("APIs are not working as expected")
717 }
718 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100719}
720
Jiri Broulikad606d02018-03-28 14:22:43 +0200721def verifyGalera(pepperEnv, target, count=0, maxRetries=200) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100722 def salt = new com.mirantis.mk.Salt()
723 def common = new com.mirantis.mk.Common()
Jiri Broulikad606d02018-03-28 14:22:43 +0200724 def out
725 while(count < maxRetries) {
726 try {
William Konitzer667143f2018-06-15 14:21:17 -0500727 out = salt.getReturnValues(salt.cmdRun(pepperEnv, target, 'salt-call -l quiet mysql.status | grep -A1 wsrep_cluster_size'))
Jiri Broulikad606d02018-03-28 14:22:43 +0200728 } catch (Exception er) {
729 common.infoMsg(er)
730 }
731 if ((!out.toString().contains('wsrep_cluster_size')) || (out.toString().contains('0'))) {
732 count++
733 if (count == maxRetries) {
734 if (INTERACTIVE.toBoolean()) {
735 input message: "Galera is not working as expected. Please check it and fix it first before clicking on PROCEED."
736 } else {
737 common.errorMsg(out)
738 throw new Exception("Galera is not working as expected")
739 }
740 }
741 sleep(time: 500, unit: 'MILLISECONDS')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100742 } else {
Jiri Broulikad606d02018-03-28 14:22:43 +0200743 break
Jiri Broulik60dcab32018-03-08 17:42:06 +0100744 }
745 }
746}
747
748def verifyContrail(pepperEnv, target) {
749 def salt = new com.mirantis.mk.Salt()
750 def common = new com.mirantis.mk.Common()
751 salt.commandStatus(pepperEnv, target, "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
752}
753
754
755def verifyService(pepperEnv, target, service) {
756 def salt = new com.mirantis.mk.Salt()
757 def common = new com.mirantis.mk.Common()
758 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
759 for (t in targetHosts) {
760 try {
761 salt.commandStatus(pepperEnv, t, "service ${service} status", 'running')
762 } catch (Exception er) {
763 common.errorMsg(er)
764 if (INTERACTIVE.toBoolean()) {
765 input message: "${service} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
766 } else {
767 throw new Exception("${service} service is not running correctly on ${t}")
768 }
769 }
770 }
771}
772
773def verifyCeph(pepperEnv, target, type) {
774 def salt = new com.mirantis.mk.Salt()
775 def common = new com.mirantis.mk.Common()
776 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
777 for (t in targetHosts) {
778 def hostname = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname'))
779 try {
780 salt.commandStatus(pepperEnv, t, "systemctl status ceph-${type}${hostname}", 'running')
781 } catch (Exception er) {
782 common.errorMsg(er)
783 if (INTERACTIVE.toBoolean()) {
784 input message: "Ceph-${type}${hostname} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
785 } else {
786 throw new Exception("Ceph-${type}${hostname} service is not running correctly on ${t}")
787 }
788 }
789 }
790}
791
792def verifyCephOsds(pepperEnv, target) {
793 def salt = new com.mirantis.mk.Salt()
794 def common = new com.mirantis.mk.Common()
795 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
796 for (t in targetHosts) {
797 def osd_ids = []
798 // get list of osd disks of the host
799 salt.runSaltProcessStep(pepperEnv, t, 'saltutil.sync_grains', [], null, true, 5)
800 def cephGrain = salt.getGrain(pepperEnv, t, 'ceph')
801 if(cephGrain['return'].isEmpty()){
802 throw new Exception("Ceph salt grain cannot be found!")
803 }
804 common.print(cephGrain)
805 def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk']
806 for (i in ceph_disks) {
807 def osd_id = i.getKey().toString()
808 osd_ids.add('osd.' + osd_id)
809 print("Will check osd." + osd_id)
810 }
811 for (i in osd_ids) {
812 try {
813 salt.commandStatus(pepperEnv, t, "ceph osd tree | grep -w ${i}", 'up')
814 } catch (Exception er) {
815 common.errorMsg(er)
816 if (INTERACTIVE.toBoolean()) {
817 input message: "Ceph ${i} is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED."
818 } else {
819 throw new Exception("Ceph ${i} is not running correctly on ${t}")
820 }
821 }
822 }
823 }
824}
825
826
827timeout(time: 12, unit: 'HOURS') {
828 node() {
829 try {
830
831 stage('Setup virtualenv for Pepper') {
832 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
833 }
834
835 // TODO, add possibility to update just specific components like kernel, openstack, contrail, ovs, rabbitmq, galera, etc.
836
837 /*
838 * Update section
839 */
840 if (updates.contains("cfg")) {
841 def target = 'I@salt:master'
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200842 def type = 'cfg'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100843 if (salt.testTarget(pepperEnv, target)) {
844 def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname'))
Jiri Broulik827d0112018-04-25 16:00:07 +0200845 getNodeProvider(pepperEnv, master, 'master')
Jiri Broulik60dcab32018-03-08 17:42:06 +0100846 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
847 virsh.liveSnapshotPresent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME)
Jiri Broulik906e9972018-03-26 16:12:00 +0200848 } else {
849 saltMasterBackup(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100850 }
851 if (PER_NODE.toBoolean()) {
852 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
853 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200854 updatePkgs(pepperEnv, t, type)
855 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100856 }
857 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200858 updatePkgs(pepperEnv, target, type)
859 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100860 }
861 }
862 }
863
864 if (updates.contains("ctl")) {
865 def target = CTL_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200866 def type = 'ctl'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100867 if (salt.testTarget(pepperEnv, target)) {
868 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200869 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100870 }
871 if (PER_NODE.toBoolean()) {
872 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
873 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200874 updatePkgs(pepperEnv, t, type)
875 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100876 }
877 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200878 updatePkgs(pepperEnv, target, type)
879 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100880 }
881 verifyAPIs(pepperEnv, target)
882 }
883 }
884
885 if (updates.contains("prx")) {
886 def target = PRX_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200887 def type = 'prx'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100888 if (salt.testTarget(pepperEnv, target)) {
889 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200890 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100891 }
892 if (PER_NODE.toBoolean()) {
893 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
894 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200895 updatePkgs(pepperEnv, t, type)
896 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100897 }
898 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200899 updatePkgs(pepperEnv, target, type)
900 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100901 }
902 verifyService(pepperEnv, target, 'nginx')
903 }
904 }
905
906 if (updates.contains("msg")) {
907 def target = MSG_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200908 def type = 'msg'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100909 if (salt.testTarget(pepperEnv, target)) {
910 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200911 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100912 }
913 if (PER_NODE.toBoolean()) {
914 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
915 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200916 updatePkgs(pepperEnv, t, type)
917 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100918 }
919 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200920 updatePkgs(pepperEnv, target, type)
921 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100922 }
923 verifyService(pepperEnv, target, 'rabbitmq-server')
924 }
925 }
926
927 if (updates.contains("dbs")) {
928 def target = DBS_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200929 def type = 'dbs'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100930 if (salt.testTarget(pepperEnv, target)) {
931 backupGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100932 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200933 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100934 }
Jiri Broulik7ba05e42018-04-06 11:39:25 +0200935 if (reboots.contains(type) || PER_NODE.toBoolean()) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100936 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100937 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200938 updatePkgs(pepperEnv, t, type)
939 highstate(pepperEnv, t, type)
Jiri Broulikad606d02018-03-28 14:22:43 +0200940 verifyGalera(pepperEnv, t)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100941 }
942 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200943 updatePkgs(pepperEnv, target, type)
944 highstate(pepperEnv, target, type)
Jiri Broulikad606d02018-03-28 14:22:43 +0200945 verifyGalera(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100946 }
Jiri Broulik60dcab32018-03-08 17:42:06 +0100947 }
948 }
949
950 if (updates.contains("ntw")) {
951 def target = NTW_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200952 def type = 'ntw'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100953 if (salt.testTarget(pepperEnv, target)) {
954 backupContrail(pepperEnv)
955 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200956 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100957 }
958 if (PER_NODE.toBoolean()) {
959 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
960 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200961 updatePkgs(pepperEnv, t, type)
962 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100963 verifyContrail(pepperEnv, t)
964 }
965 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200966 updatePkgs(pepperEnv, target, type)
967 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100968 verifyContrail(pepperEnv, target)
969 }
970 }
971 }
972
973 if (updates.contains("nal")) {
974 def target = NAL_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200975 def type = 'nal'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100976 if (salt.testTarget(pepperEnv, target)) {
977 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200978 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100979 }
980 if (PER_NODE.toBoolean()) {
981 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
982 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200983 updatePkgs(pepperEnv, t, type)
984 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100985 }
986 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200987 updatePkgs(pepperEnv, target, type)
988 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +0100989 }
990 verifyContrail(pepperEnv, target)
991 }
992 }
993
994 if (updates.contains("gtw-virtual")) {
995 def target = GTW_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200996 def type = 'gtw-virtual'
Jiri Broulik60dcab32018-03-08 17:42:06 +0100997 if (salt.testTarget(pepperEnv, target)) {
998 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +0200999 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001000 }
1001 if (PER_NODE.toBoolean()) {
1002 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1003 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001004 updatePkgs(pepperEnv, t, type)
1005 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001006 }
1007 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001008 updatePkgs(pepperEnv, target, type)
1009 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001010 }
1011 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1012 }
1013 }
1014
1015 if (updates.contains("cmn")) {
1016 def target = CMN_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001017 def type = 'cmn'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001018 if (salt.testTarget(pepperEnv, target)) {
1019 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001020 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001021 } else {
Jiri Broulik906e9972018-03-26 16:12:00 +02001022 backupCeph(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001023 }
1024 if (PER_NODE.toBoolean()) {
1025 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1026 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001027 updatePkgs(pepperEnv, t, type)
1028 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001029 }
1030 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001031 updatePkgs(pepperEnv, target, type)
1032 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001033 }
1034 verifyCeph(pepperEnv, target, 'mon@')
1035 }
1036 }
1037
1038 if (updates.contains("rgw")) {
1039 def target = RGW_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001040 def type = 'rgw'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001041 if (salt.testTarget(pepperEnv, target)) {
1042 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001043 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001044 }
1045 if (PER_NODE.toBoolean()) {
1046 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1047 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001048 updatePkgs(pepperEnv, t, type)
1049 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001050 }
1051 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001052 updatePkgs(pepperEnv, target, type)
1053 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001054 }
1055 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1056 }
1057 }
1058
1059 if (updates.contains("log")) {
1060 def target = LOG_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001061 def type = 'log'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001062 if (salt.testTarget(pepperEnv, target)) {
1063 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001064 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001065 }
1066 if (PER_NODE.toBoolean()) {
1067 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1068 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001069 updatePkgs(pepperEnv, t, type)
1070 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001071 }
1072 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001073 updatePkgs(pepperEnv, target, type)
1074 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001075 }
1076 }
1077 }
1078
1079 if (updates.contains("mon")) {
1080 def target = MON_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001081 def type = 'mon'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001082 if (salt.testTarget(pepperEnv, target)) {
1083 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001084 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001085 }
1086 if (PER_NODE.toBoolean()) {
1087 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1088 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001089 updatePkgs(pepperEnv, t, type)
1090 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001091 }
1092 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001093 updatePkgs(pepperEnv, target, type)
1094 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001095 }
1096 }
1097 }
1098
1099 if (updates.contains("mtr")) {
1100 def target = MTR_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001101 def type = 'mtr'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001102 if (salt.testTarget(pepperEnv, target)) {
1103 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001104 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001105 }
1106 if (PER_NODE.toBoolean()) {
1107 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1108 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001109 updatePkgs(pepperEnv, t, type)
1110 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001111 }
1112 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001113 updatePkgs(pepperEnv, target, type)
1114 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001115 }
1116 }
1117 }
1118
1119 if (updates.contains("cid")) {
1120 def target = CID_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001121 def type = 'cid'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001122 if (salt.testTarget(pepperEnv, target)) {
1123 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001124 liveSnapshot(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001125 }
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001126 updatePkgs(pepperEnv, target, type)
1127 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001128 verifyService(pepperEnv, target, 'docker')
1129 }
1130 }
1131
1132 //
1133 //physical machines update CMP_TARGET
1134 //
1135 if (updates.contains("cmp")) {
1136 def target = CMP_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001137 def type = 'cmp'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001138 if (salt.testTarget(pepperEnv, target)) {
1139 if (PER_NODE.toBoolean()) {
1140 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1141 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001142 updatePkgs(pepperEnv, t, type)
1143 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001144 }
1145 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001146 updatePkgs(pepperEnv, target, type)
1147 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001148 }
1149 verifyService(pepperEnv, target, 'nova-compute')
1150 }
1151 }
1152
1153 if (updates.contains("kvm")) {
1154 def target = KVM_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001155 def type = 'kvm'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001156 if (salt.testTarget(pepperEnv, target)) {
1157 if (PER_NODE.toBoolean()) {
1158 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1159 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001160 updatePkgs(pepperEnv, t, type)
1161 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001162 }
1163 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001164 updatePkgs(pepperEnv, target, type)
1165 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001166 }
1167 verifyService(pepperEnv, target, 'libvirt-bin')
1168 }
1169 }
1170
1171 if (updates.contains("osd")) {
1172 def target = CEPH_OSD_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001173 def type = 'osd'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001174 if (salt.testTarget(pepperEnv, target)) {
1175 if (PER_NODE.toBoolean()) {
1176 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1177 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001178 updatePkgs(pepperEnv, t, type)
1179 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001180 }
1181 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001182 updatePkgs(pepperEnv, target, type)
1183 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001184 }
1185 verifyCephOsds(pepperEnv, target)
1186 }
1187 }
1188
1189 if (updates.contains("gtw-physical")) {
1190 def target = GTW_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001191 def type = 'gtw-physical'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001192 if (salt.testTarget(pepperEnv, target)) {
1193 if (PER_NODE.toBoolean()) {
1194 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1195 for (t in targetHosts) {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001196 updatePkgs(pepperEnv, t, type)
1197 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001198 }
1199 } else {
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001200 updatePkgs(pepperEnv, target, type)
1201 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001202 }
1203 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1204 }
1205 }
1206
1207 /*
1208 * Rollback section
1209 */
Jiri Broulik906e9972018-03-26 16:12:00 +02001210 /* if (rollbacks.contains("cfg")) {
Jiri Broulik60dcab32018-03-08 17:42:06 +01001211 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1212 stage('ROLLBACK_CFG') {
1213 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."
1214 //rollbackSaltMaster(pepperEnv, 'I@salt:master')
1215 //finishSaltMasterRollback(pepperEnv, 'I@salt:master')
1216 }
1217 }
1218 } */
1219
1220 if (rollbacks.contains("ctl")) {
1221 def target = CTL_TARGET
1222 if (salt.testTarget(pepperEnv, target)) {
1223 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1224 rollback(pepperEnv, target, 'ctl')
1225 verifyAPIs(pepperEnv, target)
1226 } else {
1227 removeNode(pepperEnv, target, 'ctl')
1228 }
1229 }
1230 }
1231
1232 if (rollbacks.contains("prx")) {
1233 def target = PRX_TARGET
1234 if (salt.testTarget(pepperEnv, target)) {
1235 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1236 rollback(pepperEnv, target, 'prx')
1237 verifyService(pepperEnv, target, 'nginx')
1238 } else {
1239 removeNode(pepperEnv, target, 'prx')
1240 }
1241 }
1242 }
1243
1244 if (rollbacks.contains("msg")) {
1245 def target = MSG_TARGET
1246 if (salt.testTarget(pepperEnv, target)) {
1247 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1248 rollback(pepperEnv, target, 'msg')
1249 salt.enforceState(pepperEnv, target, 'rabbitmq')
1250 verifyService(pepperEnv, target, 'rabbitmq-server')
1251 } else {
1252 removeNode(pepperEnv, target, 'msg')
1253 }
1254 }
1255 }
1256
1257 if (rollbacks.contains("dbs")) {
1258 def target = DBS_TARGET
1259 if (salt.testTarget(pepperEnv, target)) {
1260 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1261 rollback(pepperEnv, target, 'dbs')
1262 clusterGalera(pepperEnv)
Jiri Broulikad606d02018-03-28 14:22:43 +02001263 verifyGalera(pepperEnv, target)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001264 } else {
1265 removeNode(pepperEnv, target, 'dbs')
1266 }
1267 }
1268 }
1269
1270 if (rollbacks.contains("ntw")) {
1271 def target = NTW_TARGET
1272 if (salt.testTarget(pepperEnv, target)) {
1273 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1274 rollback(pepperEnv, target, 'ntw')
1275 verifyContrail(pepperEnv, target)
1276 } else {
1277 removeNode(pepperEnv, target, 'ntw')
1278 }
1279 }
1280 }
1281
1282 if (rollbacks.contains("nal")) {
1283 def target = NAL_TARGET
1284 if (salt.testTarget(pepperEnv, target)) {
1285 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1286 rollback(pepperEnv, target, 'nal')
1287 verifyContrail(pepperEnv, target)
1288 } else {
1289 removeNode(pepperEnv, target, 'nal')
1290 }
1291 }
1292 }
1293
1294 if (rollbacks.contains("gtw-virtual")) {
1295 def target = GTW_TARGET
1296 if (salt.testTarget(pepperEnv, target)) {
1297 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1298 rollback(pepperEnv, target, 'gtw')
1299 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1300 } else {
1301 removeNode(pepperEnv, target, 'gtw')
1302 }
1303 }
1304 }
1305
1306 if (rollbacks.contains("cmn")) {
1307 def target = CMN_TARGET
1308 if (salt.testTarget(pepperEnv, target)) {
1309 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1310 rollback(pepperEnv, target, 'cmn')
1311 verifyCeph(pepperEnv, target, 'mon@')
1312 } else {
1313 removeNode(pepperEnv, target, 'cmn')
1314 }
1315 }
1316 }
1317
1318 if (rollbacks.contains("rgw")) {
1319 def target = RGW_TARGET
1320 if (salt.testTarget(pepperEnv, target)) {
1321 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1322 rollback(pepperEnv, target, 'rgw')
1323 verifyCeph(pepperEnv, target, 'radosgw@rgw.')
1324 } else {
1325 removeNode(pepperEnv, target, 'rgw')
1326 }
1327 }
1328 }
1329
1330 if (rollbacks.contains("log")) {
1331 def target = LOG_TARGET
1332 if (salt.testTarget(pepperEnv, target)) {
1333 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1334 rollback(pepperEnv, target, 'log')
1335 } else {
1336 removeNode(pepperEnv, target, 'log')
1337 }
1338 }
1339 }
1340
1341 if (rollbacks.contains("mon")) {
1342 def target = MON_TARGET
1343 if (salt.testTarget(pepperEnv, target)) {
1344 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1345 rollback(pepperEnv, target, 'mon')
1346 } else {
1347 removeNode(pepperEnv, target, 'mon')
1348 }
1349 }
1350 }
1351
1352 if (rollbacks.contains("mtr")) {
1353 def target = MTR_TARGET
1354 if (salt.testTarget(pepperEnv, target)) {
1355 if (!ROLLBACK_BY_REDEPLOY.toBoolean()) {
1356 rollback(pepperEnv, target, 'mtr')
1357 } else {
1358 removeNode(pepperEnv, target, 'mtr')
1359 }
1360 }
1361 }
1362 /*
1363 if (ROLLBACK_CID.toBoolean()) {
1364 def target = 'cid*'
1365 if (salt.testTarget(pepperEnv, target)) {
1366 stage('ROLLBACK_CID') {
1367 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."
1368 }
1369 }
1370 } */
1371
1372 //
1373 //physical machines rollback CMP_TARGET
1374 //
1375 if (rollbacks.contains("cmp")) {
1376 def target = CMP_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001377 def type = 'cmp'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001378 if (salt.testTarget(pepperEnv, target)) {
1379 if (PER_NODE.toBoolean()) {
1380 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1381 for (t in targetHosts) {
1382 rollbackPkgs(pepperEnv, t)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001383 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001384 }
1385 } else {
1386 rollbackPkgs(pepperEnv, target, target)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001387 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001388 }
1389 verifyService(pepperEnv, target, 'nova-compute')
1390 }
1391 }
1392
1393 if (rollbacks.contains("kvm")) {
1394 def target = KVM_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001395 def type = 'kvm'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001396 if (salt.testTarget(pepperEnv, target)) {
1397 if (PER_NODE.toBoolean()) {
1398 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1399 for (t in targetHosts) {
1400 rollbackPkgs(pepperEnv, t)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001401 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001402 }
1403 } else {
1404 rollbackPkgs(pepperEnv, target, target)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001405 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001406 }
1407 verifyService(pepperEnv, target, 'libvirt-bin')
1408 }
1409 }
1410
1411 if (rollbacks.contains("osd")) {
1412 def target = CEPH_OSD_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001413 def type = 'osd'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001414 if (salt.testTarget(pepperEnv, target)) {
1415 if (PER_NODE.toBoolean()) {
1416 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1417 for (t in targetHosts) {
1418 rollbackPkgs(pepperEnv, t)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001419 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001420 }
1421 } else {
1422 rollbackPkgs(pepperEnv, target, target)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001423 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001424 }
1425 verifyCephOsds(pepperEnv, target)
1426 }
1427 }
1428
1429 if (rollbacks.contains("gtw-physical")) {
1430 def target = GTW_TARGET
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001431 def type = 'gtw-physical'
Jiri Broulik60dcab32018-03-08 17:42:06 +01001432 if (salt.testTarget(pepperEnv, target)) {
1433 if (PER_NODE.toBoolean()) {
1434 def targetHosts = salt.getMinionsSorted(pepperEnv, target)
1435 for (t in targetHosts) {
1436 rollbackPkgs(pepperEnv, t)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001437 highstate(pepperEnv, t, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001438 }
1439 } else {
1440 rollbackPkgs(pepperEnv, target, target)
Jiri Broulikba6d85d2018-04-05 13:29:07 +02001441 highstate(pepperEnv, target, type)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001442 }
1443 verifyService(pepperEnv, target, 'neutron-dhcp-agent')
1444 }
1445 }
1446
1447 /*
1448 * Merge snapshots section
1449 */
1450 if (merges.contains("cfg")) {
1451 if (salt.testTarget(pepperEnv, 'I@salt:master')) {
1452 mergeSnapshot(pepperEnv, 'I@salt:master')
1453 }
1454 }
1455
1456 if (merges.contains("ctl")) {
1457 if (salt.testTarget(pepperEnv, CTL_TARGET)) {
1458 mergeSnapshot(pepperEnv, CTL_TARGET, 'ctl')
Jiri Broulik906e9972018-03-26 16:12:00 +02001459 verifyService(pepperEnv, CTL_TARGET, 'nova-api')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001460 }
1461 }
1462
1463 if (merges.contains("prx")) {
1464 if (salt.testTarget(pepperEnv, PRX_TARGET)) {
1465 mergeSnapshot(pepperEnv, PRX_TARGET, 'prx')
Jiri Broulik906e9972018-03-26 16:12:00 +02001466 verifyService(pepperEnv, PRX_TARGET, 'nginx')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001467 }
1468 }
1469
1470 if (merges.contains("msg")) {
1471 if (salt.testTarget(pepperEnv, MSG_TARGET)) {
1472 mergeSnapshot(pepperEnv, MSG_TARGET, 'msg')
Jiri Broulik906e9972018-03-26 16:12:00 +02001473 verifyService(pepperEnv, MSG_TARGET, 'rabbitmq-server')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001474 }
1475 }
1476
1477 if (merges.contains("dbs")) {
1478 if (salt.testTarget(pepperEnv, DBS_TARGET)) {
1479 mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs')
Jiri Broulikad606d02018-03-28 14:22:43 +02001480 verifyGalera(pepperEnv, DBS_TARGET)
Jiri Broulik906e9972018-03-26 16:12:00 +02001481 backupGalera(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001482 }
1483 }
1484
1485 if (merges.contains("ntw")) {
1486 if (salt.testTarget(pepperEnv, NTW_TARGET)) {
1487 mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001488 verifyContrail(pepperEnv, NTW_TARGET)
1489 backupContrail(pepperEnv)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001490 }
1491 }
1492
1493 if (merges.contains("nal")) {
1494 if (salt.testTarget(pepperEnv, NAL_TARGET)) {
1495 mergeSnapshot(pepperEnv, NAL_TARGET, 'nal')
Jiri Broulik906e9972018-03-26 16:12:00 +02001496 verifyContrail(pepperEnv, NAL_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001497 }
1498 }
1499
1500 if (merges.contains("gtw-virtual")) {
1501 if (salt.testTarget(pepperEnv, GTW_TARGET)) {
1502 mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001503 verifyService(pepperEnv, GTW_TARGET, 'neutron-dhcp-agent')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001504 }
1505 }
1506
1507 if (merges.contains("cmn")) {
1508 if (salt.testTarget(pepperEnv, CMN_TARGET)) {
1509 mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn')
Jiri Broulik906e9972018-03-26 16:12:00 +02001510 verifyCeph(pepperEnv, CMN_TARGET, 'mon@')
1511 backupCeph(pepperEnv, CMN_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001512 }
1513 }
1514
1515 if (merges.contains("rgw")) {
1516 if (salt.testTarget(pepperEnv, RGW_TARGET)) {
1517 mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw')
Jiri Broulik906e9972018-03-26 16:12:00 +02001518 verifyCeph(pepperEnv, RGW_TARGET, 'radosgw@rgw.')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001519 }
1520 }
1521
1522 if (merges.contains("log")) {
1523 if (salt.testTarget(pepperEnv, LOG_TARGET)) {
1524 mergeSnapshot(pepperEnv, LOG_TARGET. 'log')
1525 }
1526 }
1527
1528 if (merges.contains("mon")) {
1529 if (salt.testTarget(pepperEnv, MON_TARGET)) {
1530 mergeSnapshot(pepperEnv, MON_TARGET, 'mon')
1531 }
1532 }
1533
1534 if (merges.contains("mtr")) {
1535 if (salt.testTarget(pepperEnv, MTR_TARGET)) {
1536 mergeSnapshot(pepperEnv, MTR_TARGET, 'mtr')
1537 }
1538 }
1539
1540 if (merges.contains("cid")) {
1541 if (salt.testTarget(pepperEnv, CID_TARGET)) {
1542 mergeSnapshot(pepperEnv, CID_TARGET, 'cid')
Jiri Broulik906e9972018-03-26 16:12:00 +02001543 verifyService(pepperEnv, CID_TARGET, 'docker')
Jiri Broulik60dcab32018-03-08 17:42:06 +01001544 }
1545 }
1546
1547 if (RESTORE_GALERA.toBoolean()) {
1548 restoreGalera(pepperEnv)
Jiri Broulikad606d02018-03-28 14:22:43 +02001549 verifyGalera(pepperEnv, DBS_TARGET)
Jiri Broulik60dcab32018-03-08 17:42:06 +01001550 }
1551
1552 if (RESTORE_CONTRAIL_DB.toBoolean()) {
1553 restoreContrailDb(pepperEnv)
Jiri Broulik906e9972018-03-26 16:12:00 +02001554 // verification is already present in restore pipelines
Jiri Broulik60dcab32018-03-08 17:42:06 +01001555 }
1556
1557 } catch (Throwable e) {
1558 // If there was an error or exception thrown, the build failed
1559 currentBuild.result = "FAILURE"
1560 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
1561 throw e
1562 }
1563 }
1564}