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