blob: 86051c0e3c457200fe2c51be659f94432dd0504b [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
30def pepperEnv = "pepperEnv"
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040031flags = CLUSTER_FLAGS.tokenize(',')
Jiri Broulikdc87d722017-11-03 15:43:22 +010032
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040033def backup(master, target) {
Jiri Broulik96c867a2017-11-07 16:14:10 +010034 stage("backup ${target}") {
35
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010036 if (target == 'osd') {
Jiri Broulik96c867a2017-11-07 16:14:10 +010037 try {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010038 salt.enforceState(master, "I@ceph:${target}", "ceph.backup", true)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040039 salt.cmdRun(master, "I@ceph:${target}", "su root -c '/usr/local/bin/ceph-backup-runner-call.sh'")
Jiri Broulik96c867a2017-11-07 16:14:10 +010040 } catch (Exception e) {
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010041 common.errorMsg(e)
42 common.errorMsg("Make sure Ceph backup on OSD nodes is enabled")
43 throw new InterruptedException()
Jiri Broulik96c867a2017-11-07 16:14:10 +010044 }
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010045 } else {
46 def _pillar = salt.getGrain(master, 'I@salt:master', 'domain')
47 def domain = _pillar['return'][0].values()[0].values()[0]
48
49 def kvm_pillar = salt.getGrain(master, 'I@salt:control', 'id')
50 def kvm01 = kvm_pillar['return'][0].values()[0].values()[0]
51
52 def target_pillar = salt.getGrain(master, "I@ceph:${target}", 'host')
53 def minions = target_pillar['return'][0].values()
54 for (minion in minions) {
55 def minion_name = minion.values()[0]
56 def provider_pillar = salt.getPillar(master, "${kvm01}", "salt:control:cluster:internal:node:${minion_name}:provider")
57 def minionProvider = provider_pillar['return'][0].values()[0]
58
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040059 ceph.waitForHealthy(master, ADMIN_HOST, flags)
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010060 try {
Michael Vollmanafe91522019-05-07 08:10:00 -040061 salt.cmdRun(master, "${minionProvider}", "[ ! -f ${BACKUP_DIR}/${minion_name}.${domain}.qcow2.bak ] && virsh destroy ${minion_name}.${domain}")
Jiri Broulikfd2dcaf2017-12-08 15:19:51 +010062 } catch (Exception e) {
63 common.warningMsg('Backup already exists')
64 }
65 try {
Michael Vollmanafe91522019-05-07 08:10:00 -040066 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 +010067 } catch (Exception e) {
68 common.warningMsg('Backup already exists')
69 }
70 try {
71 salt.cmdRun(master, "${minionProvider}", "virsh start ${minion_name}.${domain}")
72 } catch (Exception e) {
73 common.warningMsg(e)
74 }
75 salt.minionsReachable(master, 'I@salt:master', "${minion_name}*")
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040076 ceph.waitForHealthy(master, ADMIN_HOST, flags)
Jiri Broulik96c867a2017-11-07 16:14:10 +010077 }
Jiri Broulik96c867a2017-11-07 16:14:10 +010078 }
79 }
80 return
81}
82
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040083def upgrade(master, target) {
Jiri Broulikdc87d722017-11-03 15:43:22 +010084
85 stage("Change ${target} repos") {
86 salt.runSaltProcessStep(master, "I@ceph:${target}", 'saltutil.refresh_pillar', [], null, true, 5)
87 salt.enforceState(master, "I@ceph:${target}", 'linux.system.repo', true)
88 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010089 if (target == 'mgr') {
90 stage('Run ceph mgr state') {
91 salt.enforceState(master, "I@ceph:mgr", "ceph.mgr", true)
92 }
93 }
Jiri Broulikdc87d722017-11-03 15:43:22 +010094 if (target == 'common') {
95 stage('Upgrade ceph-common pkgs') {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040096 salt.cmdRun(master, "I@ceph:${target}", "apt install ceph-${target} -y")
Jiri Broulikdc87d722017-11-03 15:43:22 +010097 }
98 } else {
Jiri Broulik96c867a2017-11-07 16:14:10 +010099 minions = salt.getMinions(master, "I@ceph:${target}")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100100
Jiri Broulik96c867a2017-11-07 16:14:10 +0100101 for (minion in minions) {
102 // upgrade pkgs
103 if (target == 'radosgw') {
104 stage('Upgrade radosgw pkgs') {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400105 salt.cmdRun(master, "I@ceph:${target}", "apt install ${target} -y ")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100106 }
107 } else {
108 stage("Upgrade ${target} pkgs on ${minion}") {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400109 salt.cmdRun(master, "${minion}", "apt install ceph-${target} -y")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100110 }
111 }
112 // restart services
113 stage("Restart ${target} services on ${minion}") {
Mateusz Losa4b024f2019-09-18 21:58:54 +0200114 if (target == 'osd') {
Mateusz Los80bb9252020-02-06 13:33:42 +0100115 def device_grain_name = salt.getPillar(master,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true) ? "ceph_volume" : "ceph_disk"
116 def ceph_disks = salt.getGrain(master, minion, 'ceph')['return'][0].values()[0].values()[0][device_grain_name]
117 ceph_disks.each { osd, param ->
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400118 salt.cmdRun(master, "${minion}", "systemctl restart ceph-${target}@${osd}")
119 ceph.waitForHealthy(master, ADMIN_HOST, flags)
120 }
Mateusz Losa4b024f2019-09-18 21:58:54 +0200121 } else {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400122 salt.cmdRun(master, "${minion}", "systemctl restart ceph-${target}.target")
123 ceph.waitForHealthy(master, ADMIN_HOST, flags)
Mateusz Losa4b024f2019-09-18 21:58:54 +0200124 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100125 }
126
127 stage("Verify services for ${minion}") {
128 sleep(10)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400129 salt.cmdRun(master, "${minion}", "systemctl status ceph-${target}.target")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100130 }
131
132 stage('Ask for manual confirmation') {
Mateusz Lose1ae6002019-05-08 11:55:39 +0200133 runCephCommand(master, ADMIN_HOST, "ceph -s")
Jiri Broulik96c867a2017-11-07 16:14:10 +0100134 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?"
135 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100136 }
137 }
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400138 salt.cmdRun(master, ADMIN_HOST, "ceph versions")
Jiri Broulikdc87d722017-11-03 15:43:22 +0100139 sleep(5)
140 return
141}
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400142
Jakub Josefa63f9862018-01-11 17:58:38 +0100143timeout(time: 12, unit: 'HOURS') {
144 node("python") {
Jiri Broulikdc87d722017-11-03 15:43:22 +0100145
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 // create connection to salt master
147 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100148
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400149 stage('Check user choices') {
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300150 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
151 // if rgw, check if other stuff has required version
152 def mon_ok = true
153 if (STAGE_UPGRADE_MON.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400154 def mon_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mon versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300155 mon_ok = mon_v.contains("${TARGET_RELEASE}") && !mon_v.contains("${ORIGIN_RELEASE}")
156 }
157 def mgr_ok = true
158 if (STAGE_UPGRADE_MGR.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400159 def mgr_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mgr versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300160 mgr_ok = mgr_v.contains("${TARGET_RELEASE}") && !mgr_v.contains("${ORIGIN_RELEASE}")
161 }
162 def osd_ok = true
163 if (STAGE_UPGRADE_OSD.toBoolean() == false) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400164 def osd_v = salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd versions")['return'][0].values()[0]
Alena Kiseleva30f780c2019-01-22 17:09:33 +0300165 osd_ok = osd_v.contains("${TARGET_RELEASE}") && !osd_v.contains("${ORIGIN_RELEASE}")
166 }
167 if (!mon_ok || !osd_ok || !mgr_ok) {
168 common.errorMsg('You may choose stages in any order, but RGW should be upgraded last')
169 throw new InterruptedException()
170 }
171 }
172 }
173
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 if (BACKUP_ENABLED.toBoolean() == true) {
175 if (STAGE_UPGRADE_MON.toBoolean() == true) {
176 backup(pepperEnv, 'mon')
177 }
178 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
179 backup(pepperEnv, 'radosgw')
180 }
181 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
182 backup(pepperEnv, 'osd')
Jiri Broulikdc87d722017-11-03 15:43:22 +0100183 }
184 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100185
Jakub Josefa63f9862018-01-11 17:58:38 +0100186 if (flags.size() > 0) {
187 stage('Set cluster flags') {
188 for (flag in flags) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400189 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set ' + flag)
Jiri Broulikdc87d722017-11-03 15:43:22 +0100190 }
PGlazov9085e842020-02-12 18:07:04 +0400191 if (ORIGIN_RELEASE == 'jewel') {
192 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd set sortbitwise')
193 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100194 }
195 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100196
Jakub Josefa63f9862018-01-11 17:58:38 +0100197 if (STAGE_UPGRADE_MON.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400198 upgrade(pepperEnv, 'mon')
Mateusz Los80bb9252020-02-06 13:33:42 +0100199
200 if (TARGET_RELEASE == 'nautilus' ) {
201 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph mon enable-msgr2")
202 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100203 }
204
205 if (STAGE_UPGRADE_MGR.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400206 upgrade(pepperEnv, 'mgr')
Jakub Josefa63f9862018-01-11 17:58:38 +0100207 }
208
209 if (STAGE_UPGRADE_OSD.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400210 upgrade(pepperEnv, 'osd')
Jakub Josefa63f9862018-01-11 17:58:38 +0100211 }
212
213 if (STAGE_UPGRADE_RGW.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400214 upgrade(pepperEnv, 'radosgw')
Jakub Josefa63f9862018-01-11 17:58:38 +0100215 }
216
217 if (STAGE_UPGRADE_CLIENT.toBoolean() == true) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400218 upgrade(pepperEnv, 'common')
Jakub Josefa63f9862018-01-11 17:58:38 +0100219 }
220
221 // remove cluster flags
222 if (flags.size() > 0) {
223 stage('Unset cluster flags') {
224 for (flag in flags) {
225 if (!flag.contains('sortbitwise')) {
226 common.infoMsg('Removing flag ' + flag)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400227 salt.cmdRun(pepperEnv, ADMIN_HOST, 'ceph osd unset ' + flag)
Jakub Josefa63f9862018-01-11 17:58:38 +0100228 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100229 }
Jiri Broulik96c867a2017-11-07 16:14:10 +0100230 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100231 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100232
Jakub Josefa63f9862018-01-11 17:58:38 +0100233 if (STAGE_FINALIZE.toBoolean() == true) {
234 stage("Finalize ceph version upgrade") {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400235 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd require-osd-release ${TARGET_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100236 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400237 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd set-require-min-compat-client ${ORIGIN_RELEASE}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100238 } catch (Exception e) {
239 common.warningMsg(e)
240 }
241 try {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400242 salt.cmdRun(pepperEnv, ADMIN_HOST, "ceph osd crush tunables optimal")
Jakub Josefa63f9862018-01-11 17:58:38 +0100243 } catch (Exception e) {
244 common.warningMsg(e)
245 }
246 }
247 }
248
249 // wait for healthy cluster
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +0400250 if (WAIT_FOR_HEALTHY.toBoolean()) {
251 ceph.waitForHealthy(pepperEnv, ADMIN_HOST, flags)
Jakub Josefa63f9862018-01-11 17:58:38 +0100252 }
Jiri Broulikdc87d722017-11-03 15:43:22 +0100253 }
254}