blob: a0d6a1f3119047d670019c4968e3874e884d4ebc [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 *
Jiri Broulikdc87d722017-11-03 15:43:22 +01009 * CLUSTER_FLAGS Comma separated list of tags to apply to cluster
10 * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons
Denis Egorenkoa5594de2021-01-11 15:24:45 +040011 * ASK_CONFIRMATION Ask for manual confirmation
Jiri Broulikdc87d722017-11-03 15:43:22 +010012 * 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 Vollmanbcec46f2019-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 Berezovskiy2325dcb2019-11-05 17:42:57 +040028ceph = new com.mirantis.mk.Ceph()
Denis Egorenkoa5594de2021-01-11 15:24:45 +040029askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean()
Jiri Broulikdc87d722017-11-03 15:43:22 +010030
Tomek Jaroszykbddec292020-08-18 10:21:54 +020031pepperEnv = "pepperEnv"
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040032flags = CLUSTER_FLAGS.tokenize(',')
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010033// sortbitwise is set by default on version >jewel.
34// For jewel upgrade we will set and keep it while for other cases shouldn't be there
35flags.removeElement('sortbitwise')
Jiri Broulikdc87d722017-11-03 15:43:22 +010036
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040037def backup(master, target) {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010038 stage("backup $target") {
Jiri Broulik96c867a2017-11-07 16:14:10 +010039
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010040 if (target == 'osd') {
Jiri Broulik96c867a2017-11-07 16:14:10 +010041 try {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010042 salt.enforceState(master, "I@ceph:${target}", "ceph.backup", true)
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010043 ceph.cmdRunOnTarget(master, "I@ceph:${target}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh'")
Jiri Broulik96c867a2017-11-07 16:14:10 +010044 } catch (Exception e) {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010045 common.errorMsg(e)
46 common.errorMsg("Make sure Ceph backup on OSD nodes is enabled")
47 throw new InterruptedException()
Jiri Broulik96c867a2017-11-07 16:14:10 +010048 }
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010049 } else {
50 def _pillar = salt.getGrain(master, 'I@salt:master', 'domain')
51 def domain = _pillar['return'][0].values()[0].values()[0]
52
53 def kvm_pillar = salt.getGrain(master, 'I@salt:control', 'id')
54 def kvm01 = kvm_pillar['return'][0].values()[0].values()[0]
55
56 def target_pillar = salt.getGrain(master, "I@ceph:${target}", 'host')
57 def minions = target_pillar['return'][0].values()
58 for (minion in minions) {
59 def minion_name = minion.values()[0]
60 def provider_pillar = salt.getPillar(master, "${kvm01}", "salt:control:cluster:internal:node:${minion_name}:provider")
61 def minionProvider = provider_pillar['return'][0].values()[0]
62
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010063 ceph.waitForHealthy(master, flags)
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010064 try {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010065 ceph.cmdRunOnTarget(master, minionProvider, "[ ! -f ${BACKUP_DIR}/${minion_name}.${domain}.qcow2.bak ] && virsh destroy ${minion_name}.${domain}")
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010066 } catch (Exception e) {
67 common.warningMsg('Backup already exists')
68 }
69 try {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010070 ceph.cmdRunOnTarget(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 +010071 } catch (Exception e) {
72 common.warningMsg('Backup already exists')
73 }
74 try {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010075 ceph.cmdRunOnTarget(master, minionProvider, "virsh start ${minion_name}.${domain}")
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010076 } catch (Exception e) {
77 common.warningMsg(e)
78 }
79 salt.minionsReachable(master, 'I@salt:master', "${minion_name}*")
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010080 ceph.waitForHealthy(master, flags)
Jiri Broulik96c867a2017-11-07 16:14:10 +010081 }
Jiri Broulik96c867a2017-11-07 16:14:10 +010082 }
83 }
84 return
85}
86
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040087def upgrade(master, target) {
Jiri Broulikdc87d722017-11-03 15:43:22 +010088
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +010089 stage("Change $target repos") {
Jiri Broulikdc87d722017-11-03 15:43:22 +010090 salt.runSaltProcessStep(master, "I@ceph:${target}", 'saltutil.refresh_pillar', [], null, true, 5)
91 salt.enforceState(master, "I@ceph:${target}", 'linux.system.repo', true)
92 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010093 if (target == 'mgr') {
94 stage('Run ceph mgr state') {
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +020095 salt.enforceState(master, "I@ceph:mgr", "ceph.mgr", true, failOnError=false, retries=3, retries_wait=10)
Jiri Broulikdc87d722017-11-03 15:43:22 +010096 }
97 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010098 if (target == 'common') {
99 stage('Upgrade ceph-common pkgs') {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100100 salt.runSaltProcessStep(master, "I@ceph:common", 'pkg.install', ["ceph-common"], 'only_upgrade=True')
Jiri Broulikdc87d722017-11-03 15:43:22 +0100101 }
102 } else {
Jiri Broulik96c867a2017-11-07 16:14:10 +0100103 minions = salt.getMinions(master, "I@ceph:${target}")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100104
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100105 def ignoreDifferentSubversions = false
Jiri Broulik96c867a2017-11-07 16:14:10 +0100106 for (minion in minions) {
107 // upgrade pkgs
108 if (target == 'radosgw') {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100109 stage("Upgrade radosgw pkgs on $minion") {
110 salt.runSaltProcessStep(master, minion, 'pkg.install', [target], 'only_upgrade=True')
Jiri Broulik96c867a2017-11-07 16:14:10 +0100111 }
112 } else {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100113 stage("Upgrade $target pkgs on $minion") {
114 salt.runSaltProcessStep(master, minion, 'pkg.install', ["ceph-${target}"], 'only_upgrade=True')
115 }
116 }
117 // check for subversion difference before restart
118 if (ignoreDifferentSubversions) {
119 targetVersion = ceph.cmdRun(master, "ceph versions | grep $TARGET_RELEASE | awk '{print \$3}' | sort -V | tail -1")
120 updatedVersion = ceph.cmdRunOnTarget(master, minion, "ceph version | awk '{print \$3}'")
121 if (targetVersion != updatedVersion) {
122 stage('Version differnce warning') {
123 common.warningMsg("A potential problem has been spotted.")
124 common.warningMsg("Some components already have $targetVersion version while ceph-$target has just been updated to $updatedVersion")
125 input message: "Do you want to proceed with restarts and silence this warning?"
126 ignoreDifferentSubversions = true
127 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100128 }
129 }
130 // restart services
131 stage("Restart ${target} services on ${minion}") {
Mateusz Losabf4ef52020-05-11 10:37:23 +0200132 if(target == 'osd') {
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +0200133 def ceph_disks = salt.getGrain(master, minion, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk']
Mateusz Losb8575e62020-02-06 13:33:42 +0100134 ceph_disks.each { osd, param ->
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100135 ceph.cmdRunOnTarget(master, minion, "systemctl restart ceph-${target}@${osd}")
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400136 }
Mateusz Losabf4ef52020-05-11 10:37:23 +0200137 }
138 else {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100139 ceph.cmdRunOnTarget(master, minion, "systemctl restart ceph-${target}.target")
Mateusz Losabf4ef52020-05-11 10:37:23 +0200140 }
141
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100142 ceph.waitForHealthy(master, flags)
Jiri Broulik96c867a2017-11-07 16:14:10 +0100143 }
144
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100145 stage("Verify services for $minion") {
Jiri Broulik96c867a2017-11-07 16:14:10 +0100146 sleep(10)
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100147 ceph.cmdRunOnTarget(master, minion, "systemctl status ceph-${target}.target")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100148 }
149
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100150 stage('Verify Ceph status') {
151 ceph.cmdRun(master, "ceph -s", true, true)
152 if (askConfirmation) {
153 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?"
Denis Egorenkoa5594de2021-01-11 15:24:45 +0400154 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100155 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100156 }
157 }
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100158 ceph.cmdRun(master, "ceph versions")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100159 sleep(5)
160 return
161}
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400162
Jakub Josefa63f9862018-01-11 17:58:38 +0100163timeout(time: 12, unit: 'HOURS') {
164 node("python") {
Jiri Broulikdc87d722017-11-03 15:43:22 +0100165
Jakub Josefa63f9862018-01-11 17:58:38 +0100166 // create connection to salt master
167 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100168
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400169 stage('Check user choices') {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100170 if (STAGE_UPGRADE_RGW.toBoolean()) {
Alena Kiseleva639b0012019-01-22 17:09:33 +0300171 // if rgw, check if other stuff has required version
172 def mon_ok = true
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100173 if (!STAGE_UPGRADE_MON.toBoolean()) {
174 def mon_v = ceph.cmdRun(pepperEnv, "ceph mon versions")
Alena Kiseleva639b0012019-01-22 17:09:33 +0300175 mon_ok = mon_v.contains("${TARGET_RELEASE}") && !mon_v.contains("${ORIGIN_RELEASE}")
176 }
177 def mgr_ok = true
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100178 if (!STAGE_UPGRADE_MGR.toBoolean()) {
179 def mgr_v = ceph.cmdRun(pepperEnv, "ceph mgr versions")
Alena Kiseleva639b0012019-01-22 17:09:33 +0300180 mgr_ok = mgr_v.contains("${TARGET_RELEASE}") && !mgr_v.contains("${ORIGIN_RELEASE}")
181 }
182 def osd_ok = true
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100183 if (!STAGE_UPGRADE_OSD.toBoolean()) {
184 def osd_v = ceph.cmdRun(pepperEnv, "ceph osd versions")
Alena Kiseleva639b0012019-01-22 17:09:33 +0300185 osd_ok = osd_v.contains("${TARGET_RELEASE}") && !osd_v.contains("${ORIGIN_RELEASE}")
186 }
187 if (!mon_ok || !osd_ok || !mgr_ok) {
188 common.errorMsg('You may choose stages in any order, but RGW should be upgraded last')
189 throw new InterruptedException()
190 }
191 }
192 }
193
Jakub Josefa63f9862018-01-11 17:58:38 +0100194 if (BACKUP_ENABLED.toBoolean() == true) {
195 if (STAGE_UPGRADE_MON.toBoolean() == true) {
196 backup(pepperEnv, 'mon')
197 }
198 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
199 backup(pepperEnv, 'radosgw')
200 }
201 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
202 backup(pepperEnv, 'osd')
Jiri Broulikdc87d722017-11-03 15:43:22 +0100203 }
204 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100205
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100206 stage('Set cluster flags') {
207 ceph.setFlags(pepperEnv, flags)
208 if (ORIGIN_RELEASE == 'jewel') {
209 ceph.setFlags('sortbitwise')
Jiri Broulikdc87d722017-11-03 15:43:22 +0100210 }
211 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100212
Jakub Josefa63f9862018-01-11 17:58:38 +0100213 if (STAGE_UPGRADE_MON.toBoolean() == true) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400214 upgrade(pepperEnv, 'mon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100215 }
216
217 if (STAGE_UPGRADE_MGR.toBoolean() == true) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400218 upgrade(pepperEnv, 'mgr')
Jakub Josefa63f9862018-01-11 17:58:38 +0100219 }
220
221 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400222 upgrade(pepperEnv, 'osd')
Jakub Josefa63f9862018-01-11 17:58:38 +0100223 }
224
225 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400226 upgrade(pepperEnv, 'radosgw')
Jakub Josefa63f9862018-01-11 17:58:38 +0100227 }
228
229 if (STAGE_UPGRADE_CLIENT.toBoolean() == true) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400230 upgrade(pepperEnv, 'common')
Jakub Josefa63f9862018-01-11 17:58:38 +0100231 }
232
233 // remove cluster flags
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100234 stage('Unset cluster flags') {
235 ceph.unsetFlags(flags)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100236 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100237
Jakub Josefa63f9862018-01-11 17:58:38 +0100238 if (STAGE_FINALIZE.toBoolean() == true) {
239 stage("Finalize ceph version upgrade") {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100240 ceph.cmdRun(pepperEnv, "ceph osd require-osd-release ${TARGET_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100241 try {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100242 ceph.cmdRun(pepperEnv, "ceph osd set-require-min-compat-client ${ORIGIN_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100243 } catch (Exception e) {
244 common.warningMsg(e)
245 }
246 try {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100247 ceph.cmdRun(pepperEnv, "ceph osd crush tunables optimal")
Jakub Josefa63f9862018-01-11 17:58:38 +0100248 } catch (Exception e) {
249 common.warningMsg(e)
250 }
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +0200251 if (TARGET_RELEASE == 'nautilus' ) {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100252 ceph.cmdRun(pepperEnv, "ceph mon enable-msgr2")
Tomek Jaroszyk0cb83922020-04-07 11:20:31 +0200253 }
Tomek Jaroszykf3546562020-09-17 15:34:05 +0200254 salt.enforceState(pepperEnv, "I@ceph:common", "ceph.common")
Jakub Josefa63f9862018-01-11 17:58:38 +0100255 }
256 }
257
258 // wait for healthy cluster
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +0400259 if (WAIT_FOR_HEALTHY.toBoolean()) {
Tomek Jaroszyk8b8cd142022-02-18 14:46:34 +0100260 ceph.waitForHealthy(pepperEnv, flags)
Jakub Josefa63f9862018-01-11 17:58:38 +0100261 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100262 }
263}