Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Remove OSD from existing cluster |
| 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * |
| 9 | * HOST Host (minion id) to be removed |
Jiri Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 10 | * OSD Comma separated list of osd ids to be removed |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 11 | * ADMIN_HOST Host (minion id) with admin keyring |
| 12 | * CLUSTER_FLAGS Comma separated list of tags to apply to cluster |
| 13 | * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons |
| 14 | * |
| 15 | */ |
| 16 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 17 | def common = new com.mirantis.mk.Common() |
| 18 | def salt = new com.mirantis.mk.Salt() |
| 19 | def ceph = new com.mirantis.mk.Ceph() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 20 | def python = new com.mirantis.mk.Python() |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 21 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 22 | def pepperEnv = "pepperEnv" |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 23 | def flags = CLUSTER_FLAGS.tokenize(',') |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 24 | def osds = OSD.tokenize(',') |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 25 | def cleanDisk = CLEANDISK |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 26 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node("python") { |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame] | 29 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 30 | // create connection to salt master |
| 31 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 32 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | if (flags.size() > 0) { |
| 34 | stage('Set cluster flags') { |
| 35 | for (flag in flags) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 36 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 37 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 38 | } |
| 39 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 40 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 41 | def osd_ids = [] |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 42 | |
Mateusz Los | 13d0520 | 2020-05-11 09:51:13 +0200 | [diff] [blame] | 43 | def checknode = salt.runSaltProcessStep(pepperEnv, HOST, 'test.ping') |
| 44 | if (checknode['return'][0].values().isEmpty()) { |
| 45 | common.errorMsg("Host not found") |
| 46 | throw new InterruptedException() |
| 47 | } |
| 48 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 49 | // get list of osd disks of the host |
| 50 | salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.sync_grains', [], null, true, 5) |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 51 | def cephGrain = salt.getGrain(pepperEnv, HOST, 'ceph') |
| 52 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 53 | if (cephGrain['return'].isEmpty()) { |
Jakub Josef | ed670ca | 2018-01-18 14:22:20 +0100 | [diff] [blame] | 54 | throw new Exception("Ceph salt grain cannot be found!") |
| 55 | } |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 56 | common.print(cephGrain) |
Tomek Jaroszyk | 933011a | 2020-04-07 11:20:31 +0200 | [diff] [blame] | 57 | def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk'] |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 58 | common.prettyPrint(ceph_disks) |
Jiri Broulik | adc7ecd | 2017-10-18 06:59:27 +0200 | [diff] [blame] | 59 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 60 | for (i in ceph_disks) { |
| 61 | def osd_id = i.getKey().toString() |
| 62 | if (osd_id in osds || OSD == '*') { |
| 63 | osd_ids.add('osd.' + osd_id) |
| 64 | print("Will delete " + osd_id) |
| 65 | } else { |
| 66 | print("Skipping " + osd_id) |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 67 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 68 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 69 | |
Mateusz Los | 31a3bbc | 2019-03-28 14:12:23 +0100 | [diff] [blame] | 70 | if ( osd_ids == [] ) |
| 71 | { |
| 72 | currentBuild.result = 'SUCCESS' |
| 73 | return |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // `ceph osd out <id> <id>` |
| 77 | stage('Set OSDs out') { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 78 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd out ' + osd_ids.join(' ')) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // wait for healthy cluster |
Jakub Josef | ed670ca | 2018-01-18 14:22:20 +0100 | [diff] [blame] | 82 | if (WAIT_FOR_HEALTHY.toBoolean()) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 83 | sleep(5) |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 84 | ceph.waitForHealthy(pepperEnv, ADMIN_HOST) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | // stop osd daemons |
| 88 | stage('Stop OSD daemons') { |
| 89 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 90 | salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | // `ceph osd crush remove osd.2` |
| 95 | stage('Remove OSDs from CRUSH') { |
| 96 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 97 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd crush remove ' + i) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | // remove keyring `ceph auth del osd.3` |
| 102 | stage('Remove OSD keyrings from auth') { |
| 103 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 104 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph auth del ' + i) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | // remove osd `ceph osd rm osd.3` |
| 109 | stage('Remove OSDs') { |
| 110 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 111 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd rm ' + i) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | for (osd_id in osd_ids) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 116 | id = osd_id.replaceAll('osd.', '') |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 117 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 118 | // remove journal, block_db, block_wal partition `parted /dev/sdj rm 3` |
| 119 | stage('Remove journal / block_db / block_wal partition') { |
| 120 | def partition_uuid = "" |
| 121 | def journal_partition_uuid = "" |
| 122 | def block_db_partition_uuid = "" |
| 123 | def block_wal_partition_uuid = "" |
| 124 | try { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 125 | journal_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/journal_uuid")['return'][0].values()[0].split("\n")[0] |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 126 | } |
| 127 | catch (Exception e) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 128 | common.infoMsg(e) |
| 129 | } |
| 130 | try { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 131 | block_db_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/block.db_uuid")['return'][0].values()[0].split("\n")[0] |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 132 | } |
| 133 | catch (Exception e) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 134 | common.infoMsg(e) |
| 135 | } |
| 136 | |
| 137 | try { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 138 | block_wal_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/block.wal_uuid")['return'][0].values()[0].split("\n")[0] |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 139 | } |
| 140 | catch (Exception e) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 141 | common.infoMsg(e) |
| 142 | } |
| 143 | |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 144 | // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 145 | if (journal_partition_uuid?.trim()) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 146 | ceph.removePartition(pepperEnv, HOST, journal_partition_uuid) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 147 | } |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 148 | if (block_db_partition_uuid?.trim()) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 149 | ceph.removePartition(pepperEnv, HOST, block_db_partition_uuid) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 150 | } |
| 151 | if (block_wal_partition_uuid?.trim()) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 152 | ceph.removePartition(pepperEnv, HOST, block_wal_partition_uuid) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 153 | } |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 154 | |
| 155 | try { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 156 | salt.cmdRun(pepperEnv, HOST, "partprobe") |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 157 | } |
| 158 | catch (Exception e) { |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 159 | common.warningMsg(e) |
| 160 | } |
| 161 | } |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 162 | if (cleanDisk) { |
| 163 | // remove data / block / lockbox partition `parted /dev/sdj rm 3` |
| 164 | stage('Remove data / block / lockbox partition') { |
| 165 | def data_partition_uuid = "" |
| 166 | def block_partition_uuid = "" |
| 167 | def osd_fsid = "" |
| 168 | def lvm = "" |
| 169 | def lvm_enabled= salt.getPillar(pepperEnv,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true) |
| 170 | try { |
| 171 | osd_fsid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/fsid")['return'][0].values()[0].split("\n")[0] |
| 172 | if (lvm_enabled) { |
| 173 | lvm = salt.runSaltCommand(pepperEnv, 'local', ['expression': HOST, 'type': 'compound'], 'cmd.run', null, "salt-call lvm.lvdisplay --output json -l quiet")['return'][0].values()[0] |
| 174 | lvm = new groovy.json.JsonSlurperClassic().parseText(lvm) |
| 175 | lvm["local"].each { lv, params -> |
| 176 | if (params["Logical Volume Name"].contains(osd_fsid)) { |
| 177 | data_partition_uuid = params["Logical Volume Name"].minus("/dev/") |
| 178 | } |
mjedynski | 12955c7 | 2019-12-09 15:17:58 +0100 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 182 | catch (Exception e) { |
| 183 | common.infoMsg(e) |
| 184 | } |
| 185 | try { |
| 186 | block_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/block_uuid")['return'][0].values()[0].split("\n")[0] |
| 187 | } |
| 188 | catch (Exception e) { |
| 189 | common.infoMsg(e) |
| 190 | } |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 191 | |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 192 | // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932 |
| 193 | if (block_partition_uuid?.trim()) { |
| 194 | ceph.removePartition(pepperEnv, HOST, block_partition_uuid) |
| 195 | try{ |
| 196 | salt.cmdRun(pepperEnv, HOST, "ceph-volume lvm zap `readlink /var/lib/ceph/osd/ceph-${id}/block` --destroy") |
| 197 | } |
| 198 | catch (Exception e) { |
| 199 | common.infoMsg(e) |
| 200 | } |
| 201 | } |
| 202 | if (data_partition_uuid?.trim()) { |
| 203 | ceph.removePartition(pepperEnv, HOST, data_partition_uuid, 'data', id) |
| 204 | } |
Jiri Broulik | a5bc8f6 | 2018-01-31 15:04:40 +0100 | [diff] [blame] | 205 | } |
Jiri Broulik | eb7b82f | 2017-11-30 13:55:40 +0100 | [diff] [blame] | 206 | } |
| 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) |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 213 | salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 214 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
Tomek Jaroszyk | 933011a | 2020-04-07 11:20:31 +0200 | [diff] [blame] | 218 | } |