blob: 0471f9f1ae089722c48d8d18c09dc36009f2d34c [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
10 * ADMIN_HOST Host (minion id) with admin keyring
11 * CLUSTER_FLAGS Comma separated list of tags to apply to cluster
12 * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons
13 *
14 */
15
16common = new com.mirantis.mk.Common()
17salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020018def python = new com.mirantis.mk.Python()
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020019
chnyda625f4b42017-10-11 14:10:31 +020020def pepperEnv = "pepperEnv"
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020021def flags = CLUSTER_FLAGS.tokenize(',')
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020022def osds = OSD.tokenize(',')
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020023
24def runCephCommand(master, cmd) {
25 return salt.cmdRun(master, ADMIN_HOST, cmd)
26}
27
28node("python") {
29
30 // create connection to salt master
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070031 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020032
33 if (flags.size() > 0) {
34 stage('Set cluster flags') {
35 for (flag in flags) {
chnyda625f4b42017-10-11 14:10:31 +020036 runCephCommand(pepperEnv, 'ceph osd set ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020037 }
38 }
39 }
40
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020041 def osd_ids = []
42
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020043 print("osds:")
44 print(osds)
45
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020046 // get list of osd disks of the host
47 def ceph_disks = salt.getGrain(pepperEnv, HOST, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk']
48 common.prettyPrint(ceph_disks)
49
50 for (i in ceph_disks) {
51 def osd_id = i.getKey().toString()
Tomáš Kukrál00e06912017-08-16 13:33:12 +020052 if (osd_id in osds || OSD == '*') {
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020053 osd_ids.add('osd.' + osd_id)
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020054 print("Will delete " + osd_id)
55 } else {
56 print("Skipping " + osd_id)
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020057 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020058 }
59
60 // `ceph osd out <id> <id>`
61 stage('Set OSDs out') {
chnyda625f4b42017-10-11 14:10:31 +020062 runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' '))
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020063 }
64
65 // wait for healthy cluster
66 if (common.validInputParam('WAIT_FOR_HEALTHY') && WAIT_FOR_HEALTHY.toBoolean()) {
67 stage('Waiting for healthy cluster') {
68 while (true) {
chnyda625f4b42017-10-11 14:10:31 +020069 def health = runCephCommand(pepperEnv, 'ceph health')['return'][0].values()[0]
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020070 if (health.contains('HEALTH OK')) {
71 common.infoMsg('Cluster is healthy')
72 break;
73 }
74 sleep(60)
75 }
76 }
77 }
78
79 // stop osd daemons
80 stage('Stop OSD daemons') {
81 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020082 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020083 }
84 }
85
86 // `ceph osd crush remove osd.2`
87 stage('Remove OSDs from CRUSH') {
88 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020089 runCephCommand(pepperEnv, 'ceph osd crush remove ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020090 }
91 }
92
93 // remove keyring `ceph auth del osd.3`
94 stage('Remove OSD keyrings from auth') {
95 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020096 runCephCommand(pepperEnv, 'ceph auth del ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020097 }
98 }
99
100 // remove osd `ceph osd rm osd.3`
101 stage('Remove OSDs') {
102 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +0200103 runCephCommand(pepperEnv, 'ceph osd rm ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200104 }
105 }
106
107 // remove cluster flags
108 if (flags.size() > 0) {
109 stage('Unset cluster flags') {
110 for (flag in flags) {
111 common.infoMsg('Removing flag ' + flag)
chnyda625f4b42017-10-11 14:10:31 +0200112 runCephCommand(pepperEnv, 'ceph osd unset ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200113 }
114 }
115 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200116}