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() |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 710 | 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 719 | } |
| 720 | |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 721 | def verifyGalera(pepperEnv, target, count=0, maxRetries=200) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 722 | def salt = new com.mirantis.mk.Salt() |
| 723 | def common = new com.mirantis.mk.Common() |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 724 | def out |
| 725 | while(count < maxRetries) { |
| 726 | try { |
William Konitzer | 667143f | 2018-06-15 14:21:17 -0500 | [diff] [blame^] | 727 | 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] | 728 | } 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 Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 742 | } else { |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 743 | break |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | def 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 | |
| 755 | def 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 | |
| 773 | def 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 | |
| 792 | def 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 | |
| 827 | timeout(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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 842 | def type = 'cfg' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 843 | if (salt.testTarget(pepperEnv, target)) { |
| 844 | def master = salt.getReturnValues(salt.getPillar(pepperEnv, target, 'linux:network:hostname')) |
Jiri Broulik | 827d011 | 2018-04-25 16:00:07 +0200 | [diff] [blame] | 845 | getNodeProvider(pepperEnv, master, 'master') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 846 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
| 847 | virsh.liveSnapshotPresent(pepperEnv, CFG_NODE_PROVIDER, master, SNAPSHOT_NAME) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 848 | } else { |
| 849 | saltMasterBackup(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 850 | } |
| 851 | if (PER_NODE.toBoolean()) { |
| 852 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 853 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 854 | updatePkgs(pepperEnv, t, type) |
| 855 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 856 | } |
| 857 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 858 | updatePkgs(pepperEnv, target, type) |
| 859 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | if (updates.contains("ctl")) { |
| 865 | def target = CTL_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 866 | def type = 'ctl' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 867 | if (salt.testTarget(pepperEnv, target)) { |
| 868 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 869 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 870 | } |
| 871 | if (PER_NODE.toBoolean()) { |
| 872 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 873 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 874 | updatePkgs(pepperEnv, t, type) |
| 875 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 876 | } |
| 877 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 878 | updatePkgs(pepperEnv, target, type) |
| 879 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 880 | } |
| 881 | verifyAPIs(pepperEnv, target) |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | if (updates.contains("prx")) { |
| 886 | def target = PRX_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 887 | def type = 'prx' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 888 | if (salt.testTarget(pepperEnv, target)) { |
| 889 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 890 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 891 | } |
| 892 | if (PER_NODE.toBoolean()) { |
| 893 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 894 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 895 | updatePkgs(pepperEnv, t, type) |
| 896 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 897 | } |
| 898 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 899 | updatePkgs(pepperEnv, target, type) |
| 900 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 901 | } |
| 902 | verifyService(pepperEnv, target, 'nginx') |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | if (updates.contains("msg")) { |
| 907 | def target = MSG_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 908 | def type = 'msg' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 909 | if (salt.testTarget(pepperEnv, target)) { |
| 910 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 911 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 912 | } |
| 913 | if (PER_NODE.toBoolean()) { |
| 914 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 915 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 916 | updatePkgs(pepperEnv, t, type) |
| 917 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 918 | } |
| 919 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 920 | updatePkgs(pepperEnv, target, type) |
| 921 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 922 | } |
| 923 | verifyService(pepperEnv, target, 'rabbitmq-server') |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | if (updates.contains("dbs")) { |
| 928 | def target = DBS_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 929 | def type = 'dbs' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 930 | if (salt.testTarget(pepperEnv, target)) { |
| 931 | backupGalera(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 932 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 933 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 934 | } |
Jiri Broulik | 7ba05e4 | 2018-04-06 11:39:25 +0200 | [diff] [blame] | 935 | if (reboots.contains(type) || PER_NODE.toBoolean()) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 936 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 937 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 938 | updatePkgs(pepperEnv, t, type) |
| 939 | highstate(pepperEnv, t, type) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 940 | verifyGalera(pepperEnv, t) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 941 | } |
| 942 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 943 | updatePkgs(pepperEnv, target, type) |
| 944 | highstate(pepperEnv, target, type) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 945 | verifyGalera(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 946 | } |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
| 950 | if (updates.contains("ntw")) { |
| 951 | def target = NTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 952 | def type = 'ntw' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 953 | if (salt.testTarget(pepperEnv, target)) { |
| 954 | backupContrail(pepperEnv) |
| 955 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 956 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 957 | } |
| 958 | if (PER_NODE.toBoolean()) { |
| 959 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 960 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 961 | updatePkgs(pepperEnv, t, type) |
| 962 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 963 | verifyContrail(pepperEnv, t) |
| 964 | } |
| 965 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 966 | updatePkgs(pepperEnv, target, type) |
| 967 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 968 | verifyContrail(pepperEnv, target) |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | if (updates.contains("nal")) { |
| 974 | def target = NAL_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 975 | def type = 'nal' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 976 | if (salt.testTarget(pepperEnv, target)) { |
| 977 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 978 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 979 | } |
| 980 | if (PER_NODE.toBoolean()) { |
| 981 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 982 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 983 | updatePkgs(pepperEnv, t, type) |
| 984 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 985 | } |
| 986 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 987 | updatePkgs(pepperEnv, target, type) |
| 988 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 989 | } |
| 990 | verifyContrail(pepperEnv, target) |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | if (updates.contains("gtw-virtual")) { |
| 995 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 996 | def type = 'gtw-virtual' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 997 | if (salt.testTarget(pepperEnv, target)) { |
| 998 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 999 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1000 | } |
| 1001 | if (PER_NODE.toBoolean()) { |
| 1002 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1003 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1004 | updatePkgs(pepperEnv, t, type) |
| 1005 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1006 | } |
| 1007 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1008 | updatePkgs(pepperEnv, target, type) |
| 1009 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1010 | } |
| 1011 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | if (updates.contains("cmn")) { |
| 1016 | def target = CMN_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1017 | def type = 'cmn' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1018 | if (salt.testTarget(pepperEnv, target)) { |
| 1019 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1020 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1021 | } else { |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1022 | backupCeph(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1023 | } |
| 1024 | if (PER_NODE.toBoolean()) { |
| 1025 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1026 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1027 | updatePkgs(pepperEnv, t, type) |
| 1028 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1029 | } |
| 1030 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1031 | updatePkgs(pepperEnv, target, type) |
| 1032 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1033 | } |
| 1034 | verifyCeph(pepperEnv, target, 'mon@') |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | if (updates.contains("rgw")) { |
| 1039 | def target = RGW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1040 | def type = 'rgw' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1041 | if (salt.testTarget(pepperEnv, target)) { |
| 1042 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1043 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1044 | } |
| 1045 | if (PER_NODE.toBoolean()) { |
| 1046 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1047 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1048 | updatePkgs(pepperEnv, t, type) |
| 1049 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1050 | } |
| 1051 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1052 | updatePkgs(pepperEnv, target, type) |
| 1053 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1054 | } |
| 1055 | verifyCeph(pepperEnv, target, 'radosgw@rgw.') |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | if (updates.contains("log")) { |
| 1060 | def target = LOG_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1061 | def type = 'log' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1062 | if (salt.testTarget(pepperEnv, target)) { |
| 1063 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1064 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1065 | } |
| 1066 | if (PER_NODE.toBoolean()) { |
| 1067 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1068 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1069 | updatePkgs(pepperEnv, t, type) |
| 1070 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1071 | } |
| 1072 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1073 | updatePkgs(pepperEnv, target, type) |
| 1074 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | if (updates.contains("mon")) { |
| 1080 | def target = MON_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1081 | def type = 'mon' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1082 | if (salt.testTarget(pepperEnv, target)) { |
| 1083 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1084 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1085 | } |
| 1086 | if (PER_NODE.toBoolean()) { |
| 1087 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1088 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1089 | updatePkgs(pepperEnv, t, type) |
| 1090 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1091 | } |
| 1092 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1093 | updatePkgs(pepperEnv, target, type) |
| 1094 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | if (updates.contains("mtr")) { |
| 1100 | def target = MTR_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1101 | def type = 'mtr' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1102 | if (salt.testTarget(pepperEnv, target)) { |
| 1103 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1104 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1105 | } |
| 1106 | if (PER_NODE.toBoolean()) { |
| 1107 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1108 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1109 | updatePkgs(pepperEnv, t, type) |
| 1110 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1111 | } |
| 1112 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1113 | updatePkgs(pepperEnv, target, type) |
| 1114 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | if (updates.contains("cid")) { |
| 1120 | def target = CID_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1121 | def type = 'cid' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1122 | if (salt.testTarget(pepperEnv, target)) { |
| 1123 | if (!ROLLBACK_BY_REDEPLOY.toBoolean()) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1124 | liveSnapshot(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1125 | } |
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 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1137 | def type = 'cmp' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1138 | if (salt.testTarget(pepperEnv, target)) { |
| 1139 | if (PER_NODE.toBoolean()) { |
| 1140 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1141 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1142 | updatePkgs(pepperEnv, t, type) |
| 1143 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1144 | } |
| 1145 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1146 | updatePkgs(pepperEnv, target, type) |
| 1147 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1148 | } |
| 1149 | verifyService(pepperEnv, target, 'nova-compute') |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | if (updates.contains("kvm")) { |
| 1154 | def target = KVM_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1155 | def type = 'kvm' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1156 | if (salt.testTarget(pepperEnv, target)) { |
| 1157 | if (PER_NODE.toBoolean()) { |
| 1158 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1159 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1160 | updatePkgs(pepperEnv, t, type) |
| 1161 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1162 | } |
| 1163 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1164 | updatePkgs(pepperEnv, target, type) |
| 1165 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1166 | } |
| 1167 | verifyService(pepperEnv, target, 'libvirt-bin') |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | if (updates.contains("osd")) { |
| 1172 | def target = CEPH_OSD_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1173 | def type = 'osd' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1174 | if (salt.testTarget(pepperEnv, target)) { |
| 1175 | if (PER_NODE.toBoolean()) { |
| 1176 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1177 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1178 | updatePkgs(pepperEnv, t, type) |
| 1179 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1180 | } |
| 1181 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1182 | updatePkgs(pepperEnv, target, type) |
| 1183 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1184 | } |
| 1185 | verifyCephOsds(pepperEnv, target) |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | if (updates.contains("gtw-physical")) { |
| 1190 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1191 | def type = 'gtw-physical' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1192 | if (salt.testTarget(pepperEnv, target)) { |
| 1193 | if (PER_NODE.toBoolean()) { |
| 1194 | def targetHosts = salt.getMinionsSorted(pepperEnv, target) |
| 1195 | for (t in targetHosts) { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1196 | updatePkgs(pepperEnv, t, type) |
| 1197 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1198 | } |
| 1199 | } else { |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1200 | updatePkgs(pepperEnv, target, type) |
| 1201 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1202 | } |
| 1203 | verifyService(pepperEnv, target, 'neutron-dhcp-agent') |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * Rollback section |
| 1209 | */ |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1210 | /* if (rollbacks.contains("cfg")) { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1211 | 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 Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1263 | verifyGalera(pepperEnv, target) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1264 | } 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1377 | def type = 'cmp' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1378 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1383 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1384 | } |
| 1385 | } else { |
| 1386 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1387 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1388 | } |
| 1389 | verifyService(pepperEnv, target, 'nova-compute') |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | if (rollbacks.contains("kvm")) { |
| 1394 | def target = KVM_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1395 | def type = 'kvm' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1396 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1401 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1402 | } |
| 1403 | } else { |
| 1404 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1405 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1406 | } |
| 1407 | verifyService(pepperEnv, target, 'libvirt-bin') |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | if (rollbacks.contains("osd")) { |
| 1412 | def target = CEPH_OSD_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1413 | def type = 'osd' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1414 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1419 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1420 | } |
| 1421 | } else { |
| 1422 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1423 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1424 | } |
| 1425 | verifyCephOsds(pepperEnv, target) |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | if (rollbacks.contains("gtw-physical")) { |
| 1430 | def target = GTW_TARGET |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1431 | def type = 'gtw-physical' |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1432 | 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 Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1437 | highstate(pepperEnv, t, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1438 | } |
| 1439 | } else { |
| 1440 | rollbackPkgs(pepperEnv, target, target) |
Jiri Broulik | ba6d85d | 2018-04-05 13:29:07 +0200 | [diff] [blame] | 1441 | highstate(pepperEnv, target, type) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1442 | } |
| 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 Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1459 | verifyService(pepperEnv, CTL_TARGET, 'nova-api') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | if (merges.contains("prx")) { |
| 1464 | if (salt.testTarget(pepperEnv, PRX_TARGET)) { |
| 1465 | mergeSnapshot(pepperEnv, PRX_TARGET, 'prx') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1466 | verifyService(pepperEnv, PRX_TARGET, 'nginx') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | if (merges.contains("msg")) { |
| 1471 | if (salt.testTarget(pepperEnv, MSG_TARGET)) { |
| 1472 | mergeSnapshot(pepperEnv, MSG_TARGET, 'msg') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1473 | verifyService(pepperEnv, MSG_TARGET, 'rabbitmq-server') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | if (merges.contains("dbs")) { |
| 1478 | if (salt.testTarget(pepperEnv, DBS_TARGET)) { |
| 1479 | mergeSnapshot(pepperEnv, DBS_TARGET, 'dbs') |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1480 | verifyGalera(pepperEnv, DBS_TARGET) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1481 | backupGalera(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | if (merges.contains("ntw")) { |
| 1486 | if (salt.testTarget(pepperEnv, NTW_TARGET)) { |
| 1487 | mergeSnapshot(pepperEnv, NTW_TARGET, 'ntw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1488 | verifyContrail(pepperEnv, NTW_TARGET) |
| 1489 | backupContrail(pepperEnv) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if (merges.contains("nal")) { |
| 1494 | if (salt.testTarget(pepperEnv, NAL_TARGET)) { |
| 1495 | mergeSnapshot(pepperEnv, NAL_TARGET, 'nal') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1496 | verifyContrail(pepperEnv, NAL_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | if (merges.contains("gtw-virtual")) { |
| 1501 | if (salt.testTarget(pepperEnv, GTW_TARGET)) { |
| 1502 | mergeSnapshot(pepperEnv, GTW_TARGET, 'gtw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1503 | verifyService(pepperEnv, GTW_TARGET, 'neutron-dhcp-agent') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | if (merges.contains("cmn")) { |
| 1508 | if (salt.testTarget(pepperEnv, CMN_TARGET)) { |
| 1509 | mergeSnapshot(pepperEnv, CMN_TARGET, 'cmn') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1510 | verifyCeph(pepperEnv, CMN_TARGET, 'mon@') |
| 1511 | backupCeph(pepperEnv, CMN_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | if (merges.contains("rgw")) { |
| 1516 | if (salt.testTarget(pepperEnv, RGW_TARGET)) { |
| 1517 | mergeSnapshot(pepperEnv, RGW_TARGET, 'rgw') |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1518 | verifyCeph(pepperEnv, RGW_TARGET, 'radosgw@rgw.') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1519 | } |
| 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 Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1543 | verifyService(pepperEnv, CID_TARGET, 'docker') |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | if (RESTORE_GALERA.toBoolean()) { |
| 1548 | restoreGalera(pepperEnv) |
Jiri Broulik | ad606d0 | 2018-03-28 14:22:43 +0200 | [diff] [blame] | 1549 | verifyGalera(pepperEnv, DBS_TARGET) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | if (RESTORE_CONTRAIL_DB.toBoolean()) { |
| 1553 | restoreContrailDb(pepperEnv) |
Jiri Broulik | 906e997 | 2018-03-26 16:12:00 +0200 | [diff] [blame] | 1554 | // verification is already present in restore pipelines |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 1555 | } |
| 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 | } |