Mateusz Los | 36e64e0 | 2019-03-11 14:31:14 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * |
| 3 | * Add Ceph node to existing cluster using upmap mechanism |
| 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * HOST Host (minion id) to be added |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | common = new com.mirantis.mk.Common() |
| 13 | salt = new com.mirantis.mk.Salt() |
| 14 | def python = new com.mirantis.mk.Python() |
| 15 | orchestrate = new com.mirantis.mk.Orchestrate() |
| 16 | |
| 17 | def waitForHealthy(master, count=0, attempts=100) { |
| 18 | // wait for healthy cluster |
| 19 | while (count<attempts) { |
| 20 | def health = runCephCommand('ceph health')['return'][0].values()[0] |
| 21 | if (health.contains('HEALTH_OK')) { |
| 22 | common.infoMsg('Cluster is healthy') |
| 23 | break; |
| 24 | } |
| 25 | count++ |
| 26 | sleep(10) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | def runCephCommand(cmd) { |
| 31 | return salt.cmdRun("pepperEnv", "I@ceph:mon and I@ceph:common:keyring:admin", cmd, checkResponse=true, batch=null, output=false) |
| 32 | } |
| 33 | |
| 34 | def getpgmap(master) { |
| 35 | return runCephCommand('ceph pg ls remapped --format=json')['return'][0].values()[0] |
| 36 | } |
| 37 | |
| 38 | def generatemapping(master,pgmap,map) { |
| 39 | def pg_new |
| 40 | def pg_old |
| 41 | |
| 42 | for ( pg in pgmap ) |
| 43 | { |
| 44 | |
| 45 | pg_new = pg["up"].minus(pg["acting"]) |
| 46 | pg_old = pg["acting"].minus(pg["up"]) |
| 47 | |
| 48 | for ( i = 0; i < pg_new.size(); i++ ) |
| 49 | { |
| 50 | def string = "ceph osd pg-upmap-items " + pg["pgid"].toString() + " " + pg_new[i] + " " + pg_old[i] + ";" |
| 51 | map.add(string) |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | def pepperEnv = "pepperEnv" |
| 58 | |
| 59 | timeout(time: 12, unit: 'HOURS') { |
| 60 | node("python") { |
| 61 | |
| 62 | // create connection to salt master |
| 63 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 64 | |
| 65 | stage ("verify client versions") |
| 66 | { |
| 67 | def nodes = salt.getMinions("pepperEnv", "I@ceph:common and not E@mon*") |
| 68 | for ( node in nodes ) |
| 69 | { |
| 70 | def versions = salt.cmdRun("pepperEnv", node, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0] |
| 71 | versions = new groovy.json.JsonSlurperClassic().parseText(versions[0][node]) |
| 72 | if ( versions['client']['group']['release'] != 'luminous' ) |
| 73 | { |
| 74 | throw new Exception("client installed on " + node + " is not luminous. Update all clients to luminous before using this pipeline") |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | stage ("enable luminous compat") |
| 80 | { |
| 81 | runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0] |
| 82 | } |
| 83 | |
| 84 | stage ("enable upmap balancer") |
| 85 | { |
| 86 | runCephCommand('ceph balancer on')['return'][0].values()[0] |
| 87 | runCephCommand('ceph balancer mode upmap')['return'][0].values()[0] |
| 88 | } |
| 89 | |
| 90 | |
| 91 | stage ("set norebalance") |
| 92 | { |
| 93 | runCephCommand('ceph osd set norebalance')['return'][0].values()[0] |
| 94 | } |
| 95 | |
| 96 | stage('Install Ceph OSD') { |
| 97 | orchestrate.installCephOsd(pepperEnv, HOST) |
| 98 | } |
| 99 | |
| 100 | def mapping = [] |
| 101 | |
| 102 | stage ("update mappings") |
| 103 | { |
| 104 | def pgmap1 = getpgmap(pepperEnv) |
| 105 | if ( pgmap1 == '' ) |
| 106 | { |
| 107 | return 1 |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | def pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap1) |
| 112 | for(int x=1; x<=3; x++){ |
| 113 | pgmap1 = getpgmap(pepperEnv) |
| 114 | generatemapping(pepperEnv,pgmap,mapping) |
| 115 | mapping.each(this.&runCephCommand) |
| 116 | sleep(30) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | stage ("unset norebalance") |
| 123 | { |
| 124 | runCephCommand('ceph osd unset norebalance')['return'][0].values()[0] |
| 125 | } |
| 126 | |
| 127 | stage ("wait for healthy cluster") |
| 128 | { |
| 129 | waitForHealthy(pepperEnv) |
| 130 | } |
| 131 | |
| 132 | } |
| 133 | } |