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