Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [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 | * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian]. |
| 8 | */ |
| 9 | |
| 10 | pepperEnv = "pepperEnv" |
| 11 | salt = new com.mirantis.mk.Salt() |
| 12 | def common = new com.mirantis.mk.Common() |
| 13 | def python = new com.mirantis.mk.Python() |
| 14 | def targetLiveSubset |
| 15 | def targetLiveAll |
| 16 | def minions |
| 17 | def result |
| 18 | def packages |
| 19 | def command |
| 20 | def commandKwargs |
| 21 | def selMinions = [] |
| 22 | |
| 23 | def runCephCommand(master, target, cmd) { |
| 24 | return salt.cmdRun(master, target, cmd) |
| 25 | } |
| 26 | |
| 27 | def waitForHealthy(master, tgt, attempts=100, timeout=10) { |
| 28 | // wait for healthy cluster |
| 29 | common = new com.mirantis.mk.Common() |
| 30 | common.retry(attempts, timeout){ |
| 31 | def health = runCephCommand(master, tgt, 'ceph health')['return'][0].values()[0] |
| 32 | if (health.contains('HEALTH_OK') || health.contains('HEALTH_WARN noout flag(s) set\n')) { |
| 33 | common.infoMsg('Cluster is healthy') |
| 34 | return 0 |
| 35 | } else { |
| 36 | common.infoMsg(health) |
| 37 | throw new Exception() |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | timeout(time: 12, unit: 'HOURS') { |
| 43 | node() { |
| 44 | try { |
| 45 | |
| 46 | stage('Setup virtualenv for Pepper') { |
| 47 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 48 | } |
| 49 | |
| 50 | stage('List target servers') { |
| 51 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
| 52 | |
| 53 | if (minions.isEmpty()) { |
| 54 | throw new Exception("No minion was targeted") |
| 55 | } |
| 56 | |
| 57 | for (m in minions) { |
| 58 | if (m.startsWith("osd") || m.startsWith("cmn") || m.startsWith("rgw")) { |
| 59 | selMinions.add(m) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | stage('Apply package upgrades on all nodes') { |
| 67 | |
| 68 | for (tgt in selMinions) { |
| 69 | try { |
| 70 | if (tgt.startsWith("osd")) { |
| 71 | out = runCephCommand(pepperEnv, tgt, "apt install --only-upgrade ceph-osd -y") |
| 72 | salt.printSaltCommandResult(out) |
| 73 | } else if (tgt.startsWith("cmn")) { |
| 74 | out = runCephCommand(pepperEnv, tgt, "apt install --only-upgrade ceph-mon -y") |
| 75 | salt.printSaltCommandResult(out) |
| 76 | } else if (tgt.startsWith("rgw")) { |
| 77 | out = runCephCommand(pepperEnv, tgt, "apt install --only-upgrade radosgw -y") |
| 78 | salt.printSaltCommandResult(out) |
| 79 | } |
| 80 | } catch (Throwable e) { |
| 81 | if (e.message.contains("Unmet dependencies")) { |
| 82 | out = runCephCommand(pepperEnv, tgt, "apt -f install -y") |
| 83 | salt.printSaltCommandResult(out) |
| 84 | } else { |
| 85 | throw (e) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | stage("Restart MONs and RGWs") { |
| 92 | for (tgt in selMinions) { |
| 93 | if (tgt.contains("cmn")) { |
| 94 | runCephCommand(pepperEnv, tgt, "systemctl restart ceph-mon.target") |
| 95 | waitForHealthy(pepperEnv, tgt) |
| 96 | } else if (tgt.contains("rgw")) { |
| 97 | runCephCommand(pepperEnv, tgt, "systemctl restart ceph-radosgw.target") |
| 98 | waitForHealthy(pepperEnv, tgt) |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | stage('Restart OSDs') { |
| 104 | |
| 105 | for (tgt in selMinions) { |
| 106 | if (tgt.contains("osd")) { |
| 107 | salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5) |
| 108 | def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk'] |
| 109 | |
| 110 | def osd_ids = [] |
| 111 | for (i in ceph_disks) { |
| 112 | def osd_id = i.getKey().toString() |
| 113 | osd_ids.add('osd.' + osd_id) |
| 114 | } |
| 115 | |
| 116 | runCephCommand(pepperEnv, tgt, 'ceph osd set noout') |
| 117 | |
| 118 | for (i in osd_ids) { |
| 119 | |
| 120 | salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
| 121 | // wait for healthy cluster |
| 122 | waitForHealthy(pepperEnv, tgt) |
| 123 | } |
| 124 | |
| 125 | runCephCommand(pepperEnv, tgt, 'ceph osd unset noout') |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
| 131 | } catch (Throwable e) { |
| 132 | // If there was an error or exception thrown, the build failed |
| 133 | currentBuild.result = "FAILURE" |
| 134 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 135 | throw e |
| 136 | } |
| 137 | } |
| 138 | } |