blob: b177ad32294f03b8cae5a087c352b7de5531d31e [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 Berezovskiy2325dcb2019-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 Berezovskiy2325dcb2019-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
Mateusz Losb5663e62020-05-11 09:51:13 +020042 def checknode = salt.runSaltProcessStep(pepperEnv, HOST, 'test.ping')
43 if (checknode['return'][0].values().isEmpty()) {
44 common.errorMsg("Host not found")
45 throw new InterruptedException()
46 }
47
Jakub Josefa63f9862018-01-11 17:58:38 +010048 // get list of osd disks of the host
49 salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.sync_grains', [], null, true, 5)
Jiri Broulika5bc8f62018-01-31 15:04:40 +010050 def cephGrain = salt.getGrain(pepperEnv, HOST, 'ceph')
51
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040052 if (cephGrain['return'].isEmpty()) {
Jakub Josefed670ca2018-01-18 14:22:20 +010053 throw new Exception("Ceph salt grain cannot be found!")
54 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +010055 common.print(cephGrain)
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +020056 def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk']
Jakub Josefa63f9862018-01-11 17:58:38 +010057 common.prettyPrint(ceph_disks)
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020058
Jakub Josefa63f9862018-01-11 17:58:38 +010059 for (i in ceph_disks) {
60 def osd_id = i.getKey().toString()
61 if (osd_id in osds || OSD == '*') {
62 osd_ids.add('osd.' + osd_id)
63 print("Will delete " + osd_id)
64 } else {
65 print("Skipping " + osd_id)
Jiri Broulikeb7b82f2017-11-30 13:55:40 +010066 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +010067 }
Jakub Josefa63f9862018-01-11 17:58:38 +010068
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040069 if (osd_ids == []) {
70 currentBuild.result = 'SUCCESS'
71 return
Jakub Josefa63f9862018-01-11 17:58:38 +010072 }
73
74 // `ceph osd out <id> <id>`
75 stage('Set OSDs out') {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040076 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd out ' + osd_ids.join(' '))
Jakub Josefa63f9862018-01-11 17:58:38 +010077 }
78
79 // wait for healthy cluster
Jakub Josefed670ca2018-01-18 14:22:20 +010080 if (WAIT_FOR_HEALTHY.toBoolean()) {
Jakub Josefa63f9862018-01-11 17:58:38 +010081 sleep(5)
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040082 ceph.waitForHealthy(pepperEnv, ADMIN_HOST)
Jakub Josefa63f9862018-01-11 17:58:38 +010083 }
84
85 // stop osd daemons
86 stage('Stop OSD daemons') {
87 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040088 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010089 }
90 }
91
92 // `ceph osd crush remove osd.2`
93 stage('Remove OSDs from CRUSH') {
94 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040095 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd crush remove ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +010096 }
97 }
98
99 // remove keyring `ceph auth del osd.3`
100 stage('Remove OSD keyrings from auth') {
101 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400102 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph auth del ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 }
104 }
105
106 // remove osd `ceph osd rm osd.3`
107 stage('Remove OSDs') {
108 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400109 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd rm ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +0100110 }
111 }
112
113 for (osd_id in osd_ids) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100114 id = osd_id.replaceAll('osd.', '')
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100115
Jakub Josefa63f9862018-01-11 17:58:38 +0100116 // remove journal, block_db, block_wal partition `parted /dev/sdj rm 3`
117 stage('Remove journal / block_db / block_wal partition') {
118 def partition_uuid = ""
119 def journal_partition_uuid = ""
120 def block_db_partition_uuid = ""
121 def block_wal_partition_uuid = ""
122 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400123 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 +0100124 } catch (Exception e) {
125 common.infoMsg(e)
126 }
127 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400128 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 +0100129 } catch (Exception e) {
130 common.infoMsg(e)
131 }
132
133 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400134 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 +0100135 } catch (Exception e) {
136 common.infoMsg(e)
137 }
138
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100139 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 if (journal_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400141 ceph.removePartition(pepperEnv, HOST, journal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100142 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100143 if (block_db_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400144 ceph.removePartition(pepperEnv, HOST, block_db_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100145 }
146 if (block_wal_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400147 ceph.removePartition(pepperEnv, HOST, block_wal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100148 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100149
150 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400151 salt.cmdRun(pepperEnv, HOST, "partprobe")
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100152 } catch (Exception e) {
153 common.warningMsg(e)
154 }
155 }
156
157 // remove data / block / lockbox partition `parted /dev/sdj rm 3`
158 stage('Remove data / block / lockbox partition') {
159 def data_partition_uuid = ""
160 def block_partition_uuid = ""
mjedynskiaf258b02019-12-09 15:17:58 +0100161 def osd_fsid = ""
162 def lvm = ""
163 def lvm_enabled= salt.getPillar(pepperEnv,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100164 try {
mjedynskiaf258b02019-12-09 15:17:58 +0100165 osd_fsid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/fsid")['return'][0].values()[0].split("\n")[0]
166 if (lvm_enabled) {
167 lvm = salt.runSaltCommand(pepperEnv, 'local', ['expression': HOST, 'type': 'compound'], 'cmd.run', null, "salt-call lvm.lvdisplay --output json -l quiet")['return'][0].values()[0]
168 lvm = new groovy.json.JsonSlurperClassic().parseText(lvm)
169 lvm["local"].each { lv, params ->
170 if (params["Logical Volume Name"].contains(osd_fsid)) {
171 data_partition_uuid = params["Logical Volume Name"].minus("/dev/")
172 }
173 }
174 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100175 } catch (Exception e) {
176 common.infoMsg(e)
177 }
178 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400179 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 +0100180 } catch (Exception e) {
181 common.infoMsg(e)
182 }
183
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100184 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
185 if (block_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400186 ceph.removePartition(pepperEnv, HOST, block_partition_uuid)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100187 }
188 if (data_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400189 ceph.removePartition(pepperEnv, HOST, data_partition_uuid, 'data', id)
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100190 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +0100191 }
192 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100193 // remove cluster flags
194 if (flags.size() > 0) {
195 stage('Unset cluster flags') {
196 for (flag in flags) {
197 common.infoMsg('Removing flag ' + flag)
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400198 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +0100199 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200200 }
201 }
202 }
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +0200203}