Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
Roman Lubianyi | ed68efd | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 3 | * Add Ceph OSD node to existing cluster using upmap mechanism |
Mateusz Los | ddfa846 | 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 | ed68efd | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 8 | * HOST OSD Host (minion id) to be added |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 9 | * |
| 10 | */ |
| 11 | |
Roman Lubianyi | b797adb | 2020-04-22 12:36:37 +0300 | [diff] [blame^] | 12 | common = new com.mirantis.mk.Common() |
Mateusz Los | ddfa846 | 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 | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 15 | def ceph = new com.mirantis.mk.Ceph() |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 16 | orchestrate = new com.mirantis.mk.Orchestrate() |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 17 | pepperEnv = "pepperEnv" |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 18 | def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : [] |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 19 | |
| 20 | def runCephCommand(cmd) { |
Ivan Berezovskiy | 2325dcb | 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 | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 22 | } |
| 23 | |
Ivan Berezovskiy | 2325dcb | 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 | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | def generatemapping(master,pgmap,map) { |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 29 | def pg_new |
| 30 | def pg_old |
| 31 | for (pg in pgmap) { |
| 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 | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 38 | } |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 41 | timeout(time: 12, unit: 'HOURS') { |
| 42 | node("python") { |
Roman Lubianyi | ed68efd | 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 | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 46 | |
Roman Lubianyi | ed68efd | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 47 | stage ("verify client versions") |
| 48 | { |
| 49 | // I@docker:swarm and I@prometheus:server - mon* nodes |
| 50 | def nodes = salt.getMinions(pepperEnv, "I@ceph:common and not ( I@docker:swarm and I@prometheus:server )") |
| 51 | for ( node in nodes ) |
| 52 | { |
| 53 | def versions = salt.cmdRun(pepperEnv, node, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0] |
| 54 | versions = new groovy.json.JsonSlurperClassic().parseText(versions[0][node]) |
| 55 | if ( versions['client']['group']['release'] != 'luminous' ) |
| 56 | { |
| 57 | throw new Exception("client installed on " + node + " is not luminous. Update all clients to luminous before using this pipeline") |
| 58 | } |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 59 | } |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 60 | } |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 61 | |
Roman Lubianyi | ed68efd | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 62 | stage("enable luminous compat") { |
| 63 | runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0] |
| 64 | } |
| 65 | |
| 66 | stage("enable upmap balancer") { |
| 67 | runCephCommand('ceph balancer on')['return'][0].values()[0] |
| 68 | runCephCommand('ceph balancer mode upmap')['return'][0].values()[0] |
| 69 | } |
| 70 | |
| 71 | stage("set norebalance") { |
| 72 | runCephCommand('ceph osd set norebalance')['return'][0].values()[0] |
| 73 | } |
| 74 | |
| 75 | stage('Install infra') { |
| 76 | orchestrate.installFoundationInfraOnTarget(pepperEnv, HOST) |
| 77 | } |
| 78 | |
| 79 | stage('Install Ceph OSD') { |
| 80 | orchestrate.installCephOsd(pepperEnv, HOST) |
| 81 | } |
| 82 | |
| 83 | stage("Update/Install monitoring") { |
| 84 | def prometheusNodes = salt.getMinions(pepperEnv, 'I@prometheus:server') |
| 85 | if (!prometheusNodes.isEmpty()) { |
| 86 | //Collect Grains |
| 87 | salt.enforceState(pepperEnv, HOST, 'salt.minion.grains') |
| 88 | salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.refresh_modules') |
| 89 | salt.runSaltProcessStep(pepperEnv, HOST, 'mine.update') |
| 90 | sleep(5) |
| 91 | salt.enforceState(pepperEnv, HOST, ['fluentd', 'telegraf', 'prometheus']) |
| 92 | salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus') |
| 93 | } else { |
| 94 | common.infoMsg('No Prometheus nodes in cluster. Nothing to do') |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | stage("Update host files") { |
| 99 | salt.enforceState(pepperEnv, '*', 'linux.network.host') |
| 100 | } |
| 101 | |
| 102 | def mapping = [] |
| 103 | |
| 104 | stage("update mappings") { |
| 105 | def pgmap |
| 106 | for (int x = 1; x <= 3; x++) { |
| 107 | pgmap = getpgmap() |
| 108 | if (pgmap == '') { |
| 109 | return 1 |
| 110 | } else { |
| 111 | pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap) |
| 112 | generatemapping(pepperEnv, pgmap, mapping) |
| 113 | mapping.each(this.&runCephCommand) |
| 114 | sleep(30) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | stage("unset norebalance") { |
| 120 | runCephCommand('ceph osd unset norebalance')['return'][0].values()[0] |
| 121 | } |
| 122 | |
| 123 | stage("wait for healthy cluster") { |
| 124 | ceph.waitForHealthy(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", flags) |
| 125 | } |
| 126 | } |
| 127 | catch (Throwable e) { |
| 128 | // There was an error or exception thrown. Unset norebalance. |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 129 | runCephCommand('ceph osd unset norebalance')['return'][0].values()[0] |
Roman Lubianyi | ed68efd | 2020-03-13 16:04:09 +0200 | [diff] [blame] | 130 | throw e |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 131 | } |
Mateusz Los | ddfa846 | 2019-03-11 14:31:14 +0100 | [diff] [blame] | 132 | } |
| 133 | } |