Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 1 | /** |
| 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 Broulik | 2c00f4c | 2017-10-26 13:23:11 +0200 | [diff] [blame] | 10 | * OSD Comma separated list of osd ids to be removed |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 11 | * 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 | |
| 17 | common = new com.mirantis.mk.Common() |
| 18 | salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 19 | def python = new com.mirantis.mk.Python() |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 20 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 21 | def pepperEnv = "pepperEnv" |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 22 | def flags = CLUSTER_FLAGS.tokenize(',') |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 23 | def osds = OSD.tokenize(',') |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 24 | |
| 25 | def runCephCommand(master, cmd) { |
| 26 | return salt.cmdRun(master, ADMIN_HOST, cmd) |
| 27 | } |
| 28 | |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame^] | 29 | def 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ál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 42 | node("python") { |
| 43 | |
| 44 | // create connection to salt master |
Dmitrii Kabanov | f31c896 | 2017-10-12 21:00:30 -0700 | [diff] [blame] | 45 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 46 | |
| 47 | if (flags.size() > 0) { |
| 48 | stage('Set cluster flags') { |
| 49 | for (flag in flags) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 50 | runCephCommand(pepperEnv, 'ceph osd set ' + flag) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 55 | def osd_ids = [] |
| 56 | |
Tomáš Kukrál | acadfb5 | 2017-08-18 19:07:42 +0200 | [diff] [blame] | 57 | print("osds:") |
| 58 | print(osds) |
| 59 | |
Jiri Broulik | adc7ecd | 2017-10-18 06:59:27 +0200 | [diff] [blame] | 60 | // 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ál | 00e0691 | 2017-08-16 13:33:12 +0200 | [diff] [blame] | 66 | if (osd_id in osds || OSD == '*') { |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 67 | osd_ids.add('osd.' + osd_id) |
Tomáš Kukrál | acadfb5 | 2017-08-18 19:07:42 +0200 | [diff] [blame] | 68 | print("Will delete " + osd_id) |
| 69 | } else { |
| 70 | print("Skipping " + osd_id) |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 71 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | // `ceph osd out <id> <id>` |
| 75 | stage('Set OSDs out') { |
Jiri Broulik | dc87d72 | 2017-11-03 15:43:22 +0100 | [diff] [blame] | 76 | runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' ')) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // wait for healthy cluster |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 80 | if (WAIT_FOR_HEALTHY.toBoolean() == true) { |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame^] | 81 | sleep(5) |
| 82 | waitForHealthy(pepperEnv) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // stop osd daemons |
| 86 | stage('Stop OSD daemons') { |
| 87 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 88 | salt.runSaltProcessStep(pepperEnv, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | // `ceph osd crush remove osd.2` |
| 93 | stage('Remove OSDs from CRUSH') { |
| 94 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 95 | runCephCommand(pepperEnv, 'ceph osd crush remove ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | // remove keyring `ceph auth del osd.3` |
| 100 | stage('Remove OSD keyrings from auth') { |
| 101 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 102 | runCephCommand(pepperEnv, 'ceph auth del ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | // remove osd `ceph osd rm osd.3` |
| 107 | stage('Remove OSDs') { |
| 108 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 109 | runCephCommand(pepperEnv, 'ceph osd rm ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 110 | } |
| 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) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 118 | runCephCommand(pepperEnv, 'ceph osd unset ' + flag) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 122 | } |