blob: e461363ead99a49f38f8bd1706a3ed8a9c1b9c30 [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(',')
Mateusz Los1535aa22020-05-11 10:33:58 +020025def cleanDisk = CLEANDISK
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020026
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node("python") {
Jiri Broulik96c867a2017-11-07 16:14:10 +010029
Jakub Josefa63f9862018-01-11 17:58:38 +010030 // create connection to salt master
31 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020032
Jakub Josefa63f9862018-01-11 17:58:38 +010033 if (flags.size() > 0) {
34 stage('Set cluster flags') {
35 for (flag in flags) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040036 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +010037 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020038 }
39 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020040
Jakub Josefa63f9862018-01-11 17:58:38 +010041 def osd_ids = []
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020042
Mateusz Losb5663e62020-05-11 09:51:13 +020043 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 Josefa63f9862018-01-11 17:58:38 +010049 // get list of osd disks of the host
50 salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.sync_grains', [], null, true, 5)
Jiri Broulika5bc8f62018-01-31 15:04:40 +010051 def cephGrain = salt.getGrain(pepperEnv, HOST, 'ceph')
52
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040053 if (cephGrain['return'].isEmpty()) {
Jakub Josefed670ca2018-01-18 14:22:20 +010054 throw new Exception("Ceph salt grain cannot be found!")
55 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +010056 common.print(cephGrain)
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +020057 def ceph_disks = cephGrain['return'][0].values()[0].values()[0]['ceph_disk']
Jakub Josefa63f9862018-01-11 17:58:38 +010058 common.prettyPrint(ceph_disks)
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020059
Jakub Josefa63f9862018-01-11 17:58:38 +010060 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 Broulikeb7b82f2017-11-30 13:55:40 +010067 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +010068 }
Jakub Josefa63f9862018-01-11 17:58:38 +010069
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040070 if (osd_ids == []) {
71 currentBuild.result = 'SUCCESS'
72 return
Jakub Josefa63f9862018-01-11 17:58:38 +010073 }
74
75 // `ceph osd out <id> <id>`
76 stage('Set OSDs out') {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040077 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd out ' + osd_ids.join(' '))
Jakub Josefa63f9862018-01-11 17:58:38 +010078 }
79
80 // wait for healthy cluster
Jakub Josefed670ca2018-01-18 14:22:20 +010081 if (WAIT_FOR_HEALTHY.toBoolean()) {
Jakub Josefa63f9862018-01-11 17:58:38 +010082 sleep(5)
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040083 ceph.waitForHealthy(pepperEnv, ADMIN_HOST)
Jakub Josefa63f9862018-01-11 17:58:38 +010084 }
85
86 // stop osd daemons
87 stage('Stop OSD daemons') {
88 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040089 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010090 }
91 }
92
93 // `ceph osd crush remove osd.2`
94 stage('Remove OSDs from CRUSH') {
95 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040096 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd crush remove ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +010097 }
98 }
99
100 // remove keyring `ceph auth del osd.3`
101 stage('Remove OSD keyrings from auth') {
102 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400103 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph auth del ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +0100104 }
105 }
106
107 // remove osd `ceph osd rm osd.3`
108 stage('Remove OSDs') {
109 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400110 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd rm ' + i)
Jakub Josefa63f9862018-01-11 17:58:38 +0100111 }
112 }
113
114 for (osd_id in osd_ids) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 id = osd_id.replaceAll('osd.', '')
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100116
Jakub Josefa63f9862018-01-11 17:58:38 +0100117 // remove journal, block_db, block_wal partition `parted /dev/sdj rm 3`
118 stage('Remove journal / block_db / block_wal partition') {
119 def partition_uuid = ""
120 def journal_partition_uuid = ""
121 def block_db_partition_uuid = ""
122 def block_wal_partition_uuid = ""
123 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400124 journal_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/journal_uuid")['return'][0].values()[0].split("\n")[0]
Mateusz Los1535aa22020-05-11 10:33:58 +0200125 }
126 catch (Exception e) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100127 common.infoMsg(e)
128 }
129 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400130 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 Los1535aa22020-05-11 10:33:58 +0200131 }
132 catch (Exception e) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100133 common.infoMsg(e)
134 }
135
136 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400137 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 Los1535aa22020-05-11 10:33:58 +0200138 }
139 catch (Exception e) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 common.infoMsg(e)
141 }
142
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100143 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 if (journal_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400145 ceph.removePartition(pepperEnv, HOST, journal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100147 if (block_db_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400148 ceph.removePartition(pepperEnv, HOST, block_db_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100149 }
150 if (block_wal_partition_uuid?.trim()) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400151 ceph.removePartition(pepperEnv, HOST, block_wal_partition_uuid)
Jakub Josefa63f9862018-01-11 17:58:38 +0100152 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100153
154 try {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400155 salt.cmdRun(pepperEnv, HOST, "partprobe")
Mateusz Los1535aa22020-05-11 10:33:58 +0200156 }
157 catch (Exception e) {
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100158 common.warningMsg(e)
159 }
160 }
Mateusz Los1535aa22020-05-11 10:33:58 +0200161 if (cleanDisk) {
162 // remove data / block / lockbox partition `parted /dev/sdj rm 3`
163 stage('Remove data / block / lockbox partition') {
164 def data_partition_uuid = ""
165 def block_partition_uuid = ""
166 def osd_fsid = ""
167 def lvm = ""
168 def lvm_enabled= salt.getPillar(pepperEnv,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true)
169 try {
170 osd_fsid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/fsid")['return'][0].values()[0].split("\n")[0]
171 if (lvm_enabled) {
172 lvm = salt.runSaltCommand(pepperEnv, 'local', ['expression': HOST, 'type': 'compound'], 'cmd.run', null, "salt-call lvm.lvdisplay --output json -l quiet")['return'][0].values()[0]
173 lvm = new groovy.json.JsonSlurperClassic().parseText(lvm)
174 lvm["local"].each { lv, params ->
175 if (params["Logical Volume Name"].contains(osd_fsid)) {
176 data_partition_uuid = params["Logical Volume Name"].minus("/dev/")
177 }
mjedynskiaf258b02019-12-09 15:17:58 +0100178 }
179 }
180 }
Mateusz Los1535aa22020-05-11 10:33:58 +0200181 catch (Exception e) {
182 common.infoMsg(e)
183 }
184 try {
185 block_partition_uuid = salt.cmdRun(pepperEnv, HOST, "cat /var/lib/ceph/osd/ceph-${id}/block_uuid")['return'][0].values()[0].split("\n")[0]
186 }
187 catch (Exception e) {
188 common.infoMsg(e)
189 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100190
Mateusz Los1535aa22020-05-11 10:33:58 +0200191 // remove partition_uuid = 2c76f144-f412-481e-b150-4046212ca932
192 if (block_partition_uuid?.trim()) {
193 ceph.removePartition(pepperEnv, HOST, block_partition_uuid)
194 try{
195 salt.cmdRun(pepperEnv, HOST, "ceph-volume lvm zap `readlink /var/lib/ceph/osd/ceph-${id}/block` --destroy")
196 }
197 catch (Exception e) {
198 common.infoMsg(e)
199 }
200 }
201 if (data_partition_uuid?.trim()) {
202 ceph.removePartition(pepperEnv, HOST, data_partition_uuid, 'data', id)
203 }
Jiri Broulika5bc8f62018-01-31 15:04:40 +0100204 }
Jiri Broulikeb7b82f2017-11-30 13:55:40 +0100205 }
206 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100207 // remove cluster flags
208 if (flags.size() > 0) {
209 stage('Unset cluster flags') {
210 for (flag in flags) {
211 common.infoMsg('Removing flag ' + flag)
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400212 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +0100213 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200214 }
215 }
216 }
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +0200217}