blob: 48b975f365a826e36bd8ae527c854b6dbb07fde1 [file] [log] [blame]
Mateusz Losddfa8462019-03-11 14:31:14 +01001/**
2 *
Roman Lubianyied68efd2020-03-13 16:04:09 +02003 * Add Ceph OSD node to existing cluster using upmap mechanism
Mateusz Losddfa8462019-03-11 14:31:14 +01004 *
5 * Requred parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Roman Lubianyied68efd2020-03-13 16:04:09 +02008 * HOST OSD Host (minion id) to be added
Mateusz Losddfa8462019-03-11 14:31:14 +01009 *
10 */
11
Roman Lubianyib797adb2020-04-22 12:36:37 +030012common = new com.mirantis.mk.Common()
Mateusz Losddfa8462019-03-11 14:31:14 +010013salt = new com.mirantis.mk.Salt()
14def python = new com.mirantis.mk.Python()
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040015def ceph = new com.mirantis.mk.Ceph()
Mateusz Losddfa8462019-03-11 14:31:14 +010016orchestrate = new com.mirantis.mk.Orchestrate()
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040017pepperEnv = "pepperEnv"
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040018def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : []
Mateusz Losddfa8462019-03-11 14:31:14 +010019
20def runCephCommand(cmd) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040021 return salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", cmd, checkResponse = true, batch = null, output = false)
Mateusz Losddfa8462019-03-11 14:31:14 +010022}
23
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040024def getpgmap() {
25 return runCephCommand('ceph pg ls remapped --format=json')['return'][0].values()[0]
Mateusz Losddfa8462019-03-11 14:31:14 +010026}
27
28def generatemapping(master,pgmap,map) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040029 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 Losddfa8462019-03-11 14:31:14 +010038 }
Mateusz Losddfa8462019-03-11 14:31:14 +010039}
40
Mateusz Losddfa8462019-03-11 14:31:14 +010041timeout(time: 12, unit: 'HOURS') {
42 node("python") {
Roman Lubianyied68efd2020-03-13 16:04:09 +020043 try {
44 // create connection to salt master
45 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Mateusz Losddfa8462019-03-11 14:31:14 +010046
Tomek Jaroszyk2ea6b2f2020-04-30 14:13:49 +020047 stage ("verification of supported features") {
Roman Lubianyied68efd2020-03-13 16:04:09 +020048 // I@docker:swarm and I@prometheus:server - mon* nodes
49 def nodes = salt.getMinions(pepperEnv, "I@ceph:common and not ( I@docker:swarm and I@prometheus:server )")
50 for ( node in nodes )
51 {
Tomek Jaroszyk2ea6b2f2020-04-30 14:13:49 +020052 def features = salt.cmdRun(pepperEnv, node, "ceph features --format json", checkResponse=true, batch=null, output=false).values()[0]
53 features = new groovy.json.JsonSlurperClassic().parseText(features[0][node])
54 if ( fetures['client']['group']['release'] != 'luminous' )
Roman Lubianyied68efd2020-03-13 16:04:09 +020055 {
Tomek Jaroszyk2ea6b2f2020-04-30 14:13:49 +020056 throw new Exception("client installed on " + node + " does not support upmap. Update all clients to luminous or newer before using this pipeline")
Roman Lubianyied68efd2020-03-13 16:04:09 +020057 }
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040058 }
Mateusz Losddfa8462019-03-11 14:31:14 +010059 }
Mateusz Losddfa8462019-03-11 14:31:14 +010060
Roman Lubianyied68efd2020-03-13 16:04:09 +020061 stage("enable luminous compat") {
62 runCephCommand('ceph osd set-require-min-compat-client luminous')['return'][0].values()[0]
63 }
64
65 stage("enable upmap balancer") {
66 runCephCommand('ceph balancer on')['return'][0].values()[0]
67 runCephCommand('ceph balancer mode upmap')['return'][0].values()[0]
68 }
69
70 stage("set norebalance") {
71 runCephCommand('ceph osd set norebalance')['return'][0].values()[0]
72 }
73
74 stage('Install infra') {
75 orchestrate.installFoundationInfraOnTarget(pepperEnv, HOST)
76 }
77
78 stage('Install Ceph OSD') {
79 orchestrate.installCephOsd(pepperEnv, HOST)
80 }
81
82 stage("Update/Install monitoring") {
83 def prometheusNodes = salt.getMinions(pepperEnv, 'I@prometheus:server')
84 if (!prometheusNodes.isEmpty()) {
85 //Collect Grains
86 salt.enforceState(pepperEnv, HOST, 'salt.minion.grains')
87 salt.runSaltProcessStep(pepperEnv, HOST, 'saltutil.refresh_modules')
88 salt.runSaltProcessStep(pepperEnv, HOST, 'mine.update')
89 sleep(5)
90 salt.enforceState(pepperEnv, HOST, ['fluentd', 'telegraf', 'prometheus'])
91 salt.enforceState(pepperEnv, 'I@prometheus:server', 'prometheus')
92 } else {
93 common.infoMsg('No Prometheus nodes in cluster. Nothing to do')
94 }
95 }
96
97 stage("Update host files") {
98 salt.enforceState(pepperEnv, '*', 'linux.network.host')
99 }
100
101 def mapping = []
102
103 stage("update mappings") {
104 def pgmap
105 for (int x = 1; x <= 3; x++) {
106 pgmap = getpgmap()
107 if (pgmap == '') {
108 return 1
109 } else {
110 pgmap = new groovy.json.JsonSlurperClassic().parseText(pgmap)
111 generatemapping(pepperEnv, pgmap, mapping)
112 mapping.each(this.&runCephCommand)
113 sleep(30)
114 }
115 }
116 }
117
118 stage("unset norebalance") {
119 runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
120 }
121
122 stage("wait for healthy cluster") {
123 ceph.waitForHealthy(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", flags)
124 }
125 }
126 catch (Throwable e) {
127 // There was an error or exception thrown. Unset norebalance.
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400128 runCephCommand('ceph osd unset norebalance')['return'][0].values()[0]
Roman Lubianyied68efd2020-03-13 16:04:09 +0200129 throw e
Mateusz Losddfa8462019-03-11 14:31:14 +0100130 }
Mateusz Losddfa8462019-03-11 14:31:14 +0100131 }
132}