blob: 4bbb78dc1ba4d8a3fc762aead9cfffe8473bec01 [file] [log] [blame]
Mateusz Los36e64e02019-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 {
Denis Egorenkoe983d452019-08-23 14:29:34 +040067 // I@docker:swarm and I@prometheus:server - mon* nodes
68 def nodes = salt.getMinions("pepperEnv", "I@ceph:common and not ( I@docker:swarm and I@prometheus:server )")
Mateusz Los36e64e02019-03-11 14:31:14 +010069 for ( node in nodes )
70 {
71 def versions = salt.cmdRun("pepperEnv", node, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0]
72 versions = new groovy.json.JsonSlurperClassic().parseText(versions[0][node])
73 if ( versions['client']['group']['release'] != 'luminous' )
74 {
75 throw new Exception("client installed on " + node + " is not luminous. Update all clients to luminous before using this pipeline")
76 }
77 }
78 }
79
80 stage ("enable luminous compat")
81 {
82 runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0]
83 }
84
85 stage ("enable upmap balancer")
86 {
87 runCephCommand('ceph balancer on')['return'][0].values()[0]
88 runCephCommand('ceph balancer mode upmap')['return'][0].values()[0]
89 }
90
91
92 stage ("set norebalance")
93 {
94 runCephCommand('ceph osd set norebalance')['return'][0].values()[0]
95 }
96
97 stage('Install Ceph OSD') {
98 orchestrate.installCephOsd(pepperEnv, HOST)
99 }
100
101 def mapping = []
102
103 stage ("update mappings")
104 {
105 def pgmap1 = getpgmap(pepperEnv)
106 if ( pgmap1 == '' )
107 {
108 return 1
109 }
110 else
111 {
112 def pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap1)
113 for(int x=1; x<=3; x++){
114 pgmap1 = getpgmap(pepperEnv)
115 generatemapping(pepperEnv,pgmap,mapping)
116 mapping.each(this.&runCephCommand)
117 sleep(30)
118 }
119 }
120
121 }
122
123 stage ("unset norebalance")
124 {
125 runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
126 }
127
128 stage ("wait for healthy cluster")
129 {
130 waitForHealthy(pepperEnv)
131 }
132
133 }
134}