blob: 31e214dc921f1729bf6c57f624fbb310485986d0 [file] [log] [blame]
Jiri Broulikbb447ac2017-05-04 15:36:22 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
Jiri Broulik3792c962017-05-17 18:26:36 +02007 * STAGE_TEST_UPGRADE Run test upgrade stage (bool)
8 * STAGE_REAL_UPGRADE Run real upgrade stage (bool)
9 * STAGE_ROLLBACK_UPGRADE Run rollback upgrade stage (bool)
Jiri Broulik7cadf582017-11-13 17:35:31 +010010 * SKIP_VM_RELAUNCH Set to true if vms should not be recreated
Jiri Broulikbb447ac2017-05-04 15:36:22 +020011 *
12**/
13
14def common = new com.mirantis.mk.Common()
15def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020016def python = new com.mirantis.mk.Python()
Jiri Broulikbb447ac2017-05-04 15:36:22 +020017
chnyda625f4b42017-10-11 14:10:31 +020018def pepperEnv = "pepperEnv"
Jakub Josefa63f9862018-01-11 17:58:38 +010019timeout(time: 12, unit: 'HOURS') {
20 node() {
Jiri Broulikbb447ac2017-05-04 15:36:22 +020021
Jakub Josefa63f9862018-01-11 17:58:38 +010022 stage('Setup virtualenv for Pepper') {
23 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
24 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020025
Jakub Josefa63f9862018-01-11 17:58:38 +010026 if (STAGE_TEST_UPGRADE.toBoolean() == true) {
27 stage('Test upgrade') {
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020028
Jiri Broulik7cadf582017-11-13 17:35:31 +010029 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010030 salt.enforceState(pepperEnv, 'I@salt:master', 'reclass')
Jiri Broulik7cadf582017-11-13 17:35:31 +010031 } catch (Exception e) {
Jakub Josefa63f9862018-01-11 17:58:38 +010032 common.warningMsg("Some parts of Reclass state failed. The most probable reasons were uncommited changes. We should continue to run")
Jiri Broulik7cadf582017-11-13 17:35:31 +010033 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020034
Jakub Josefa63f9862018-01-11 17:58:38 +010035 try {
36 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
37 } catch (Exception e) {
38 common.warningMsg("No response from some minions. We should continue to run")
39 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020040
Jakub Josefa63f9862018-01-11 17:58:38 +010041 try {
42 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
43 } catch (Exception e) {
44 common.warningMsg("No response from some minions. We should continue to run")
45 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020046
Jakub Josefa63f9862018-01-11 17:58:38 +010047 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
48 domain = domain['return'][0].values()[0]
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020049
Jakub Josefa63f9862018-01-11 17:58:38 +010050 // read backupninja variable
51 _pillar = salt.getPillar(pepperEnv, 'I@backupninja:client', '_param:backupninja_backup_host')
52 def backupninja_backup_host = _pillar['return'][0].values()[0]
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020053
Jakub Josefa63f9862018-01-11 17:58:38 +010054 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
55
56 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
57 def kvm01 = _pillar['return'][0].values()[0].values()[0]
58 print(_pillar)
59 print(kvm01)
60
61 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider')
62 def upgNodeProvider = _pillar['return'][0].values()[0]
63 print(_pillar)
64 print(upgNodeProvider)
65
66 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true)
67 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true)
68
69 try {
70 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d upg01.${domain} -y")
71 } catch (Exception e) {
72 common.warningMsg("upg01.${domain} does not match any accepted, unaccepted or rejected keys. The key did not exist yet or was already removed. We should continue to run")
Jiri Broulik3792c962017-05-17 18:26:36 +020073 }
Jakub Josefa63f9862018-01-11 17:58:38 +010074
75 // salt 'kvm02*' state.sls salt.control
76 salt.enforceState(pepperEnv, "${upgNodeProvider}", 'salt.control')
77 // wait until upg node is registered in salt-key
78 salt.minionPresent(pepperEnv, 'I@salt:master', 'upg01')
79 // salt '*' saltutil.refresh_pillar
80 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.refresh_pillar', [], null, true)
81 // salt '*' saltutil.sync_all
82 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.sync_all', [], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +020083 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020084
Jakub Josefa63f9862018-01-11 17:58:38 +010085 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
86 try {
87 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh'])
88 } catch (Exception e) {
89 common.warningMsg(e)
90 }
91 try {
92 salt.runSaltProcessStep(master, 'upg*', 'state.sls', ["salt.minion"], null, true, 60)
93 } catch (Exception e) {
94 common.warningMsg(e)
95 }
96 try {
97 salt.enforceState(pepperEnv, 'upg*', ['ntp', 'rsyslog'])
98 } catch (Exception e) {
99 common.warningMsg(e)
100 }
101 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
102
103 // salt "upg*" state.sls rabbitmq
104 salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached'])
105 try {
106 salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
107 } catch (Exception e) {
108 common.warningMsg('salt-minion was restarted. We should continue to run')
109 }
110 try {
111 salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion'])
112 } catch (Exception e) {
113 common.warningMsg('salt-minion was restarted. We should continue to run')
114 }
115 // salt '*' state.apply salt.minion.grains
116 //salt.enforceState(pepperEnv, '*', 'salt.minion.grains')
117 // salt -C 'I@backupninja:server' state.sls backupninja
118 salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja')
119 // salt -C 'I@backupninja:client' state.sls backupninja
120 salt.enforceState(pepperEnv, 'I@backupninja:client', 'backupninja')
121 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
122 try {
123 salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
124 } catch (Exception e) {
125 common.warningMsg('The ARP entry does not exist. We should continue to run.')
126 }
127 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
128 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
129 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
130
131 salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup')
132 salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client')
133 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
134 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
135
136 def databases = salt.cmdRun(pepperEnv, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
137 if(databases && databases != ""){
138 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
139 for( i = 0; i < databasesList.size(); i++){
140 if(databasesList[i].toLowerCase().contains('upgrade')){
141 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
142 common.warningMsg("removing database ${databasesList[i]}")
143 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
144 }
145 }
146 salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client')
147 }else{
148 common.errorMsg("No _upgrade databases were returned")
149 }
150
151 try {
152 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
153 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
154 } catch (Exception e) {
155 common.warningMsg('Restarting Apache2')
156 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
157 }
158 try {
159 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
160 } catch (Exception e) {
161 common.warningMsg('running keystone.client state again')
162 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
163 }
164 try {
165 salt.enforceState(pepperEnv, 'upg*', 'glance')
166 } catch (Exception e) {
167 common.warningMsg('running glance state again')
168 salt.enforceState(pepperEnv, 'upg*', 'glance')
169 }
chnyda625f4b42017-10-11 14:10:31 +0200170 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
Jakub Josefa63f9862018-01-11 17:58:38 +0100171 try {
172 salt.enforceState(pepperEnv, 'upg*', 'nova')
173 } catch (Exception e) {
174 common.warningMsg('running nova state again')
175 salt.enforceState(pepperEnv, 'upg*', 'nova')
176 }
177 // run nova state again as sometimes nova does not enforce itself for some reason
178 try {
179 salt.enforceState(pepperEnv, 'upg*', 'nova')
180 } catch (Exception e) {
181 common.warningMsg('running nova state again')
182 salt.enforceState(pepperEnv, 'upg*', 'nova')
183 }
184 try {
185 salt.enforceState(pepperEnv, 'upg*', 'cinder')
186 } catch (Exception e) {
187 common.warningMsg('running cinder state again')
188 salt.enforceState(pepperEnv, 'upg*', 'cinder')
189 }
190 try {
191 salt.enforceState(pepperEnv, 'upg*', 'neutron')
192 } catch (Exception e) {
193 common.warningMsg('running neutron state again')
194 salt.enforceState(pepperEnv, 'upg*', 'neutron')
195 }
196 try {
197 salt.enforceState(pepperEnv, 'upg*', 'heat')
198 } catch (Exception e) {
199 common.warningMsg('running heat state again')
200 salt.enforceState(pepperEnv, 'upg*', 'heat')
201 }
202 salt.cmdRun(pepperEnv, 'upg01*', '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400203
Jakub Josefa63f9862018-01-11 17:58:38 +0100204 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
205 stage('Ask for manual confirmation') {
206 input message: "Do you want to continue with upgrade?"
207 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200208 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400209 }
210 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400211
Jakub Josefa63f9862018-01-11 17:58:38 +0100212 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
213 stage('Real upgrade') {
214 // # actual upgrade
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400215
Jakub Josefa63f9862018-01-11 17:58:38 +0100216 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
217 domain = domain['return'][0].values()[0]
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400218
Jakub Josefa63f9862018-01-11 17:58:38 +0100219 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
220 kvm01 = _pillar['return'][0].values()[0].values()[0]
221 print(_pillar)
222 print(kvm01)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400223
Jakub Josefa63f9862018-01-11 17:58:38 +0100224 def errorOccured = false
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400225
Jakub Josefa63f9862018-01-11 17:58:38 +0100226 def proxy_general_target = ""
227 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server').sort()
228 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400229
Jakub Josefa63f9862018-01-11 17:58:38 +0100230 for (t in proxy_target_hosts) {
231 def target = t.split("\\.")[0]
232 proxy_general_target = target.replaceAll('\\d+$', "")
233 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
234 break
235 }
236 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
237 def nodeProvider = _pillar['return'][0].values()[0]
238 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
239 sleep(2)
240 try {
241 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
242 } catch (Exception e) {
243 common.warningMsg('File already exists')
244 }
245 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
246 try {
247 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
248 } catch (Exception e) {
249 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
250 }
251 node_count++
Jiri Broulik7cadf582017-11-13 17:35:31 +0100252 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100253 def control_general_target = ""
254 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server and not upg*').sort()
255 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400256
Jiri Broulik7cadf582017-11-13 17:35:31 +0100257 for (t in control_target_hosts) {
258 def target = t.split("\\.")[0]
Jakub Josefa63f9862018-01-11 17:58:38 +0100259 control_general_target = target.replaceAll('\\d+$', "")
260 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
261 break
262 }
263 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
264 def nodeProvider = _pillar['return'][0].values()[0]
265 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
266 sleep(2)
267 try {
268 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
269 } catch (Exception e) {
270 common.warningMsg('File already exists')
271 }
272 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
273 try {
274 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
275 } catch (Exception e) {
276 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
277 }
278 node_count++
Jiri Broulik7cadf582017-11-13 17:35:31 +0100279 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100280
281 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
282 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
283
284 // salt 'kvm*' state.sls salt.control
285 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
286
287 for (t in control_target_hosts) {
288 def target = t.split("\\.")[0]
289 // wait until ctl and prx nodes are registered in salt-key
290 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
291 }
292 for (t in proxy_target_hosts) {
293 def target = t.split("\\.")[0]
294 // wait until ctl and prx nodes are registered in salt-key
295 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
296 }
297
298 // salt '*' saltutil.refresh_pillar
299 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
300 // salt '*' saltutil.sync_all
301 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
302 }
303 try {
304 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh'])
305 } catch (Exception e) {
306 common.warningMsg(e)
307 }
308 try {
309 salt.runSaltProcessStep(master, "${proxy_general_target}* or ${control_general_target}*", 'state.sls', ["salt.minion"], null, true, 60)
310 } catch (Exception e) {
311 common.warningMsg(e)
312 }
313 try {
314 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['ntp', 'rsyslog'])
315 } catch (Exception e) {
316 common.warningMsg(e)
317 }
318
319 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
320
321 // salt 'ctl*' state.sls keepalived
322 // salt 'ctl*' state.sls haproxy
323 salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy'])
324 // salt 'ctl*' service.restart rsyslog
325 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true)
326 // salt "ctl*" state.sls memcached
327 // salt "ctl*" state.sls keystone.server
328 try {
329 try {
330 salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server'])
331 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
332 } catch (Exception e) {
333 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
334 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
335 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
336 }
337 // salt 'ctl01*' state.sls keystone.client
338 try {
339 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
340 } catch (Exception e) {
341 common.warningMsg('running keystone.client state again')
342 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
343 }
344 try {
345 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
346 } catch (Exception e) {
347 common.warningMsg('running glance state again')
348 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
349 } // salt 'ctl*' state.sls glusterfs.client
350 salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client')
351 // salt 'ctl*' state.sls keystone.server
352 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
353 // salt 'ctl*' state.sls nova
354 try {
355 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
356 } catch (Exception e) {
357 common.warningMsg('running nova state again')
358 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
359 }
360 // salt 'ctl*' state.sls cinder
361 try {
362 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
363 } catch (Exception e) {
364 common.warningMsg('running cinder state again')
365 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
366 }
367 try {
368 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
369 } catch (Exception e) {
370 common.warningMsg('running neutron state again')
371 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
372 }
373 // salt 'ctl*' state.sls heat
374 try {
375 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
376 } catch (Exception e) {
377 common.warningMsg('running heat state again')
378 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
379 }
380
381 } catch (Exception e) {
382 errorOccured = true
383 input message: "Some states that require syncdb failed. Please check the reason and click proceed only if you want to restore database into it's pre-upgrade state. Otherwise, click abort."
384 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
385
386 // database restore section
387 try {
388 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
389 } catch (Exception er) {
390 common.warningMsg('Mysql service already stopped')
391 }
392 try {
393 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
394 } catch (Exception er) {
395 common.warningMsg('Mysql service already stopped')
396 }
397 try {
398 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
399 } catch (Exception er) {
400 common.warningMsg('Files are not present')
401 }
402 try {
403 salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
404 } catch (Exception er) {
405 common.warningMsg('Directory already exists')
406 }
407 try {
408 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
409 } catch (Exception er) {
410 common.warningMsg('Directory already empty')
411 }
412 try {
413 salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
414 } catch (Exception er) {
415 common.warningMsg('Files were already moved')
416 }
417 try {
418 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
419 } catch (Exception er) {
420 common.warningMsg('File is not present')
421 }
422 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
423 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
424 backup_dir = _pillar['return'][0].values()[0]
425 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
426 print(backup_dir)
427 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
428 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
429 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
430
431 // wait until mysql service on galera master is up
432 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
433
434 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
435 //
436
437 common.errorMsg("Stage Real control upgrade failed")
438 }
439 if(!errorOccured){
440
441 ceph = null
442
443 try {
444 ceph = salt.cmdRun(pepperEnv, "${control_general_target}*", "salt-call grains.item roles | grep ceph.client")
445
446 } catch (Exception er) {
447 common.infoMsg("Ceph is not used")
448 }
449
450 if(ceph != null) {
451 try {
452 salt.enforceState(pepperEnv, "${control_general_target}*", 'ceph.client')
453 } catch (Exception er) {
454 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
455 }
456 }
457
458 // salt 'cmp*' cmd.run 'service nova-compute restart'
459 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
460 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
461 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
462
463
464 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
465 // salt 'ctl*' state.sls keepalived
466 // salt 'prx*' state.sls keepalived
467 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'keepalived')
468 // salt 'prx*' state.sls horizon
469 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'horizon')
470 // salt 'prx*' state.sls nginx
471 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'nginx')
472 // salt "prx*" state.sls memcached
473 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'memcached')
474
475 try {
476 salt.enforceHighstate(pepperEnv, "${control_general_target}*")
477 } catch (Exception er) {
478 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
479 }
480
481 try {
482 salt.enforceHighstate(pepperEnv, "${proxy_general_target}*")
483 } catch (Exception er) {
484 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
485 }
486
487 salt.cmdRun(pepperEnv, "${control_general_target}01*", '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
488 }
489 }
490
491 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
492 stage('Ask for manual confirmation') {
493 input message: "Please verify if the control upgrade was successful. If it did not succeed, in the worst scenario, you can click YES to continue with control-upgrade-rollback. Do you want to continue with the rollback?"
494 }
495 }
496 }
497
498 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
499 stage('Rollback upgrade') {
500
501 stage('Ask for manual confirmation') {
502 input message: "Do you really want to continue with the rollback?"
503 }
504
505 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
506 domain = domain['return'][0].values()[0]
507
508 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
509 kvm01 = _pillar['return'][0].values()[0].values()[0]
510 print(_pillar)
511 print(kvm01)
512
513 def proxy_general_target = ""
514 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server')
515 def node_count = 1
516
Jiri Broulik7cadf582017-11-13 17:35:31 +0100517 for (t in proxy_target_hosts) {
518 def target = t.split("\\.")[0]
Jakub Josefa63f9862018-01-11 17:58:38 +0100519 proxy_general_target = target.replaceAll('\\d+$', "")
520 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
521 break
522 }
523 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
524 def nodeProvider = _pillar['return'][0].values()[0]
525 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
526 sleep(2)
527 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
528 try {
529 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
530 } catch (Exception e) {
531 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
532 }
533 node_count++
Jiri Broulik7cadf582017-11-13 17:35:31 +0100534 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100535 def control_general_target = ""
536 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server').sort()
537 node_count = 1
Jiri Broulik7cadf582017-11-13 17:35:31 +0100538
Jakub Josefa63f9862018-01-11 17:58:38 +0100539 for (t in control_target_hosts) {
540 def target = t.split("\\.")[0]
541 control_general_target = target.replaceAll('\\d+$', "")
542 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
543 break
544 }
545 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
546 def nodeProvider = _pillar['return'][0].values()[0]
547 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
548 sleep(2)
549 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
550 try {
551 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
552 } catch (Exception e) {
553 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
554 }
555 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400556 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200557
Jiri Broulik00d01092017-06-01 19:38:15 +0200558 // database restore section
559 try {
chnyda625f4b42017-10-11 14:10:31 +0200560 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100561 } catch (Exception e) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200562 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200563 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200564 try {
chnyda625f4b42017-10-11 14:10:31 +0200565 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100566 } catch (Exception e) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200567 common.warningMsg('Mysql service already stopped')
568 }
569 try {
chnyda625f4b42017-10-11 14:10:31 +0200570 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Jakub Josefa63f9862018-01-11 17:58:38 +0100571 } catch (Exception e) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200572 common.warningMsg('Files are not present')
573 }
574 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100575 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
576 } catch (Exception e) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200577 common.warningMsg('Directory already empty')
578 }
579 try {
chnyda625f4b42017-10-11 14:10:31 +0200580 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100581 } catch (Exception e) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200582 common.warningMsg('File is not present')
583 }
chnyda625f4b42017-10-11 14:10:31 +0200584 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
585 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Jiri Broulik00d01092017-06-01 19:38:15 +0200586 backup_dir = _pillar['return'][0].values()[0]
587 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
588 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200589 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
590 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
591 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200592
593 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200594 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200595
chnyda625f4b42017-10-11 14:10:31 +0200596 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik00d01092017-06-01 19:38:15 +0200597 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200598
Jakub Josefa63f9862018-01-11 17:58:38 +0100599 node_count = 1
600 for (t in control_target_hosts) {
601 def target = t.split("\\.")[0]
602 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
603 def nodeProvider = _pillar['return'][0].values()[0]
604 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
605 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400606 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100607 node_count = 1
608 for (t in proxy_target_hosts) {
609 def target = t.split("\\.")[0]
610 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
611 def nodeProvider = _pillar['return'][0].values()[0]
612 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
613 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400614 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200615
616 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100617 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100618
619 for (t in control_target_hosts) {
620 def target = t.split("\\.")[0]
621 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
622 }
623 for (t in proxy_target_hosts) {
624 def target = t.split("\\.")[0]
625 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
626 }
627
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100628 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
629 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Jiri Broulikf20c7672017-06-19 21:20:52 +0200630
Jakub Josefa63f9862018-01-11 17:58:38 +0100631 salt.cmdRun(pepperEnv, "${control_general_target}01*", '. /root/keystonerc; nova service-list; glance image-list; nova flavor-list; nova hypervisor-list; nova list; neutron net-list; cinder list; heat service-list')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400632 }
633 }
634 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100635}