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 |
| 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 | |
| 16 | common = new com.mirantis.mk.Common() |
| 17 | salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 18 | def python = new com.mirantis.mk.Python() |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 19 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 20 | def pepperEnv = "pepperEnv" |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 21 | def flags = CLUSTER_FLAGS.tokenize(',') |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 22 | def osds = OSD.tokenize(',') |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 23 | |
| 24 | def runCephCommand(master, cmd) { |
| 25 | return salt.cmdRun(master, ADMIN_HOST, cmd) |
| 26 | } |
| 27 | |
| 28 | node("python") { |
| 29 | |
| 30 | // create connection to salt master |
Dmitrii Kabanov | f31c896 | 2017-10-12 21:00:30 -0700 | [diff] [blame] | 31 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 32 | |
| 33 | if (flags.size() > 0) { |
| 34 | stage('Set cluster flags') { |
| 35 | for (flag in flags) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 36 | runCephCommand(pepperEnv, 'ceph osd set ' + flag) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 41 | def osd_ids = [] |
| 42 | |
Tomáš Kukrál | acadfb5 | 2017-08-18 19:07:42 +0200 | [diff] [blame] | 43 | print("osds:") |
| 44 | print(osds) |
| 45 | |
Jiri Broulik | adc7ecd | 2017-10-18 06:59:27 +0200 | [diff] [blame^] | 46 | // 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ál | 00e0691 | 2017-08-16 13:33:12 +0200 | [diff] [blame] | 52 | if (osd_id in osds || OSD == '*') { |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 53 | osd_ids.add('osd.' + osd_id) |
Tomáš Kukrál | acadfb5 | 2017-08-18 19:07:42 +0200 | [diff] [blame] | 54 | print("Will delete " + osd_id) |
| 55 | } else { |
| 56 | print("Skipping " + osd_id) |
Tomáš Kukrál | 9d6228b | 2017-08-15 16:54:55 +0200 | [diff] [blame] | 57 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // `ceph osd out <id> <id>` |
| 61 | stage('Set OSDs out') { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 62 | runCephCommand(pepperEnv, 'ceph osd out ' + osd_ids.join(' ')) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 63 | } |
| 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) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 69 | def health = runCephCommand(pepperEnv, 'ceph health')['return'][0].values()[0] |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 70 | 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) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 82 | 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] | 83 | } |
| 84 | } |
| 85 | |
| 86 | // `ceph osd crush remove osd.2` |
| 87 | stage('Remove OSDs from CRUSH') { |
| 88 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 89 | runCephCommand(pepperEnv, 'ceph osd crush remove ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | // remove keyring `ceph auth del osd.3` |
| 94 | stage('Remove OSD keyrings from auth') { |
| 95 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 96 | runCephCommand(pepperEnv, 'ceph auth del ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | // remove osd `ceph osd rm osd.3` |
| 101 | stage('Remove OSDs') { |
| 102 | for (i in osd_ids) { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 103 | runCephCommand(pepperEnv, 'ceph osd rm ' + i) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 104 | } |
| 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) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 112 | runCephCommand(pepperEnv, 'ceph osd unset ' + flag) |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | } |
Tomáš Kukrál | f72096d | 2017-08-11 12:58:03 +0200 | [diff] [blame] | 116 | } |