blob: 747615f44730576b1e49a0165f92c6f275af5f16 [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') {
chnyda625f4b42017-10-11 14:10:31 +020063 runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' '))
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020064 }
65
66 // wait for healthy cluster
67 if (common.validInputParam('WAIT_FOR_HEALTHY') && WAIT_FOR_HEALTHY.toBoolean()) {
68 stage('Waiting for healthy cluster') {
69 while (true) {
chnyda625f4b42017-10-11 14:10:31 +020070 def health = runCephCommand(pepperEnv, 'ceph health')['return'][0].values()[0]
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020071 if (health.contains('HEALTH OK')) {
72 common.infoMsg('Cluster is healthy')
73 break;
74 }
75 sleep(60)
76 }
77 }
78 }
79
80 // stop osd daemons
81 stage('Stop OSD daemons') {
82 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020083 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020084 }
85 }
86
87 // `ceph osd crush remove osd.2`
88 stage('Remove OSDs from CRUSH') {
89 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020090 runCephCommand(pepperEnv, 'ceph osd crush remove ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020091 }
92 }
93
94 // remove keyring `ceph auth del osd.3`
95 stage('Remove OSD keyrings from auth') {
96 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020097 runCephCommand(pepperEnv, 'ceph auth del ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020098 }
99 }
100
101 // remove osd `ceph osd rm osd.3`
102 stage('Remove OSDs') {
103 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +0200104 runCephCommand(pepperEnv, 'ceph osd rm ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200105 }
106 }
107
108 // remove cluster flags
109 if (flags.size() > 0) {
110 stage('Unset cluster flags') {
111 for (flag in flags) {
112 common.infoMsg('Removing flag ' + flag)
chnyda625f4b42017-10-11 14:10:31 +0200113 runCephCommand(pepperEnv, 'ceph osd unset ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200114 }
115 }
116 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200117}