blob: c51292e3520f3e73ad30de9ad9926aab6f9b278a [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
Jiri Broulik96c867a2017-11-07 16:14:10 +010029def waitForHealthy(master, count=0, attempts=300) {
30 // wait for healthy cluster
31 while (count<attempts) {
32 def health = runCephCommand(master, ADMIN_HOST, 'ceph health')['return'][0].values()[0]
33 if (health.contains('HEALTH_OK')) {
34 common.infoMsg('Cluster is healthy')
35 break;
36 }
37 count++
38 sleep(10)
39 }
40}
41
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020042node("python") {
43
44 // create connection to salt master
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070045 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020046
47 if (flags.size() > 0) {
48 stage('Set cluster flags') {
49 for (flag in flags) {
chnyda625f4b42017-10-11 14:10:31 +020050 runCephCommand(pepperEnv, 'ceph osd set ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020051 }
52 }
53 }
54
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020055 def osd_ids = []
56
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020057 print("osds:")
58 print(osds)
59
Jiri Broulikadc7ecd2017-10-18 06:59:27 +020060 // get list of osd disks of the host
61 def ceph_disks = salt.getGrain(pepperEnv, HOST, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk']
62 common.prettyPrint(ceph_disks)
63
64 for (i in ceph_disks) {
65 def osd_id = i.getKey().toString()
Tomáš Kukrál00e06912017-08-16 13:33:12 +020066 if (osd_id in osds || OSD == '*') {
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020067 osd_ids.add('osd.' + osd_id)
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020068 print("Will delete " + osd_id)
69 } else {
70 print("Skipping " + osd_id)
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020071 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020072 }
73
74 // `ceph osd out <id> <id>`
75 stage('Set OSDs out') {
Jiri Broulikdc87d722017-11-03 15:43:22 +010076 runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' '))
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020077 }
78
79 // wait for healthy cluster
Jiri Broulik99887c82017-10-31 09:27:52 +010080 if (WAIT_FOR_HEALTHY.toBoolean() == true) {
Jiri Broulik96c867a2017-11-07 16:14:10 +010081 sleep(5)
82 waitForHealthy(pepperEnv)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020083 }
84
85 // stop osd daemons
86 stage('Stop OSD daemons') {
87 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020088 salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020089 }
90 }
91
92 // `ceph osd crush remove osd.2`
93 stage('Remove OSDs from CRUSH') {
94 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +020095 runCephCommand(pepperEnv, 'ceph osd crush remove ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020096 }
97 }
98
99 // remove keyring `ceph auth del osd.3`
100 stage('Remove OSD keyrings from auth') {
101 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +0200102 runCephCommand(pepperEnv, 'ceph auth del ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200103 }
104 }
105
106 // remove osd `ceph osd rm osd.3`
107 stage('Remove OSDs') {
108 for (i in osd_ids) {
chnyda625f4b42017-10-11 14:10:31 +0200109 runCephCommand(pepperEnv, 'ceph osd rm ' + i)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200110 }
111 }
112
113 // remove cluster flags
114 if (flags.size() > 0) {
115 stage('Unset cluster flags') {
116 for (flag in flags) {
117 common.infoMsg('Removing flag ' + flag)
chnyda625f4b42017-10-11 14:10:31 +0200118 runCephCommand(pepperEnv, 'ceph osd unset ' + flag)
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200119 }
120 }
121 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +0200122}