blob: c5610eb752d325de6a5919d6460ac1ee0444764f [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
17common = new com.mirantis.mk.Common()
18salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020019def python = new com.mirantis.mk.Python()
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020020
chnyda625f4b42017-10-11 14:10:31 +020021def pepperEnv = "pepperEnv"
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020022def flags = CLUSTER_FLAGS.tokenize(',')
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020023def osds = OSD.tokenize(',')
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020024
25def runCephCommand(master, cmd) {
26 return salt.cmdRun(master, ADMIN_HOST, cmd)
27}
28
29node("python") {
30
31 // create connection to salt master
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070032 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020033
34 if (flags.size() > 0) {
35 stage('Set cluster flags') {
36 for (flag in flags) {
chnyda625f4b42017-10-11 14:10:31 +020037 runCephCommand(pepperEnv, 'ceph osd set ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020038 }
39 }
40 }
41
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020042 def osd_ids = []
43
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020044 print("osds:")
45 print(osds)
46
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020047 // get list of osd disks of the host
48 def ceph_disks = salt.getGrain(pepperEnv, HOST, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk']
49 common.prettyPrint(ceph_disks)
50
51 for (i in ceph_disks) {
52 def osd_id = i.getKey().toString()
Tomáš Kukrál00e06912017-08-16 13:33:12 +020053 if (osd_id in osds || OSD == '*') {
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020054 osd_ids.add('osd.' + osd_id)
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020055 print("Will delete " + osd_id)
56 } else {
57 print("Skipping " + osd_id)
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020058 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020059 }
60
61 // `ceph osd out <id> <id>`
62 stage('Set OSDs out') {
Jiri Broulikdc87d722017-11-03 15:43:22 +010063 runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' '))
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020064 }
65
66 // wait for healthy cluster
Jiri Broulik99887c82017-10-31 09:27:52 +010067 if (WAIT_FOR_HEALTHY.toBoolean() == true) {
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020068 stage('Waiting for healthy cluster') {
Jiri Broulikdc87d722017-11-03 15:43:22 +010069 sleep(5)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020070 while (true) {
chnyda625f4b42017-10-11 14:10:31 +020071 def health = runCephCommand(pepperEnv, 'ceph health')['return'][0].values()[0]
Jiri Broulik99887c82017-10-31 09:27:52 +010072 if (health.contains('HEALTH_OK')) {
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020073 common.infoMsg('Cluster is healthy')
74 break;
75 }
Jiri Broulik99887c82017-10-31 09:27:52 +010076 sleep(10)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020077 }
78 }
79 }
80
81 // stop osd daemons
82 stage('Stop OSD daemons') {
83 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020084 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020085 }
86 }
87
88 // `ceph osd crush remove osd.2`
89 stage('Remove OSDs from CRUSH') {
90 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020091 runCephCommand(pepperEnv, 'ceph osd crush remove ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020092 }
93 }
94
95 // remove keyring `ceph auth del osd.3`
96 stage('Remove OSD keyrings from auth') {
97 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020098 runCephCommand(pepperEnv, 'ceph auth del ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020099 }
100 }
101
102 // remove osd `ceph osd rm osd.3`
103 stage('Remove OSDs') {
104 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +0200105 runCephCommand(pepperEnv, 'ceph osd rm ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200106 }
107 }
108
109 // remove cluster flags
110 if (flags.size() > 0) {
111 stage('Unset cluster flags') {
112 for (flag in flags) {
113 common.infoMsg('Removing flag ' + flag)
chnyda625f4b42017-10-11 14:10:31 +0200114 runCephCommand(pepperEnv, 'ceph osd unset ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200115 }
116 }
117 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200118}