Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1 | /** |
| 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 13 | * 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 16 | * 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 Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 17 | * 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 Broulik | 5dac8d8 | 2018-03-29 13:34:39 +0200 | [diff] [blame] | 18 | * 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 19 | * 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 Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 34 | * GTW_TARGET Salt targeted physical or virtual GTW nodes (ex. gtw01*) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 35 | * 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 38 | * RESTORE_GALERA Restore Galera DB (bool) |
| 39 | * RESTORE_CONTRAIL_DB Restore Cassandra and Zookeeper DBs for OpenContrail (bool) |
| 40 | * |
| 41 | **/ |
| 42 | def common = new com.mirantis.mk.Common() |
| 43 | def salt = new com.mirantis.mk.Salt() |
| 44 | def python = new com.mirantis.mk.Python() |
| 45 | def virsh = new com.mirantis.mk.Virsh() |
| 46 | |
| 47 | def updates = TARGET_UPDATES.tokenize(",").collect{it -> it.trim()} |
| 48 | def rollbacks = TARGET_ROLLBACKS.tokenize(",").collect{it -> it.trim()} |
Jiri Broulik | 5dac8d8 | 2018-03-29 13:34:39 +0200 | [diff] [blame] | 49 | def merges = TARGET_SNAPSHOT_MERGES.tokenize(",").collect{it -> it.trim()} |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 50 | def reboots = TARGET_REBOOT.tokenize(",").collect{it -> it.trim()} |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 51 | |
| 52 | def pepperEnv = "pepperEnv" |
| 53 | def minions |
| 54 | def result |
| 55 | def packages |
| 56 | def command |
| 57 | def commandKwargs |
| 58 | |
| 59 | def updatePkgs(pepperEnv, target, targetType="", targetPackages="") { |
| 60 | def salt = new com.mirantis.mk.Salt() |
| 61 | def common = new com.mirantis.mk.Common() |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 62 | def kernelUpdates = TARGET_KERNEL_UPDATES.tokenize(",").collect{it -> it.trim()} |
| 63 | def distUpgrade = false |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 64 | def commandKwargs |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 65 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 72 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 77 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 102 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 119 | } |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 120 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 124 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 125 | // 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 132 | if (kernelUpdates.contains(targetType)) { |
| 133 | commandKwargs = ['dist_upgrade': 'true'] |
| 134 | distUpgrade = true |
| 135 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 136 | packages = null |
| 137 | } |
| 138 | |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 139 | stage("stop services on ${target}") { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 140 | if ((STOP_SERVICES.toBoolean()) && (targetType != 'cid')) { |
| 141 | if (targetType == 'ntw' || targetType == 'nal') { |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 142 | contrailServices(pepperEnv, target, 'stop') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 143 | } else { |
| 144 | def probe = salt.getFirstMinion(pepperEnv, "${target}") |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 145 | services(pepperEnv, probe, target, 'stop') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | stage('Apply package upgrades') { |
| 151 | // salt master pkg |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 152 | if (targetType == 'cfg') { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 153 | 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 | |
| 210 | def 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 Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 272 | services(pepperEnv, probe, target, 'stop') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 273 | } |
| 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 Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 355 | def getNodeProvider(pepperEnv, nodeName, type='') { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 356 | def salt = new com.mirantis.mk.Salt() |
| 357 | def common = new com.mirantis.mk.Common() |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 358 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 364 | CFG_NODE_PROVIDER = kvm |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 365 | } else { |
| 366 | return kvm |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 367 | //break |
| 368 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 369 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 370 | } catch (Exception er) { |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 371 | common.infoMsg("${nodeName} not present on ${kvm}") |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 372 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 376 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 381 | } else { |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 382 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 397 | // must be treated separately due to OC on Trusty |
| 398 | def contrailServices(pepperEnv, target, action='stop') { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 399 | def salt = new com.mirantis.mk.Salt() |
| 400 | def common = new com.mirantis.mk.Common() |
| 401 | def services = [] |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 402 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 419 | for (s in services) { |
| 420 | try { |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 421 | salt.runSaltProcessStep(pepperEnv, target, "service.${action}", [s], null, true) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 422 | } catch (Exception er) { |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 423 | common.warningMsg(er) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
Jiri Broulik | 059d2df | 2018-06-15 14:03:34 +0200 | [diff] [blame] | 428 | def 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 444 | def highstate(pepperEnv, target, type) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 445 | def salt = new com.mirantis.mk.Salt() |
| 446 | def common = new com.mirantis.mk.Common() |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 447 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 463 | } |
| 464 | } |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 465 | } 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 472 | } |
| 473 | // optionally reboot |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 474 | if (reboots.contains(type)) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 475 | stage("Reboot ${target} nodes") { |
Jiri Broulik | 059d2df | 2018-06-15 14:03:34 +0200 | [diff] [blame] | 476 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | def 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 | |
| 513 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 520 | for (t in target_hosts) { |
| 521 | def target = salt.stripDomainName(t) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 522 | def nodeProvider = getNodeProvider(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 523 | virsh.liveSnapshotPresent(pepperEnv, nodeProvider, target, SNAPSHOT_NAME) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
| 527 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 532 | for (t in target_hosts) { |
| 533 | if (tgt == 'I@salt:master') { |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 534 | def master = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname')) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 535 | getNodeProvider(pepperEnv, master, 'master') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 536 | virsh.liveSnapshotMerge(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME) |
| 537 | } else { |
| 538 | def target = salt.stripDomainName(t) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 539 | def nodeProvider = getNodeProvider(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 540 | virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, SNAPSHOT_NAME) |
| 541 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 542 | } |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 543 | salt.minionsReachable(pepperEnv, 'I@salt:master', tgt) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | |
| 548 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 555 | for (t in target_hosts) { |
| 556 | def target = salt.stripDomainName(t) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 557 | def nodeProvider = getNodeProvider(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 558 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 559 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 560 | // rollback vms |
| 561 | for (t in target_hosts) { |
| 562 | def target = salt.stripDomainName(t) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 563 | def nodeProvider = getNodeProvider(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 564 | virsh.liveSnapshotRollback(pepperEnv, nodeProvider, target, SNAPSHOT_NAME) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 565 | } |
| 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 | |
| 580 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 587 | for (t in target_hosts) { |
| 588 | def target = salt.stripDomainName(t) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 589 | def nodeProvider = getNodeProvider(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 590 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.destroy', ["${target}.${domain}"], null, true) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 591 | //salt.runSaltProcessStep(pepperEnv, "${nodeProvider}*", 'virt.undefine', ["${target}.${domain}"], null, true) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 592 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 600 | def 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 606 | def 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 | |
| 613 | def 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 |
| 622 | def 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 | |
| 655 | def 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 | |
| 663 | def 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 | |
| 675 | def 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 | |
| 688 | def backupContrail(pepperEnv) { |
| 689 | backupZookeeper(pepperEnv) |
| 690 | backupCassandra(pepperEnv) |
| 691 | } |
| 692 | |
| 693 | // cassandra and zookeeper |
| 694 | def 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 Broulik | d2dd563 | 2018-03-27 15:44:56 +0200 | [diff] [blame] | 707 | def verifyAPIs(pepperEnv, target) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 708 | def salt = new com.mirantis.mk.Salt() |
| 709 | def common = new com.mirantis.mk.Common() |
William Konitzer | b147e84 | 2018-06-15 15:03:40 -0500 | [diff] [blame] | 710 | def cmds = ["openstack service list", |
| 711 | "openstack image list", |
| 712 | "openstack flavor list", |
| 713 | "openstack compute service list", |
| 714 | "openstack server list", |
| 715 | "openstack network list", |
| 716 | "openstack volume list", |
| 717 | "openstack orchestration service list"] |
| 718 | def sourcerc = ". /root/keystonercv3;" |
| 719 | def cmdOut = ">/dev/null 2>&1;echo \$?" |
| 720 | for (c in cmds) { |
| 721 | def command = sourcerc + c + cmdOut |
| 722 | def out = salt.cmdRun(pepperEnv, target, "${command}") |
| 723 | if (!out.toString().toLowerCase().contains('0')) { |
| 724 | common.errorMsg(out) |
| 725 | if (INTERACTIVE.toBoolean()) { |
| 726 | input message: "APIs are not working as expected. Please fix it manually." |
| 727 | } else { |
| 728 | throw new Exception("APIs are not working as expected") |
| 729 | } |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 730 | } |
| 731 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 734 | def verifyGalera(pepperEnv, target, count=0, maxRetries=200) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 735 | def salt = new com.mirantis.mk.Salt() |
| 736 | def common = new com.mirantis.mk.Common() |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 737 | def out |
| 738 | while(count < maxRetries) { |
| 739 | try { |
William Konitzer | 667143f | 2018-06-15 14:21:17 -0500 | [diff] [blame] | 740 | out = salt.getReturnValues(salt.cmdRun(pepperEnv, target, 'salt-call -l quiet mysql.status | grep -A1 wsrep_cluster_size')) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 741 | } catch (Exception er) { |
| 742 | common.infoMsg(er) |
| 743 | } |
| 744 | if ((!out.toString().contains('wsrep_cluster_size')) || (out.toString().contains('0'))) { |
| 745 | count++ |
| 746 | if (count == maxRetries) { |
| 747 | if (INTERACTIVE.toBoolean()) { |
| 748 | input message: "Galera is not working as expected. Please check it and fix it first before clicking on PROCEED." |
| 749 | } else { |
| 750 | common.errorMsg(out) |
| 751 | throw new Exception("Galera is not working as expected") |
| 752 | } |
| 753 | } |
| 754 | sleep(time: 500, unit: 'MILLISECONDS') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 755 | } else { |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 756 | break |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | def verifyContrail(pepperEnv, target) { |
| 762 | def salt = new com.mirantis.mk.Salt() |
| 763 | def common = new com.mirantis.mk.Common() |
| 764 | salt.commandStatus(pepperEnv, target, "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
| 765 | } |
| 766 | |
| 767 | |
| 768 | def verifyService(pepperEnv, target, service) { |
| 769 | def salt = new com.mirantis.mk.Salt() |
| 770 | def common = new com.mirantis.mk.Common() |
| 771 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 772 | for (t in targetHosts) { |
| 773 | try { |
| 774 | salt.commandStatus(pepperEnv, t, "service ${service} status", 'running') |
| 775 | } catch (Exception er) { |
| 776 | common.errorMsg(er) |
| 777 | if (INTERACTIVE.toBoolean()) { |
| 778 | input message: "${service} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED." |
| 779 | } else { |
| 780 | throw new Exception("${service} service is not running correctly on ${t}") |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | def verifyCeph(pepperEnv, target, type) { |
| 787 | def salt = new com.mirantis.mk.Salt() |
| 788 | def common = new com.mirantis.mk.Common() |
| 789 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 790 | for (t in targetHosts) { |
| 791 | def hostname = salt.getReturnValues(salt.getPillar(pepperEnv, t, 'linux:network:hostname')) |
| 792 | try { |
| 793 | salt.commandStatus(pepperEnv, t, "systemctl status ceph-${type}${hostname}", 'running') |
| 794 | } catch (Exception er) { |
| 795 | common.errorMsg(er) |
| 796 | if (INTERACTIVE.toBoolean()) { |
| 797 | input message: "Ceph-${type}${hostname} service is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED." |
| 798 | } else { |
| 799 | throw new Exception("Ceph-${type}${hostname} service is not running correctly on ${t}") |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | def verifyCephOsds(pepperEnv, target) { |
| 806 | def salt = new com.mirantis.mk.Salt() |
| 807 | def common = new com.mirantis.mk.Common() |
| 808 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 809 | for (t in targetHosts) { |
| 810 | def osd_ids = [] |
| 811 | // get list of osd disks of the host |
| 812 | salt.runSaltProcessStep(pepperEnv, t, 'saltutil.sync_grains', [], null, true, 5) |
| 813 | def cephGrain = salt.getGrain(pepperEnv, t, 'ceph') |
| 814 | if(cephGrain['return'].isEmpty()){ |
| 815 | throw new Exception("Ceph salt grain cannot be found!") |
| 816 | } |
| 817 | common.print(cephGrain) |
| 818 | def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk'] |
| 819 | for (i in ceph_disks) { |
| 820 | def osd_id = i.getKey().toString() |
| 821 | osd_ids.add('osd.' + osd_id) |
| 822 | print("Will check osd." + osd_id) |
| 823 | } |
| 824 | for (i in osd_ids) { |
| 825 | try { |
| 826 | salt.commandStatus(pepperEnv, t, "ceph osd tree | grep -w ${i}", 'up') |
| 827 | } catch (Exception er) { |
| 828 | common.errorMsg(er) |
| 829 | if (INTERACTIVE.toBoolean()) { |
| 830 | input message: "Ceph ${i} is not running correctly on ${t}. Please fix it first manually and only then click on PROCEED." |
| 831 | } else { |
| 832 | throw new Exception("Ceph ${i} is not running correctly on ${t}") |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
| 840 | timeout(time: 12, unit: 'HOURS') { |
| 841 | node() { |
| 842 | try { |
| 843 | |
| 844 | stage('Setup virtualenv for Pepper') { |
| 845 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 846 | } |
| 847 | |
| 848 | // TODO, add possibility to update just specific components like kernel, openstack, contrail, ovs, rabbitmq, galera, etc. |
| 849 | |
| 850 | /* |
| 851 | * Update section |
| 852 | */ |
| 853 | if (updates.contains("cfg")) { |
| 854 | def target = 'I@salt:master' |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 855 | def type = 'cfg' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 856 | if (salt.testTarget(pepperEnv, target)) { |
| 857 | def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname')) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 858 | getNodeProvider(pepperEnv, master, 'master') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 859 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 860 | virsh.liveSnapshotPresent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 861 | } else { |
| 862 | saltMasterBackup(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 863 | } |
| 864 | if (PER_NODE.toBoolean()) { |
| 865 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 866 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 867 | updatePkgs(pepperEnv, t, type) |
| 868 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 869 | } |
| 870 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 871 | updatePkgs(pepperEnv, target, type) |
| 872 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | if (updates.contains("ctl")) { |
| 878 | def target = CTL_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 879 | def type = 'ctl' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 880 | if (salt.testTarget(pepperEnv, target)) { |
| 881 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 882 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 883 | } |
| 884 | if (PER_NODE.toBoolean()) { |
| 885 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 886 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 887 | updatePkgs(pepperEnv, t, type) |
| 888 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 889 | } |
| 890 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 891 | updatePkgs(pepperEnv, target, type) |
| 892 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 893 | } |
| 894 | verifyAPIs(pepperEnv, target) |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | if (updates.contains("prx")) { |
| 899 | def target = PRX_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 900 | def type = 'prx' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 901 | if (salt.testTarget(pepperEnv, target)) { |
| 902 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 903 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 904 | } |
| 905 | if (PER_NODE.toBoolean()) { |
| 906 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 907 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 908 | updatePkgs(pepperEnv, t, type) |
| 909 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 910 | } |
| 911 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 912 | updatePkgs(pepperEnv, target, type) |
| 913 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 914 | } |
| 915 | verifyService(pepperEnv, target, 'nginx') |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (updates.contains("msg")) { |
| 920 | def target = MSG_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 921 | def type = 'msg' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 922 | if (salt.testTarget(pepperEnv, target)) { |
| 923 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 924 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 925 | } |
| 926 | if (PER_NODE.toBoolean()) { |
| 927 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 928 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 929 | updatePkgs(pepperEnv, t, type) |
| 930 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 931 | } |
| 932 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 933 | updatePkgs(pepperEnv, target, type) |
| 934 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 935 | } |
| 936 | verifyService(pepperEnv, target, 'rabbitmq-server') |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | if (updates.contains("dbs")) { |
| 941 | def target = DBS_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 942 | def type = 'dbs' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 943 | if (salt.testTarget(pepperEnv, target)) { |
| 944 | backupGalera(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 945 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 946 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 947 | } |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 948 | if (reboots.contains(type) || PER_NODE.toBoolean()) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 949 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 950 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 951 | updatePkgs(pepperEnv, t, type) |
| 952 | highstate(pepperEnv, t, type) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 953 | verifyGalera(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 954 | } |
| 955 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 956 | updatePkgs(pepperEnv, target, type) |
| 957 | highstate(pepperEnv, target, type) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 958 | verifyGalera(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 959 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | |
| 963 | if (updates.contains("ntw")) { |
| 964 | def target = NTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 965 | def type = 'ntw' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 966 | if (salt.testTarget(pepperEnv, target)) { |
| 967 | backupContrail(pepperEnv) |
| 968 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 969 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 970 | } |
| 971 | if (PER_NODE.toBoolean()) { |
| 972 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 973 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 974 | updatePkgs(pepperEnv, t, type) |
| 975 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 976 | verifyContrail(pepperEnv, t) |
| 977 | } |
| 978 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 979 | updatePkgs(pepperEnv, target, type) |
| 980 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 981 | verifyContrail(pepperEnv, target) |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | if (updates.contains("nal")) { |
| 987 | def target = NAL_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 988 | def type = 'nal' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 989 | if (salt.testTarget(pepperEnv, target)) { |
| 990 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 991 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 992 | } |
| 993 | if (PER_NODE.toBoolean()) { |
| 994 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 995 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 996 | updatePkgs(pepperEnv, t, type) |
| 997 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 998 | } |
| 999 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1000 | updatePkgs(pepperEnv, target, type) |
| 1001 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1002 | } |
| 1003 | verifyContrail(pepperEnv, target) |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | if (updates.contains("gtw-virtual")) { |
| 1008 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1009 | def type = 'gtw-virtual' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1010 | if (salt.testTarget(pepperEnv, target)) { |
| 1011 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1012 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1013 | } |
| 1014 | if (PER_NODE.toBoolean()) { |
| 1015 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1016 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1017 | updatePkgs(pepperEnv, t, type) |
| 1018 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1019 | } |
| 1020 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1021 | updatePkgs(pepperEnv, target, type) |
| 1022 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1023 | } |
| 1024 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | if (updates.contains("cmn")) { |
| 1029 | def target = CMN_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1030 | def type = 'cmn' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1031 | if (salt.testTarget(pepperEnv, target)) { |
| 1032 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1033 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1034 | } else { |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1035 | backupCeph(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1036 | } |
| 1037 | if (PER_NODE.toBoolean()) { |
| 1038 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1039 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1040 | updatePkgs(pepperEnv, t, type) |
| 1041 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1042 | } |
| 1043 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1044 | updatePkgs(pepperEnv, target, type) |
| 1045 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1046 | } |
| 1047 | verifyCeph(pepperEnv, target, 'mon@') |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | if (updates.contains("rgw")) { |
| 1052 | def target = RGW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1053 | def type = 'rgw' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1054 | if (salt.testTarget(pepperEnv, target)) { |
| 1055 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1056 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1057 | } |
| 1058 | if (PER_NODE.toBoolean()) { |
| 1059 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1060 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1061 | updatePkgs(pepperEnv, t, type) |
| 1062 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1063 | } |
| 1064 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1065 | updatePkgs(pepperEnv, target, type) |
| 1066 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1067 | } |
| 1068 | verifyCeph(pepperEnv, target, 'radosgw@rgw.') |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | if (updates.contains("log")) { |
| 1073 | def target = LOG_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1074 | def type = 'log' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1075 | if (salt.testTarget(pepperEnv, target)) { |
| 1076 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1077 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1078 | } |
| 1079 | if (PER_NODE.toBoolean()) { |
| 1080 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1081 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1082 | updatePkgs(pepperEnv, t, type) |
| 1083 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1084 | } |
| 1085 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1086 | updatePkgs(pepperEnv, target, type) |
| 1087 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | if (updates.contains("mon")) { |
| 1093 | def target = MON_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1094 | def type = 'mon' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1095 | if (salt.testTarget(pepperEnv, target)) { |
| 1096 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1097 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1098 | } |
| 1099 | if (PER_NODE.toBoolean()) { |
| 1100 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1101 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1102 | updatePkgs(pepperEnv, t, type) |
| 1103 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1104 | } |
| 1105 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1106 | updatePkgs(pepperEnv, target, type) |
| 1107 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | if (updates.contains("mtr")) { |
| 1113 | def target = MTR_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1114 | def type = 'mtr' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1115 | if (salt.testTarget(pepperEnv, target)) { |
| 1116 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1117 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1118 | } |
| 1119 | if (PER_NODE.toBoolean()) { |
| 1120 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1121 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1122 | updatePkgs(pepperEnv, t, type) |
| 1123 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1124 | } |
| 1125 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1126 | updatePkgs(pepperEnv, target, type) |
| 1127 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | if (updates.contains("cid")) { |
| 1133 | def target = CID_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1134 | def type = 'cid' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1135 | if (salt.testTarget(pepperEnv, target)) { |
| 1136 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1137 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1138 | } |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1139 | updatePkgs(pepperEnv, target, type) |
| 1140 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1141 | verifyService(pepperEnv, target, 'docker') |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | // |
| 1146 | //physical machines update CMP_TARGET |
| 1147 | // |
| 1148 | if (updates.contains("cmp")) { |
| 1149 | def target = CMP_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1150 | def type = 'cmp' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1151 | if (salt.testTarget(pepperEnv, target)) { |
| 1152 | if (PER_NODE.toBoolean()) { |
| 1153 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1154 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1155 | updatePkgs(pepperEnv, t, type) |
| 1156 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1157 | } |
| 1158 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1159 | updatePkgs(pepperEnv, target, type) |
| 1160 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1161 | } |
| 1162 | verifyService(pepperEnv, target, 'nova-compute') |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | if (updates.contains("kvm")) { |
| 1167 | def target = KVM_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1168 | def type = 'kvm' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1169 | if (salt.testTarget(pepperEnv, target)) { |
| 1170 | if (PER_NODE.toBoolean()) { |
| 1171 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1172 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1173 | updatePkgs(pepperEnv, t, type) |
| 1174 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1175 | } |
| 1176 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1177 | updatePkgs(pepperEnv, target, type) |
| 1178 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1179 | } |
| 1180 | verifyService(pepperEnv, target, 'libvirt-bin') |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | if (updates.contains("osd")) { |
| 1185 | def target = CEPH_OSD_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1186 | def type = 'osd' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1187 | if (salt.testTarget(pepperEnv, target)) { |
| 1188 | if (PER_NODE.toBoolean()) { |
| 1189 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1190 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1191 | updatePkgs(pepperEnv, t, type) |
| 1192 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1193 | } |
| 1194 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1195 | updatePkgs(pepperEnv, target, type) |
| 1196 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1197 | } |
| 1198 | verifyCephOsds(pepperEnv, target) |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (updates.contains("gtw-physical")) { |
| 1203 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1204 | def type = 'gtw-physical' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1205 | if (salt.testTarget(pepperEnv, target)) { |
| 1206 | if (PER_NODE.toBoolean()) { |
| 1207 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1208 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1209 | updatePkgs(pepperEnv, t, type) |
| 1210 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1211 | } |
| 1212 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1213 | updatePkgs(pepperEnv, target, type) |
| 1214 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1215 | } |
| 1216 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | /* |
| 1221 | * Rollback section |
| 1222 | */ |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1223 | /* if (rollbacks.contains("cfg")) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1224 | if (salt.testTarget(pepperEnv, 'I@salt:master')) { |
| 1225 | stage('ROLLBACK_CFG') { |
| 1226 | 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." |
| 1227 | //rollbackSaltMaster(pepperEnv, 'I@salt:master') |
| 1228 | //finishSaltMasterRollback(pepperEnv, 'I@salt:master') |
| 1229 | } |
| 1230 | } |
| 1231 | } */ |
| 1232 | |
| 1233 | if (rollbacks.contains("ctl")) { |
| 1234 | def target = CTL_TARGET |
| 1235 | if (salt.testTarget(pepperEnv, target)) { |
| 1236 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1237 | rollback(pepperEnv, target, 'ctl') |
| 1238 | verifyAPIs(pepperEnv, target) |
| 1239 | } else { |
| 1240 | removeNode(pepperEnv, target, 'ctl') |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if (rollbacks.contains("prx")) { |
| 1246 | def target = PRX_TARGET |
| 1247 | if (salt.testTarget(pepperEnv, target)) { |
| 1248 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1249 | rollback(pepperEnv, target, 'prx') |
| 1250 | verifyService(pepperEnv, target, 'nginx') |
| 1251 | } else { |
| 1252 | removeNode(pepperEnv, target, 'prx') |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | if (rollbacks.contains("msg")) { |
| 1258 | def target = MSG_TARGET |
| 1259 | if (salt.testTarget(pepperEnv, target)) { |
| 1260 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1261 | rollback(pepperEnv, target, 'msg') |
| 1262 | salt.enforceState(pepperEnv, target, 'rabbitmq') |
| 1263 | verifyService(pepperEnv, target, 'rabbitmq-server') |
| 1264 | } else { |
| 1265 | removeNode(pepperEnv, target, 'msg') |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | if (rollbacks.contains("dbs")) { |
| 1271 | def target = DBS_TARGET |
| 1272 | if (salt.testTarget(pepperEnv, target)) { |
| 1273 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1274 | rollback(pepperEnv, target, 'dbs') |
| 1275 | clusterGalera(pepperEnv) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1276 | verifyGalera(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1277 | } else { |
| 1278 | removeNode(pepperEnv, target, 'dbs') |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | if (rollbacks.contains("ntw")) { |
| 1284 | def target = NTW_TARGET |
| 1285 | if (salt.testTarget(pepperEnv, target)) { |
| 1286 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1287 | rollback(pepperEnv, target, 'ntw') |
| 1288 | verifyContrail(pepperEnv, target) |
| 1289 | } else { |
| 1290 | removeNode(pepperEnv, target, 'ntw') |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if (rollbacks.contains("nal")) { |
| 1296 | def target = NAL_TARGET |
| 1297 | if (salt.testTarget(pepperEnv, target)) { |
| 1298 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1299 | rollback(pepperEnv, target, 'nal') |
| 1300 | verifyContrail(pepperEnv, target) |
| 1301 | } else { |
| 1302 | removeNode(pepperEnv, target, 'nal') |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | if (rollbacks.contains("gtw-virtual")) { |
| 1308 | def target = GTW_TARGET |
| 1309 | if (salt.testTarget(pepperEnv, target)) { |
| 1310 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1311 | rollback(pepperEnv, target, 'gtw') |
| 1312 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1313 | } else { |
| 1314 | removeNode(pepperEnv, target, 'gtw') |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | if (rollbacks.contains("cmn")) { |
| 1320 | def target = CMN_TARGET |
| 1321 | if (salt.testTarget(pepperEnv, target)) { |
| 1322 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1323 | rollback(pepperEnv, target, 'cmn') |
| 1324 | verifyCeph(pepperEnv, target, 'mon@') |
| 1325 | } else { |
| 1326 | removeNode(pepperEnv, target, 'cmn') |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | if (rollbacks.contains("rgw")) { |
| 1332 | def target = RGW_TARGET |
| 1333 | if (salt.testTarget(pepperEnv, target)) { |
| 1334 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1335 | rollback(pepperEnv, target, 'rgw') |
| 1336 | verifyCeph(pepperEnv, target, 'radosgw@rgw.') |
| 1337 | } else { |
| 1338 | removeNode(pepperEnv, target, 'rgw') |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | if (rollbacks.contains("log")) { |
| 1344 | def target = LOG_TARGET |
| 1345 | if (salt.testTarget(pepperEnv, target)) { |
| 1346 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1347 | rollback(pepperEnv, target, 'log') |
| 1348 | } else { |
| 1349 | removeNode(pepperEnv, target, 'log') |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | if (rollbacks.contains("mon")) { |
| 1355 | def target = MON_TARGET |
| 1356 | if (salt.testTarget(pepperEnv, target)) { |
| 1357 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1358 | rollback(pepperEnv, target, 'mon') |
| 1359 | } else { |
| 1360 | removeNode(pepperEnv, target, 'mon') |
| 1361 | } |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | if (rollbacks.contains("mtr")) { |
| 1366 | def target = MTR_TARGET |
| 1367 | if (salt.testTarget(pepperEnv, target)) { |
| 1368 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 1369 | rollback(pepperEnv, target, 'mtr') |
| 1370 | } else { |
| 1371 | removeNode(pepperEnv, target, 'mtr') |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | /* |
| 1376 | if (ROLLBACK_CID.toBoolean()) { |
| 1377 | def target = 'cid*' |
| 1378 | if (salt.testTarget(pepperEnv, target)) { |
| 1379 | stage('ROLLBACK_CID') { |
| 1380 | 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." |
| 1381 | } |
| 1382 | } |
| 1383 | } */ |
| 1384 | |
| 1385 | // |
| 1386 | //physical machines rollback CMP_TARGET |
| 1387 | // |
| 1388 | if (rollbacks.contains("cmp")) { |
| 1389 | def target = CMP_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1390 | def type = 'cmp' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1391 | if (salt.testTarget(pepperEnv, target)) { |
| 1392 | if (PER_NODE.toBoolean()) { |
| 1393 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1394 | for (t in targetHosts) { |
| 1395 | rollbackPkgs(pepperEnv, t) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1396 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1397 | } |
| 1398 | } else { |
| 1399 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1400 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1401 | } |
| 1402 | verifyService(pepperEnv, target, 'nova-compute') |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | if (rollbacks.contains("kvm")) { |
| 1407 | def target = KVM_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1408 | def type = 'kvm' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1409 | if (salt.testTarget(pepperEnv, target)) { |
| 1410 | if (PER_NODE.toBoolean()) { |
| 1411 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1412 | for (t in targetHosts) { |
| 1413 | rollbackPkgs(pepperEnv, t) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1414 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1415 | } |
| 1416 | } else { |
| 1417 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1418 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1419 | } |
| 1420 | verifyService(pepperEnv, target, 'libvirt-bin') |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | if (rollbacks.contains("osd")) { |
| 1425 | def target = CEPH_OSD_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1426 | def type = 'osd' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1427 | if (salt.testTarget(pepperEnv, target)) { |
| 1428 | if (PER_NODE.toBoolean()) { |
| 1429 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1430 | for (t in targetHosts) { |
| 1431 | rollbackPkgs(pepperEnv, t) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1432 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1433 | } |
| 1434 | } else { |
| 1435 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1436 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1437 | } |
| 1438 | verifyCephOsds(pepperEnv, target) |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | if (rollbacks.contains("gtw-physical")) { |
| 1443 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1444 | def type = 'gtw-physical' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1445 | if (salt.testTarget(pepperEnv, target)) { |
| 1446 | if (PER_NODE.toBoolean()) { |
| 1447 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1448 | for (t in targetHosts) { |
| 1449 | rollbackPkgs(pepperEnv, t) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1450 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } else { |
| 1453 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1454 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1455 | } |
| 1456 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /* |
| 1461 | * Merge snapshots section |
| 1462 | */ |
| 1463 | if (merges.contains("cfg")) { |
| 1464 | if (salt.testTarget(pepperEnv, 'I@salt:master')) { |
| 1465 | mergeSnapshot(pepperEnv, 'I@salt:master') |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | if (merges.contains("ctl")) { |
| 1470 | if (salt.testTarget(pepperEnv, CTL_TARGET)) { |
| 1471 | mergeSnapshot(pepperEnv, CTL_TARGET, 'ctl') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1472 | verifyService(pepperEnv, CTL_TARGET, 'nova-api') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | if (merges.contains("prx")) { |
| 1477 | if (salt.testTarget(pepperEnv, PRX_TARGET)) { |
| 1478 | mergeSnapshot(pepperEnv, PRX_TARGET, 'prx') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1479 | verifyService(pepperEnv, PRX_TARGET, 'nginx') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | if (merges.contains("msg")) { |
| 1484 | if (salt.testTarget(pepperEnv, MSG_TARGET)) { |
| 1485 | mergeSnapshot(pepperEnv, MSG_TARGET, 'msg') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1486 | verifyService(pepperEnv, MSG_TARGET, 'rabbitmq-server') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | if (merges.contains("dbs")) { |
| 1491 | if (salt.testTarget(pepperEnv, DBS_TARGET)) { |
| 1492 | mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs') |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1493 | verifyGalera(pepperEnv, DBS_TARGET) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1494 | backupGalera(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | if (merges.contains("ntw")) { |
| 1499 | if (salt.testTarget(pepperEnv, NTW_TARGET)) { |
| 1500 | mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1501 | verifyContrail(pepperEnv, NTW_TARGET) |
| 1502 | backupContrail(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | if (merges.contains("nal")) { |
| 1507 | if (salt.testTarget(pepperEnv, NAL_TARGET)) { |
| 1508 | mergeSnapshot(pepperEnv, NAL_TARGET, 'nal') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1509 | verifyContrail(pepperEnv, NAL_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | if (merges.contains("gtw-virtual")) { |
| 1514 | if (salt.testTarget(pepperEnv, GTW_TARGET)) { |
| 1515 | mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1516 | verifyService(pepperEnv, GTW_TARGET, 'neutron-dhcp-agent') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | if (merges.contains("cmn")) { |
| 1521 | if (salt.testTarget(pepperEnv, CMN_TARGET)) { |
| 1522 | mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1523 | verifyCeph(pepperEnv, CMN_TARGET, 'mon@') |
| 1524 | backupCeph(pepperEnv, CMN_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | if (merges.contains("rgw")) { |
| 1529 | if (salt.testTarget(pepperEnv, RGW_TARGET)) { |
| 1530 | mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1531 | verifyCeph(pepperEnv, RGW_TARGET, 'radosgw@rgw.') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | if (merges.contains("log")) { |
| 1536 | if (salt.testTarget(pepperEnv, LOG_TARGET)) { |
Jiri Broulik | 3bd7adf | 2018-06-29 09:17:28 +0200 | [diff] [blame^] | 1537 | mergeSnapshot(pepperEnv, LOG_TARGET, 'log') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | if (merges.contains("mon")) { |
| 1542 | if (salt.testTarget(pepperEnv, MON_TARGET)) { |
| 1543 | mergeSnapshot(pepperEnv, MON_TARGET, 'mon') |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | if (merges.contains("mtr")) { |
| 1548 | if (salt.testTarget(pepperEnv, MTR_TARGET)) { |
| 1549 | mergeSnapshot(pepperEnv, MTR_TARGET, 'mtr') |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | if (merges.contains("cid")) { |
| 1554 | if (salt.testTarget(pepperEnv, CID_TARGET)) { |
| 1555 | mergeSnapshot(pepperEnv, CID_TARGET, 'cid') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1556 | verifyService(pepperEnv, CID_TARGET, 'docker') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | if (RESTORE_GALERA.toBoolean()) { |
| 1561 | restoreGalera(pepperEnv) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1562 | verifyGalera(pepperEnv, DBS_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | if (RESTORE_CONTRAIL_DB.toBoolean()) { |
| 1566 | restoreContrailDb(pepperEnv) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1567 | // verification is already present in restore pipelines |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | } catch (Throwable e) { |
| 1571 | // If there was an error or exception thrown, the build failed |
| 1572 | currentBuild.result = "FAILURE" |
| 1573 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 1574 | throw e |
| 1575 | } |
| 1576 | } |
| 1577 | } |