Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 3 | * Add Ceph OSD node to existing cluster using upmap mechanism |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 8 | * HOST OSD Host (minion id) to be added |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 9 | * |
| 10 | */ |
| 11 | |
Roman Lubianyi | 75f6316 | 2020-04-22 12:36:37 +0300 | [diff] [blame] | 12 | common = new com.mirantis.mk.Common() |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 13 | salt = new com.mirantis.mk.Salt() |
| 14 | def python = new com.mirantis.mk.Python() |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 15 | def ceph = new com.mirantis.mk.Ceph() |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 16 | orchestrate = new com.mirantis.mk.Orchestrate() |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 17 | pepperEnv = "pepperEnv" |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 18 | def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : [] |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 19 | |
| 20 | def runCephCommand(cmd) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 21 | return salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", cmd, checkResponse = true, batch = null, output = false) |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 22 | } |
| 23 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 24 | def getpgmap() { |
| 25 | return runCephCommand('ceph pg ls remapped --format=json')['return'][0].values()[0] |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | def generatemapping(master,pgmap,map) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 29 | def pg_new |
| 30 | def pg_old |
Tomek Jaroszyk | 8f976f4 | 2020-08-21 18:40:59 +0200 | [diff] [blame] | 31 | for (pg in pgmap.get('pg_stats',[])) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 32 | pg_new = pg["up"].minus(pg["acting"]) |
| 33 | pg_old = pg["acting"].minus(pg["up"]) |
| 34 | for (i = 0; i < pg_new.size(); i++) { |
| 35 | def string = "ceph osd pg-upmap-items " + pg["pgid"].toString() + " " + pg_new[i] + " " + pg_old[i] + ";" |
| 36 | map.add(string) |
| 37 | } |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 38 | } |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 41 | timeout(time: 12, unit: 'HOURS') { |
| 42 | node("python") { |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 43 | try { |
| 44 | // create connection to salt master |
| 45 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 46 | |
Tomek Jaroszyk | 2c19b7a | 2020-04-30 14:13:49 +0200 | [diff] [blame] | 47 | stage ("verification of supported features") { |
Mateusz Los | 350e1d2 | 2020-05-12 14:33:50 +0200 | [diff] [blame] | 48 | def checknode = salt.runSaltProcessStep(pepperEnv, HOST, 'test.ping') |
| 49 | if (checknode['return'][0].values().isEmpty()) { |
| 50 | common.errorMsg("Host not found") |
| 51 | throw new InterruptedException() |
| 52 | } |
Tomek Jaroszyk | 8f976f4 | 2020-08-21 18:40:59 +0200 | [diff] [blame] | 53 | def cmn = salt.getFirstMinion(pepperEnv, "I@ceph:mon") |
| 54 | def features = salt.cmdRun(pepperEnv, cmn, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0] |
| 55 | |
| 56 | features = new groovy.json.JsonSlurperClassic().parseText(features[0][cmn]) |
| 57 | for ( group in features['client'] ) { |
| 58 | if ( group['release'] != 'luminous' ) { |
| 59 | throw new Exception("Some of installed clients does not support upmap. Update all clients to luminous or newer before using this pipeline") |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 60 | } |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 61 | } |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 62 | } |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 63 | |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 64 | stage("enable luminous compat") { |
| 65 | runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0] |
| 66 | } |
| 67 | |
| 68 | stage("enable upmap balancer") { |
| 69 | runCephCommand('ceph balancer on')['return'][0].values()[0] |
| 70 | runCephCommand('ceph balancer mode upmap')['return'][0].values()[0] |
| 71 | } |
| 72 | |
| 73 | stage("set norebalance") { |
| 74 | runCephCommand('ceph osd set norebalance')['return'][0].values()[0] |
| 75 | } |
| 76 | |
| 77 | stage('Install infra') { |
| 78 | orchestrate.installFoundationInfraOnTarget(pepperEnv, HOST) |
| 79 | } |
| 80 | |
| 81 | stage('Install Ceph OSD') { |
Tomek Jaroszyk | 8f976f4 | 2020-08-21 18:40:59 +0200 | [diff] [blame] | 82 | salt.enforceState(pepperEnv, HOST, 'linux.storage') |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 83 | orchestrate.installCephOsd(pepperEnv, HOST) |
| 84 | } |
| 85 | |
| 86 | stage("Update/Install monitoring") { |
| 87 | def prometheusNodes = salt.getMinions(pepperEnv, 'I@prometheus:server') |
| 88 | if (!prometheusNodes.isEmpty()) { |
| 89 | //Collect Grains |
| 90 | salt.enforceState(pepperEnv, HOST, 'salt.minion.grains') |
| 91 | salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.refresh_modules') |
| 92 | salt.runSaltProcessStep(pepperEnv, HOST, 'mine.update') |
| 93 | sleep(5) |
| 94 | salt.enforceState(pepperEnv, HOST, ['fluentd', 'telegraf', 'prometheus']) |
| 95 | salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus') |
| 96 | } else { |
| 97 | common.infoMsg('No Prometheus nodes in cluster. Nothing to do') |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | stage("Update host files") { |
| 102 | salt.enforceState(pepperEnv, '*', 'linux.network.host') |
| 103 | } |
| 104 | |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 105 | |
| 106 | stage("update mappings") { |
| 107 | def pgmap |
| 108 | for (int x = 1; x <= 3; x++) { |
| 109 | pgmap = getpgmap() |
| 110 | if (pgmap == '') { |
| 111 | return 1 |
| 112 | } else { |
Tomek Jaroszyk | 8f976f4 | 2020-08-21 18:40:59 +0200 | [diff] [blame] | 113 | def mapping = [] |
Roman Lubianyi | af11e53 | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 114 | pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap) |
| 115 | generatemapping(pepperEnv, pgmap, mapping) |
| 116 | mapping.each(this.&runCephCommand) |
| 117 | sleep(30) |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | stage("unset norebalance") { |
| 123 | runCephCommand('ceph osd unset norebalance')['return'][0].values()[0] |
| 124 | } |
| 125 | |
| 126 | stage("wait for healthy cluster") { |
| 127 | ceph.waitForHealthy(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", flags) |
| 128 | } |
| 129 | } |
Tomek Jaroszyk | 6d8a3aa | 2020-07-07 12:07:40 +0200 | [diff] [blame] | 130 | finally { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 131 | runCephCommand('ceph osd unset norebalance')['return'][0].values()[0] |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 132 | } |
Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 133 | } |
| 134 | } |