blob: 26ed68e607eeb99e6a4ef792462bb332a327e2ed [file] [log] [blame]
Mateusz Losddfa8462019-03-11 14:31:14 +01001/**
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
12common = new com.mirantis.mk.Common()
13salt = new com.mirantis.mk.Salt()
14def python = new com.mirantis.mk.Python()
15orchestrate = new com.mirantis.mk.Orchestrate()
16
17def 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
30def 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
34def getpgmap(master) {
35 return runCephCommand('ceph pg ls remapped --format=json')['return'][0].values()[0]
36}
37
38def 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
57def pepperEnv = "pepperEnv"
58
59timeout(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 {
Mateusz Los0e183112019-04-04 20:10:05 +020067 def admin = salt.getMinions("pepperEnv", "I@ceph:mon and I@ceph:common:keyring:admin")[0]
68 def versions = salt.cmdRun("pepperEnv", admin, "ceph features", checkResponse=true, batch=null, output=false).values()[0]
69
70 if ( versions[0][admin].contains('jewel') )
Mateusz Losddfa8462019-03-11 14:31:14 +010071 {
Mateusz Los0e183112019-04-04 20:10:05 +020072 throw new Exception("Update all clients to luminous before using this pipeline")
Mateusz Losddfa8462019-03-11 14:31:14 +010073 }
74 }
75
76 stage ("enable luminous compat")
77 {
78 runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0]
79 }
80
81 stage ("enable upmap balancer")
82 {
83 runCephCommand('ceph balancer on')['return'][0].values()[0]
84 runCephCommand('ceph balancer mode upmap')['return'][0].values()[0]
85 }
86
87
88 stage ("set norebalance")
89 {
90 runCephCommand('ceph osd set norebalance')['return'][0].values()[0]
91 }
92
93 stage('Install Ceph OSD') {
94 orchestrate.installCephOsd(pepperEnv, HOST)
95 }
96
97 def mapping = []
98
99 stage ("update mappings")
100 {
Mateusz Los0e183112019-04-04 20:10:05 +0200101 def pgmap = getpgmap(pepperEnv)
102 if ( pgmap == '' )
Mateusz Losddfa8462019-03-11 14:31:14 +0100103 {
104 return 1
105 }
106 else
107 {
Mateusz Los0e183112019-04-04 20:10:05 +0200108 pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap)
Mateusz Losddfa8462019-03-11 14:31:14 +0100109 for(int x=1; x<=3; x++){
Mateusz Los0e183112019-04-04 20:10:05 +0200110 pgmap = getpgmap(pepperEnv)
111 if ( pgmap == '' )
112 {
113 return 1
114 }
115 else
116 {
117 pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap)
118 generatemapping(pepperEnv,pgmap,mapping)
119 mapping.each(this.&runCephCommand)
120 }
Mateusz Losddfa8462019-03-11 14:31:14 +0100121 }
122 }
123
124 }
125
126 stage ("unset norebalance")
127 {
128 runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
129 }
130
131 stage ("wait for healthy cluster")
132 {
133 waitForHealthy(pepperEnv)
134 }
135
136 }
137}