blob: fd0c8214987570dccfd5f5b6435eeea74bde112d [file] [log] [blame]
Jiri Broulikdc87d722017-11-03 15:43:22 +01001/**
2 *
3 * Upgrade Ceph mon/mgr/osd/rgw/client
4 *
5 * Requred parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 * ADMIN_HOST Host (minion id) with admin keyring and /etc/crushmap file present
10 * CLUSTER_FLAGS Comma separated list of tags to apply to cluster
11 * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons
12 * ORIGIN_RELEASE Ceph release version before upgrade
13 * TARGET_RELEASE Ceph release version after upgrade
14 * STAGE_UPGRADE_MON Set to True if Ceph mon nodes upgrade is desired
15 * STAGE_UPGRADE_MGR Set to True if Ceph mgr nodes upgrade or new deploy is desired
16 * STAGE_UPGRADE_OSD Set to True if Ceph osd nodes upgrade is desired
17 * STAGE_UPGRADE_RGW Set to True if Ceph rgw nodes upgrade is desired
18 * STAGE_UPGRADE_CLIENT Set to True if Ceph client nodes upgrade is desired (includes for example ctl/cmp nodes)
Michael Vollmanafe91522019-05-07 08:10:00 -040019 * STAGE_FINALIZE Set to True if configs recommended for TARGET_RELEASE should be set after upgrade is done
20 * BACKUP_ENABLED Select to copy the disks of Ceph VMs before upgrade and backup Ceph directories on OSD nodes
21 * BACKUP_DIR Select the target dir to backup to when BACKUP_ENABLED
Jiri Broulikdc87d722017-11-03 15:43:22 +010022 *
23 */
24
25common = new com.mirantis.mk.Common()
26salt = new com.mirantis.mk.Salt()
27def python = new com.mirantis.mk.Python()
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040028ceph = new com.mirantis.mk.Ceph()
Jiri Broulikdc87d722017-11-03 15:43:22 +010029
Tomek Jaroszykb7c88d52020-08-18 10:21:54 +020030pepperEnv = "pepperEnv"
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040031flags = CLUSTER_FLAGS.tokenize(',')
Jiri Broulikdc87d722017-11-03 15:43:22 +010032
Mateusz Losc5de5c82020-05-11 10:37:23 +020033def runHighState = RUNHIGHSTATE
34
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040035def backup(master, target) {
Jiri Broulik96c867a2017-11-07 16:14:10 +010036 stage("backup ${target}") {
37
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010038 if (target == 'osd') {
Jiri Broulik96c867a2017-11-07 16:14:10 +010039 try {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010040 salt.enforceState(master, "I@ceph:${target}", "ceph.backup", true)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040041 salt.cmdRun(master, "I@ceph:${target}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh'")
Jiri Broulik96c867a2017-11-07 16:14:10 +010042 } catch (Exception e) {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010043 common.errorMsg(e)
44 common.errorMsg("Make sure Ceph backup on OSD nodes is enabled")
45 throw new InterruptedException()
Jiri Broulik96c867a2017-11-07 16:14:10 +010046 }
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010047 } else {
48 def _pillar = salt.getGrain(master, 'I@salt:master', 'domain')
49 def domain = _pillar['return'][0].values()[0].values()[0]
50
51 def kvm_pillar = salt.getGrain(master, 'I@salt:control', 'id')
52 def kvm01 = kvm_pillar['return'][0].values()[0].values()[0]
53
54 def target_pillar = salt.getGrain(master, "I@ceph:${target}", 'host')
55 def minions = target_pillar['return'][0].values()
56 for (minion in minions) {
57 def minion_name = minion.values()[0]
58 def provider_pillar = salt.getPillar(master, "${kvm01}", "salt:control:cluster:internal:node:${minion_name}:provider")
59 def minionProvider = provider_pillar['return'][0].values()[0]
60
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040061 ceph.waitForHealthy(master, ADMIN_HOST, flags)
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010062 try {
Michael Vollmanafe91522019-05-07 08:10:00 -040063 salt.cmdRun(master, "${minionProvider}", "[ ! -f ${BACKUP_DIR}/${minion_name}.${domain}.qcow2.bak ] && virsh destroy ${minion_name}.${domain}")
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010064 } catch (Exception e) {
65 common.warningMsg('Backup already exists')
66 }
67 try {
Michael Vollmanafe91522019-05-07 08:10:00 -040068 salt.cmdRun(master, "${minionProvider}", "[ ! -f ${BACKUP_DIR}/${minion_name}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${minion_name}.${domain}/system.qcow2 ${BACKUP_DIR}/${minion_name}.${domain}.qcow2.bak")
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010069 } catch (Exception e) {
70 common.warningMsg('Backup already exists')
71 }
72 try {
73 salt.cmdRun(master, "${minionProvider}", "virsh start ${minion_name}.${domain}")
74 } catch (Exception e) {
75 common.warningMsg(e)
76 }
77 salt.minionsReachable(master, 'I@salt:master', "${minion_name}*")
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040078 ceph.waitForHealthy(master, ADMIN_HOST, flags)
Jiri Broulik96c867a2017-11-07 16:14:10 +010079 }
Jiri Broulik96c867a2017-11-07 16:14:10 +010080 }
81 }
82 return
83}
84
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040085def upgrade(master, target) {
Jiri Broulikdc87d722017-11-03 15:43:22 +010086
87 stage("Change ${target} repos") {
88 salt.runSaltProcessStep(master, "I@ceph:${target}", 'saltutil.refresh_pillar', [], null, true, 5)
89 salt.enforceState(master, "I@ceph:${target}", 'linux.system.repo', true)
90 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010091 if (target == 'mgr') {
92 stage('Run ceph mgr state') {
Tomek Jaroszyk933011a2020-04-07 11:20:31 +020093 salt.enforceState(master, "I@ceph:mgr", "ceph.mgr", true, failOnError=false, retries=3, retries_wait=10)
Jiri Broulikdc87d722017-11-03 15:43:22 +010094 }
95 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010096 if (target == 'common') {
97 stage('Upgrade ceph-common pkgs') {
Tomek Jaroszyk933011a2020-04-07 11:20:31 +020098 salt.runSaltProcessStep(master, "I@ceph:${target}", 'pkg.install', ["ceph-common"], 'only_upgrade=True')
Jiri Broulikdc87d722017-11-03 15:43:22 +010099 }
100 } else {
Jiri Broulik96c867a2017-11-07 16:14:10 +0100101 minions = salt.getMinions(master, "I@ceph:${target}")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100102
Jiri Broulik96c867a2017-11-07 16:14:10 +0100103 for (minion in minions) {
104 // upgrade pkgs
105 if (target == 'radosgw') {
106 stage('Upgrade radosgw pkgs') {
Tomek Jaroszyk933011a2020-04-07 11:20:31 +0200107 salt.runSaltProcessStep(master, "I@ceph:${target}", 'pkg.install', [target], 'only_upgrade=True')
Jiri Broulik96c867a2017-11-07 16:14:10 +0100108 }
109 } else {
110 stage("Upgrade ${target} pkgs on ${minion}") {
Tomek Jaroszyk933011a2020-04-07 11:20:31 +0200111 salt.runSaltProcessStep(master, "${minion}", 'pkg.install', ["ceph-${target}"], 'only_upgrade=True')
Jiri Broulik96c867a2017-11-07 16:14:10 +0100112 }
113 }
114 // restart services
115 stage("Restart ${target} services on ${minion}") {
Mateusz Losc5de5c82020-05-11 10:37:23 +0200116 if(target == 'osd') {
Tomek Jaroszyk933011a2020-04-07 11:20:31 +0200117 def ceph_disks = salt.getGrain(master, minion, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk']
Mateusz Los80bb9252020-02-06 13:33:42 +0100118 ceph_disks.each { osd, param ->
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400119 salt.cmdRun(master, "${minion}", "systemctl restart ceph-${target}@${osd}")
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400120 }
Mateusz Losc5de5c82020-05-11 10:37:23 +0200121 }
122 else {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400123 salt.cmdRun(master, "${minion}", "systemctl restart ceph-${target}.target")
Mateusz Losc5de5c82020-05-11 10:37:23 +0200124 }
125
126 ceph.waitForHealthy(master, ADMIN_HOST, flags)
127 if(runHighState) {
Tomek Jaroszykb7c88d52020-08-18 10:21:54 +0200128 salt.enforceHighstate(master, "I@ceph:${target}")
Mateusz Losa4b024f2019-09-18 21:58:54 +0200129 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100130 }
131
132 stage("Verify services for ${minion}") {
133 sleep(10)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400134 salt.cmdRun(master, "${minion}", "systemctl status ceph-${target}.target")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100135 }
136
137 stage('Ask for manual confirmation') {
Mateusz Lose1ae6002019-05-08 11:55:39 +0200138 runCephCommand(master, ADMIN_HOST, "ceph -s")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100139 input message: "From the verification command above, please check Ceph ${target} joined the cluster correctly. If so, Do you want to continue to upgrade next node?"
140 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100141 }
142 }
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400143 salt.cmdRun(master, ADMIN_HOST, "ceph versions")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100144 sleep(5)
145 return
146}
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400147
Jakub Josefa63f9862018-01-11 17:58:38 +0100148timeout(time: 12, unit: 'HOURS') {
149 node("python") {
Jiri Broulikdc87d722017-11-03 15:43:22 +0100150
Jakub Josefa63f9862018-01-11 17:58:38 +0100151 // create connection to salt master
152 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100153
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400154 stage('Check user choices') {
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300155 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
156 // if rgw, check if other stuff has required version
157 def mon_ok = true
158 if (STAGE_UPGRADE_MON.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400159 def mon_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mon versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300160 mon_ok = mon_v.contains("${TARGET_RELEASE}") && !mon_v.contains("${ORIGIN_RELEASE}")
161 }
162 def mgr_ok = true
163 if (STAGE_UPGRADE_MGR.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400164 def mgr_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mgr versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300165 mgr_ok = mgr_v.contains("${TARGET_RELEASE}") && !mgr_v.contains("${ORIGIN_RELEASE}")
166 }
167 def osd_ok = true
168 if (STAGE_UPGRADE_OSD.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400169 def osd_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300170 osd_ok = osd_v.contains("${TARGET_RELEASE}") && !osd_v.contains("${ORIGIN_RELEASE}")
171 }
172 if (!mon_ok || !osd_ok || !mgr_ok) {
173 common.errorMsg('You may choose stages in any order, but RGW should be upgraded last')
174 throw new InterruptedException()
175 }
176 }
177 }
178
Jakub Josefa63f9862018-01-11 17:58:38 +0100179 if (BACKUP_ENABLED.toBoolean() == true) {
180 if (STAGE_UPGRADE_MON.toBoolean() == true) {
181 backup(pepperEnv, 'mon')
182 }
183 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
184 backup(pepperEnv, 'radosgw')
185 }
186 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
187 backup(pepperEnv, 'osd')
Jiri Broulikdc87d722017-11-03 15:43:22 +0100188 }
189 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100190
Jakub Josefa63f9862018-01-11 17:58:38 +0100191 if (flags.size() > 0) {
192 stage('Set cluster flags') {
193 for (flag in flags) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400194 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100195 }
PGlazov9085e842020-02-12 18:07:04 +0400196 if (ORIGIN_RELEASE == 'jewel') {
197 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set sortbitwise')
198 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100199 }
200 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100201
Jakub Josefa63f9862018-01-11 17:58:38 +0100202 if (STAGE_UPGRADE_MON.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400203 upgrade(pepperEnv, 'mon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100204 }
205
206 if (STAGE_UPGRADE_MGR.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400207 upgrade(pepperEnv, 'mgr')
Jakub Josefa63f9862018-01-11 17:58:38 +0100208 }
209
210 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400211 upgrade(pepperEnv, 'osd')
Jakub Josefa63f9862018-01-11 17:58:38 +0100212 }
213
214 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400215 upgrade(pepperEnv, 'radosgw')
Jakub Josefa63f9862018-01-11 17:58:38 +0100216 }
217
218 if (STAGE_UPGRADE_CLIENT.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400219 upgrade(pepperEnv, 'common')
Jakub Josefa63f9862018-01-11 17:58:38 +0100220 }
221
222 // remove cluster flags
223 if (flags.size() > 0) {
224 stage('Unset cluster flags') {
225 for (flag in flags) {
226 if (!flag.contains('sortbitwise')) {
227 common.infoMsg('Removing flag ' + flag)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400228 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +0100229 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100230 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100231 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100232 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100233
Jakub Josefa63f9862018-01-11 17:58:38 +0100234 if (STAGE_FINALIZE.toBoolean() == true) {
235 stage("Finalize ceph version upgrade") {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400236 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd require-osd-release ${TARGET_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100237 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400238 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd set-require-min-compat-client ${ORIGIN_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100239 } catch (Exception e) {
240 common.warningMsg(e)
241 }
242 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400243 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd crush tunables optimal")
Jakub Josefa63f9862018-01-11 17:58:38 +0100244 } catch (Exception e) {
245 common.warningMsg(e)
246 }
Tomek Jaroszyk933011a2020-04-07 11:20:31 +0200247 if (TARGET_RELEASE == 'nautilus' ) {
248 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mon enable-msgr2")
249 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100250 }
251 }
252
253 // wait for healthy cluster
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400254 if (WAIT_FOR_HEALTHY.toBoolean()) {
255 ceph.waitForHealthy(pepperEnv, ADMIN_HOST, flags)
Jakub Josefa63f9862018-01-11 17:58:38 +0100256 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100257 }
258}