Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Replace failed disk with a new disk |
| 4 | * |
| 5 | * Requred parameters: |
Jiri Broulik | a657d56 | 2017-11-28 14:19:32 +0100 | [diff] [blame] | 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 8 | * |
Jiri Broulik | a657d56 | 2017-11-28 14:19:32 +0100 | [diff] [blame] | 9 | * HOST Host (minion id) to be removed |
| 10 | * ADMIN_HOST Host (minion id) with admin keyring and /etc/crushmap file present |
| 11 | * OSD Failed OSD ids to be replaced (comma-separated list - 1,2,3) |
| 12 | * DEVICE Comma separated list of failed devices that will be replaced at HOST (/dev/sdb,/dev/sdc) |
| 13 | * JOURNAL_BLOCKDB_BLOCKWAL_PARTITION Comma separated list of partitions where journal or block_db or block_wal for the failed devices on this HOST were stored (/dev/sdh2,/dev/sdh3) |
| 14 | * CLUSTER_FLAGS Comma separated list of tags to apply to cluster |
| 15 | * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 16 | * DMCRYPT Set to True if replacing osds are/were encrypted |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | common = new com.mirantis.mk.Common() |
| 21 | salt = new com.mirantis.mk.Salt() |
| 22 | def python = new com.mirantis.mk.Python() |
| 23 | |
| 24 | def pepperEnv = "pepperEnv" |
| 25 | def flags = CLUSTER_FLAGS.tokenize(',') |
| 26 | def osds = OSD.tokenize(',') |
| 27 | def devices = DEVICE.tokenize(',') |
Jiri Broulik | a657d56 | 2017-11-28 14:19:32 +0100 | [diff] [blame] | 28 | def journals_blockdbs_blockwals = JOURNAL_BLOCKDB_BLOCKWAL_PARTITION.tokenize(',') |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def runCephCommand(master, target, cmd) { |
| 32 | return salt.cmdRun(master, target, cmd) |
| 33 | } |
| 34 | |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame] | 35 | def waitForHealthy(master, count=0, attempts=300) { |
| 36 | // wait for healthy cluster |
| 37 | while (count<attempts) { |
| 38 | def health = runCephCommand(master, ADMIN_HOST, 'ceph health')['return'][0].values()[0] |
| 39 | if (health.contains('HEALTH_OK')) { |
| 40 | common.infoMsg('Cluster is healthy') |
| 41 | break; |
| 42 | } |
| 43 | count++ |
| 44 | sleep(10) |
| 45 | } |
| 46 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 47 | timeout(time: 12, unit: 'HOURS') { |
| 48 | node("python") { |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame] | 49 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 50 | // create connection to salt master |
| 51 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 52 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 53 | def osd_ids = [] |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 54 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 55 | for (osd_id in osds) { |
| 56 | osd_ids.add('osd.' + osd_id) |
| 57 | print("Will delete " + osd_id) |
| 58 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 59 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 60 | // `ceph osd out <id> <id>` |
| 61 | stage('Set OSDs out') { |
| 62 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd out ' + osd_ids.join(' ')) |
| 63 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 64 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 65 | // wait for healthy cluster |
| 66 | if (WAIT_FOR_HEALTHY.toBoolean() == true) { |
| 67 | sleep(5) |
| 68 | waitForHealthy(pepperEnv) |
| 69 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 70 | |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 71 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 72 | if (flags.size() > 0) { |
| 73 | stage('Set cluster flags') { |
| 74 | for (flag in flags) { |
| 75 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag) |
| 76 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 77 | } |
| 78 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 79 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 80 | // stop osd daemons |
| 81 | stage('Stop OSD daemons') { |
| 82 | for (i in osd_ids) { |
| 83 | salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
| 84 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 85 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 86 | /* |
| 87 | // `ceph osd crush remove osd.2` |
| 88 | stage('Remove OSDs from CRUSH') { |
| 89 | for (i in osd_ids) { |
| 90 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd crush remove ' + i) |
| 91 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 92 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 93 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 94 | // wait for pgs to rebalance |
| 95 | if (WAIT_FOR_PG_REBALANCE.toBoolean() == true) { |
| 96 | stage('Waiting for pgs to rebalance') { |
| 97 | while (true) { |
| 98 | def status = runCephCommand(pepperEnv, ADMIN_HOST, 'ceph -s')['return'][0].values()[0] |
| 99 | if (!status.contains('degraded')) { |
| 100 | common.infoMsg('PGs rebalanced') |
| 101 | break; |
| 102 | } |
| 103 | sleep(10) |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 104 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 105 | } |
| 106 | } |
| 107 | */ |
| 108 | // remove keyring `ceph auth del osd.3` |
| 109 | stage('Remove OSD keyrings from auth') { |
| 110 | for (i in osd_ids) { |
| 111 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph auth del ' + i) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // remove osd `ceph osd rm osd.3` |
| 116 | stage('Remove OSDs') { |
| 117 | for (i in osd_ids) { |
| 118 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd rm ' + i) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if (DMCRYPT.toBoolean() == true) { |
| 123 | |
| 124 | // remove partition tables |
| 125 | stage('dd part tables') { |
| 126 | for (dev in devices) { |
| 127 | runCephCommand(pepperEnv, HOST, "dd if=/dev/zero of=${dev} bs=512 count=1 conv=notrunc") |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // remove journal, block_db or block_wal partition `parted /dev/sdj rm 3` |
| 132 | stage('Remove journal / block_db / block_wal partitions') { |
| 133 | for (partition in journals_blockdbs_blockwals) { |
| 134 | if (partition?.trim()) { |
| 135 | // dev = /dev/sdi |
| 136 | def dev = partition.replaceAll("[0-9]", "") |
| 137 | // part_id = 2 |
| 138 | def part_id = partition.substring(partition.lastIndexOf("/")+1).replaceAll("[^0-9]", "") |
| 139 | try { |
| 140 | runCephCommand(pepperEnv, HOST, "Ignore | parted ${dev} rm ${part_id}") |
| 141 | } catch (Exception e) { |
| 142 | common.warningMsg(e) |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // reboot |
| 149 | stage('reboot and wait') { |
| 150 | salt.runSaltProcessStep(pepperEnv, HOST, 'system.reboot', null, null, true, 5) |
| 151 | salt.minionsReachable(pepperEnv, 'I@salt:master', HOST) |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 152 | sleep(10) |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 153 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 154 | |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 155 | |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 156 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 157 | // zap disks `ceph-disk zap /dev/sdi` |
| 158 | stage('Zap devices') { |
| 159 | for (dev in devices) { |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 160 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 161 | runCephCommand(pepperEnv, HOST, 'ceph-disk zap ' + dev) |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 162 | } catch (Exception e) { |
| 163 | common.warningMsg(e) |
| 164 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 165 | runCephCommand(pepperEnv, HOST, 'ceph-disk zap ' + dev) |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 166 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 167 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 168 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 169 | } else { |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 170 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 171 | // umount `umount /dev/sdi1` |
| 172 | stage('Umount devices') { |
| 173 | for (dev in devices) { |
| 174 | runCephCommand(pepperEnv, HOST, 'umount ' + dev + '1') |
| 175 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 176 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 177 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 178 | // zap disks `ceph-disk zap /dev/sdi` |
| 179 | stage('Zap devices') { |
| 180 | for (dev in devices) { |
| 181 | runCephCommand(pepperEnv, HOST, 'ceph-disk zap ' + dev) |
| 182 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 183 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 184 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 185 | // remove journal, block_db or block_wal partition `parted /dev/sdj rm 3` |
| 186 | stage('Remove journal / block_db / block_wal partitions') { |
| 187 | for (partition in journals_blockdbs_blockwals) { |
| 188 | if (partition?.trim()) { |
| 189 | // dev = /dev/sdi |
| 190 | def dev = partition.replaceAll("[0-9]", "") |
| 191 | // part_id = 2 |
| 192 | def part_id = partition.substring(partition.lastIndexOf("/")+1).replaceAll("[^0-9]", "") |
| 193 | try { |
| 194 | runCephCommand(pepperEnv, HOST, "parted ${dev} rm ${part_id}") |
| 195 | } catch (Exception e) { |
| 196 | common.warningMsg(e) |
| 197 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 198 | } |
| 199 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 200 | } |
| 201 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 202 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 203 | // Deploy failed Ceph OSD |
| 204 | stage('Deploy Ceph OSD') { |
| 205 | salt.enforceState(pepperEnv, HOST, 'ceph.osd', true) |
| 206 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 207 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 208 | // remove cluster flags |
| 209 | if (flags.size() > 0) { |
| 210 | stage('Unset cluster flags') { |
| 211 | for (flag in flags) { |
| 212 | common.infoMsg('Removing flag ' + flag) |
| 213 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag) |
| 214 | } |
Jiri Broulik | dc87d72 | 2017-11-03 15:43:22 +0100 | [diff] [blame] | 215 | } |
| 216 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 217 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 218 | /* |
| 219 | if (ENFORCE_CRUSHMAP.toBoolean() == true) { |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 220 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 221 | // enforce crushmap `crushtool -c /etc/ceph/crushmap -o /etc/ceph/crushmap.compiled; ceph osd setcrushmap -i /etc/ceph/crushmap.compiled` |
| 222 | stage('Enforce crushmap') { |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 223 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 224 | stage('Ask for manual confirmation') { |
| 225 | input message: "Are you sure that your ADMIN_HOST has correct /etc/ceph/crushmap file? Click proceed to compile and enforce crushmap." |
| 226 | } |
| 227 | runCephCommand(pepperEnv, ADMIN_HOST, 'crushtool -c /etc/ceph/crushmap -o /etc/ceph/crushmap.compiled') |
| 228 | runCephCommand(pepperEnv, ADMIN_HOST, 'ceph osd setcrushmap -i /etc/ceph/crushmap.compiled') |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 229 | } |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 230 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 231 | */ |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 232 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 233 | } |