blob: 447a0316aadb950f4277506f9a70bdb95e9171eb [file] [log] [blame]
Tomáš Kukrálf72096d2017-08-11 12:58:03 +02001/**
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 Broulik2c00f4c2017-10-26 13:23:11 +020010 * OSD Comma separated list of osd ids to be removed
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020011 * 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 Berezovskiy19c685a2019-11-05 17:42:57 +040017def common = new com.mirantis.mk.Common()
18def salt = new com.mirantis.mk.Salt()
19def ceph = new com.mirantis.mk.Ceph()
chnyda625f4b42017-10-11 14:10:31 +020020def python = new com.mirantis.mk.Python()
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020021
chnyda625f4b42017-10-11 14:10:31 +020022def pepperEnv = "pepperEnv"
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020023def flags = CLUSTER_FLAGS.tokenize(',')
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020024def osds = OSD.tokenize(',')
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020025
Jakub Josefa63f9862018-01-11 17:58:38 +010026timeout(time: 12, unit: 'HOURS') {
27 node("python") {
Jiri Broulik96c867a2017-11-07 16:14:10 +010028
Jakub Josefa63f9862018-01-11 17:58:38 +010029 // create connection to salt master
30 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020031
Jakub Josefa63f9862018-01-11 17:58:38 +010032 if (flags.size() > 0) {
33 stage('Set cluster flags') {
34 for (flag in flags) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040035 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +010036 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020037 }
38 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020039
Jakub Josefa63f9862018-01-11 17:58:38 +010040 def osd_ids = []
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020041
Jakub Josefa63f9862018-01-11 17:58:38 +010042 // get list of osd disks of the host
43 salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.sync_grains', [], null, true, 5)
Jiri Broulika5bc8f62018-01-31 15:04:40 +010044 def cephGrain = salt.getGrain(pepperEnv, HOST, 'ceph')
45
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040046 if (cephGrain['return'].isEmpty()) {
Jakub Josefed670ca2018-01-18 14:22:20 +010047 throw new Exception("Ceph salt grain cannot be found!")
48 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +010049 common.print(cephGrain)
mjedynski12955c72019-12-09 15:17:58 +010050 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 Josefa63f9862018-01-11 17:58:38 +010052 common.prettyPrint(ceph_disks)
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020053
Jakub Josefa63f9862018-01-11 17:58:38 +010054 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 Broulikeb7b82f2017-11-30 13:55:40 +010061 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +010062 }
Jakub Josefa63f9862018-01-11 17:58:38 +010063
Mateusz Los31a3bbc2019-03-28 14:12:23 +010064 if ( osd_ids == [] )
65 {
66 currentBuild.result = 'SUCCESS'
67 return
Jakub Josefa63f9862018-01-11 17:58:38 +010068 }
69
70 // `ceph osd out <id> <id>`
71 stage('Set OSDs out') {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040072 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd out ' + osd_ids.join(' '))
Jakub Josefa63f9862018-01-11 17:58:38 +010073 }
74
75 // wait for healthy cluster
Jakub Josefed670ca2018-01-18 14:22:20 +010076 if (WAIT_FOR_HEALTHY.toBoolean()) {
Jakub Josefa63f9862018-01-11 17:58:38 +010077 sleep(5)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040078 ceph.waitForHealthy(pepperEnv, ADMIN_HOST)
Jakub Josefa63f9862018-01-11 17:58:38 +010079 }
80
81 // stop osd daemons
82 stage('Stop OSD daemons') {
83 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040084 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010085 }
86 }
87
88 // `ceph osd crush remove osd.2`
89 stage('Remove OSDs from CRUSH') {
90 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040091 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd crush remove ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +010092 }
93 }
94
95 // remove keyring `ceph auth del osd.3`
96 stage('Remove OSD keyrings from auth') {
97 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040098 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph auth del ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +010099 }
100 }
101
102 // remove osd `ceph osd rm osd.3`
103 stage('Remove OSDs') {
104 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400105 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd rm ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +0100106 }
107 }
108
109 for (osd_id in osd_ids) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100110 id = osd_id.replaceAll('osd.', '')
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 // remove journal, block_db, block_wal partition `parted /dev/sdj rm 3`
113 stage('Remove journal / block_db / block_wal partition') {
114 def partition_uuid = ""
115 def journal_partition_uuid = ""
116 def block_db_partition_uuid = ""
117 def block_wal_partition_uuid = ""
118 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400119 journal_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/journal_uuid")['return'][0].values()[0].split("\n")[0]
Jakub Josefa63f9862018-01-11 17:58:38 +0100120 } catch (Exception e) {
121 common.infoMsg(e)
122 }
123 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400124 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 Josefa63f9862018-01-11 17:58:38 +0100125 } catch (Exception e) {
126 common.infoMsg(e)
127 }
128
129 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400130 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 Josefa63f9862018-01-11 17:58:38 +0100131 } catch (Exception e) {
132 common.infoMsg(e)
133 }
134
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100135 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
Jakub Josefa63f9862018-01-11 17:58:38 +0100136 if (journal_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400137 ceph.removePartition(pepperEnv, HOST, journal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100139 if (block_db_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400140 ceph.removePartition(pepperEnv, HOST, block_db_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 }
142 if (block_wal_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400143 ceph.removePartition(pepperEnv, HOST, block_wal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100145
146 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400147 salt.cmdRun(pepperEnv, HOST, "partprobe")
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100148 } catch (Exception e) {
149 common.warningMsg(e)
150 }
151 }
152
153 // remove data / block / lockbox partition `parted /dev/sdj rm 3`
154 stage('Remove data / block / lockbox partition') {
155 def data_partition_uuid = ""
156 def block_partition_uuid = ""
157 def lockbox_partition_uuid = ""
mjedynski12955c72019-12-09 15:17:58 +0100158 def osd_fsid = ""
159 def lvm = ""
160 def lvm_enabled= salt.getPillar(pepperEnv,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100161 try {
mjedynski12955c72019-12-09 15:17:58 +0100162 osd_fsid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/fsid")['return'][0].values()[0].split("\n")[0]
163 if (lvm_enabled) {
164 lvm = salt.runSaltCommand(pepperEnv, 'local', ['expression': HOST, 'type': 'compound'], 'cmd.run', null, "salt-call lvm.lvdisplay --output json -l quiet")['return'][0].values()[0]
165 lvm = new groovy.json.JsonSlurperClassic().parseText(lvm)
166 lvm["local"].each { lv, params ->
167 if (params["Logical Volume Name"].contains(osd_fsid)) {
168 data_partition_uuid = params["Logical Volume Name"].minus("/dev/")
169 }
170 }
171 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100172 } catch (Exception e) {
173 common.infoMsg(e)
174 }
175 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400176 block_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/block_uuid")['return'][0].values()[0].split("\n")[0]
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100177 } catch (Exception e) {
178 common.infoMsg(e)
179 }
180
181 try {
182 lockbox_partition_uuid = data_partition_uuid
183 } catch (Exception e) {
184 common.infoMsg(e)
185 }
186
187 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
188 if (block_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400189 ceph.removePartition(pepperEnv, HOST, block_partition_uuid)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100190 }
191 if (data_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400192 ceph.removePartition(pepperEnv, HOST, data_partition_uuid, 'data', id)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100193 }
194 if (lockbox_partition_uuid?.trim()) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400195 ceph.removePartition(pepperEnv, HOST, lockbox_partition_uuid, 'lockbox')
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100196 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +0100197 }
198 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100199 // remove cluster flags
200 if (flags.size() > 0) {
201 stage('Unset cluster flags') {
202 for (flag in flags) {
203 common.infoMsg('Removing flag ' + flag)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400204 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +0100205 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200206 }
207 }
208 }
mjedynski12955c72019-12-09 15:17:58 +0100209}