blob: 0bba70ed02c71bb37e82e42ae7cbcbac7b3ac71f [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 Broulikbb447ac2017-05-04 15:36:22 +020010 *
11**/
12
13def common = new com.mirantis.mk.Common()
14def salt = new com.mirantis.mk.Salt()
15
16
17def saltMaster
18
19timestamps {
20 node() {
21
22 stage('Connect to Salt API') {
23 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
24 }
25
Jiri Broulik3792c962017-05-17 18:26:36 +020026 if (STAGE_TEST_UPGRADE.toBoolean() == true) {
27 stage('Test upgrade') {
28
Jiri Broulik3792c962017-05-17 18:26:36 +020029
Jiri Broulik80d96752017-05-22 19:42:01 +020030 try {
31 salt.enforceState(saltMaster, 'I@salt:master', 'reclass')
32 } catch (Exception e) {
Jiri Broulik34674322017-05-25 19:10:57 +020033 common.warningMsg("Some parts of Reclass state failed. The most probable reasons were uncommited changes. We should continue to run")
Jiri Broulik80d96752017-05-22 19:42:01 +020034 }
35
Jiri Broulik34674322017-05-25 19:10:57 +020036 try {
37 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
38 } catch (Exception e) {
39 common.warningMsg("No response from some minions. We should continue to run")
40 }
Jiri Broulik3792c962017-05-17 18:26:36 +020041
Jiri Broulik34674322017-05-25 19:10:57 +020042 try {
43 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
44 } catch (Exception e) {
45 common.warningMsg("No response from some minions. We should continue to run")
46 }
Jiri Broulik3792c962017-05-17 18:26:36 +020047
48 def _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
49 def domain = _pillar['return'][0].values()[0].values()[0]
50 print(_pillar)
51 print(domain)
52
53 // read backupninja variable
54 _pillar = salt.getPillar(saltMaster, 'I@backupninja:client', '_param:backupninja_backup_host')
55 def backupninja_backup_host = _pillar['return'][0].values()[0]
56 print(_pillar)
57 print(backupninja_backup_host)
58
59 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
60 def kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulik3792c962017-05-17 18:26:36 +020061 print(_pillar)
62 print(kvm01)
Jiri Broulik3792c962017-05-17 18:26:36 +020063
64 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider')
65 def upgNodeProvider = _pillar['return'][0].values()[0]
66 print(_pillar)
67 print(upgNodeProvider)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020068
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020069
Jiri Broulik3792c962017-05-17 18:26:36 +020070 salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true)
71 salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020072
Jiri Broulik3792c962017-05-17 18:26:36 +020073
74 try {
Jiri Broulikd6bc1382017-05-17 18:46:27 +020075 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d upg01.${domain} -y")
Jiri Broulik3792c962017-05-17 18:26:36 +020076 } catch (Exception e) {
Jiri Broulikd6bc1382017-05-17 18:46:27 +020077 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 +020078 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020079
80
Jiri Broulik3792c962017-05-17 18:26:36 +020081 // salt 'kvm02*' state.sls salt.control
82 salt.enforceState(saltMaster, "${upgNodeProvider}", 'salt.control')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020083
Jiri Broulik9b73d6c2017-06-02 12:27:05 +020084 sleep(70)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020085
Jiri Broulik3792c962017-05-17 18:26:36 +020086 // salt '*' saltutil.refresh_pillar
87 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.refresh_pillar', [], null, true)
88 // salt '*' saltutil.sync_all
89 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.sync_all', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020090
Jiri Broulik3792c962017-05-17 18:26:36 +020091 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
92 try {
93 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
94 } catch (Exception e) {
95 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
96 }
97 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +020098
Jiri Broulik3792c962017-05-17 18:26:36 +020099 // salt "upg*" state.sls rabbitmq
100 salt.enforceState(saltMaster, 'upg*', ['rabbitmq', 'memcached'])
101 try {
102 salt.enforceState(saltMaster, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
103 } catch (Exception e) {
104 common.warningMsg('salt-minion was restarted. We should continue to run')
105 }
106 try {
107 salt.enforceState(saltMaster, 'I@backupninja:server', ['salt.minion'])
108 } catch (Exception e) {
109 common.warningMsg('salt-minion was restarted. We should continue to run')
110 }
111 // salt '*' state.apply salt.minion.grains
112 //salt.enforceState(saltMaster, '*', 'salt.minion.grains')
113 // salt -C 'I@backupninja:server' state.sls backupninja
114 salt.enforceState(saltMaster, 'I@backupninja:server', 'backupninja')
115 // salt -C 'I@backupninja:client' state.sls backupninja
116 salt.enforceState(saltMaster, 'I@backupninja:client', 'backupninja')
117 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
Jiri Broulik90c6c7f2017-06-12 13:05:46 +0200118 try {
119 salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
120 } catch (Exception e) {
121 common.warningMsg('arp entry does not exist you. We should continue to run.')
122 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200123 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
124 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
Jiri Broulik2be7f672017-05-25 11:07:06 +0200125 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200126
Jiri Broulik00d01092017-06-01 19:38:15 +0200127 salt.enforceState(saltMaster, 'I@xtrabackup:server', 'xtrabackup')
128 salt.enforceState(saltMaster, 'I@xtrabackup:client', 'openssh.client')
129 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
130 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200131
Jiri Broulik3792c962017-05-17 18:26:36 +0200132 def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
133 if(databases && databases != ""){
134 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
Jiri Broulik00d01092017-06-01 19:38:15 +0200135 for( i = 0; i < databasesList.size(); i++){
Jiri Broulik3792c962017-05-17 18:26:36 +0200136 if(databasesList[i].toLowerCase().contains('upgrade')){
137 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
138 common.warningMsg("removing database ${databasesList[i]}")
139 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
140 }
141 }
Jiri Broulik5a13a652017-05-18 14:33:32 +0200142 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client')
Jiri Broulik3792c962017-05-17 18:26:36 +0200143 }else{
144 common.errorMsg("No _upgrade databases were returned")
145 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200146
Jiri Broulik3792c962017-05-17 18:26:36 +0200147 try {
148 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
149 } catch (Exception e) {
Jiri Broulik08229c82017-05-22 23:35:32 +0200150 common.warningMsg('Restarting Apache2')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200151 salt.runSaltProcessStep(saltMaster, 'upg*', 'service.restart', ['apache2'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200152 }
Jiri Broulik69de13a2017-05-18 13:53:58 +0200153 try {
154 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
155 } catch (Exception e) {
156 common.warningMsg('running keystone.client state again')
157 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
158 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200159 try {
160 salt.enforceState(saltMaster, 'upg*', 'glance')
161 } catch (Exception e) {
162 common.warningMsg('running glance state again')
163 salt.enforceState(saltMaster, 'upg*', 'glance')
164 }
165 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
166 try {
167 salt.enforceState(saltMaster, 'upg*', 'nova')
168 } catch (Exception e) {
169 common.warningMsg('running nova state again')
170 salt.enforceState(saltMaster, 'upg*', 'nova')
171 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200172 // run nova state again as sometimes nova does not enforce itself for some reason
173 try {
174 salt.enforceState(saltMaster, 'upg*', 'nova')
175 } catch (Exception e) {
176 common.warningMsg('running nova state again')
177 salt.enforceState(saltMaster, 'upg*', 'nova')
178 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200179 try {
180 salt.enforceState(saltMaster, 'upg*', 'cinder')
181 } catch (Exception e) {
182 common.warningMsg('running cinder state again')
183 salt.enforceState(saltMaster, 'upg*', 'cinder')
184 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200185 try {
186 salt.enforceState(saltMaster, 'upg*', 'neutron')
187 } catch (Exception e) {
188 common.warningMsg('running neutron state again')
189 salt.enforceState(saltMaster, 'upg*', 'neutron')
190 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200191 try {
192 salt.enforceState(saltMaster, 'upg*', 'heat')
193 } catch (Exception e) {
194 common.warningMsg('running heat state again')
195 salt.enforceState(saltMaster, 'upg*', 'heat')
196 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200197 salt.cmdRun(saltMaster, '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')
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200198
Jiri Broulik08229c82017-05-22 23:35:32 +0200199 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
200 stage('Ask for manual confirmation') {
201 input message: "Do you want to continue with upgrade?"
202 }
203 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200204 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200205 }
206
Jiri Broulik3792c962017-05-17 18:26:36 +0200207 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
208 stage('Real upgrade') {
209 // # actual upgrade
210
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200211 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
212 domain = _pillar['return'][0].values()[0].values()[0]
213 print(_pillar)
214 print(domain)
215
216 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
217 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200218 print(_pillar)
219 print(kvm01)
Jiri Broulik80d96752017-05-22 19:42:01 +0200220
221 def errorOccured = false
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200222
Jiri Broulik3792c962017-05-17 18:26:36 +0200223 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
224 def ctl01NodeProvider = _pillar['return'][0].values()[0]
225
226 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
227 def ctl02NodeProvider = _pillar['return'][0].values()[0]
228
229 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
230 def ctl03NodeProvider = _pillar['return'][0].values()[0]
231
232 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
233 def prx01NodeProvider = _pillar['return'][0].values()[0]
234
235 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
236 def prx02NodeProvider = _pillar['return'][0].values()[0]
237
238
239 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
240 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
241 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
242 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
243 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
244
245
246 try {
247 salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak")
248 } catch (Exception e) {
249 common.warningMsg('File already exists')
250 }
251 try {
252 salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak")
253 } catch (Exception e) {
254 common.warningMsg('File already exists')
255 }
256 try {
257 salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak")
258 } catch (Exception e) {
259 common.warningMsg('File already exists')
260 }
261 try {
262 salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak")
263 } catch (Exception e) {
264 common.warningMsg('File already exists')
265 }
266 try {
267 salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak")
268 } catch (Exception e) {
269 common.warningMsg('File already exists')
270 }
271
272
273 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true)
274 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true)
275 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true)
276 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true)
277 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true)
278
Jiri Broulik00d01092017-06-01 19:38:15 +0200279 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik3792c962017-05-17 18:26:36 +0200280
281 try {
282 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
283 } catch (Exception e) {
284 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
285 }
286
287 // salt 'kvm*' state.sls salt.control
288 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control')
289
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200290 sleep(70)
Jiri Broulik3792c962017-05-17 18:26:36 +0200291
292 // salt '*' saltutil.refresh_pillar
293 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
294 // salt '*' saltutil.sync_all
295 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
296
297 try {
298 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
299 } catch (Exception e) {
300 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
301 }
302 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
303
304 // salt 'ctl*' state.sls keepalived
305 // salt 'ctl*' state.sls haproxy
306 salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy'])
307 // salt 'ctl*' service.restart rsyslog
308 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true)
309 // salt "ctl*" state.sls memcached
310 // salt "ctl*" state.sls keystone.server
311 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200312 try {
313 salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server'])
314 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200315 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200316 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['apache2'], null, true)
Jiri Broulik69de13a2017-05-18 13:53:58 +0200317 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
318 }
319 // salt 'ctl01*' state.sls keystone.client
320 try {
321 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
322 } catch (Exception e) {
323 common.warningMsg('running keystone.client state again')
324 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
325 }
326 try {
327 salt.enforceState(saltMaster, 'ctl*', 'glance')
328 } catch (Exception e) {
329 common.warningMsg('running glance state again')
330 salt.enforceState(saltMaster, 'ctl*', 'glance')
331 } // salt 'ctl*' state.sls glusterfs.client
332 salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client')
333 // salt 'ctl*' state.sls keystone.server
334 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
335 // salt 'ctl*' state.sls nova
336 try {
337 salt.enforceState(saltMaster, 'ctl*', 'nova')
338 } catch (Exception e) {
339 common.warningMsg('running nova state again')
340 salt.enforceState(saltMaster, 'ctl*', 'nova')
341 }
342 // salt 'ctl*' state.sls cinder
343 try {
344 salt.enforceState(saltMaster, 'ctl*', 'cinder')
345 } catch (Exception e) {
346 common.warningMsg('running cinder state again')
347 salt.enforceState(saltMaster, 'ctl*', 'cinder')
348 }
349 try {
350 salt.enforceState(saltMaster, 'ctl*', 'neutron')
351 } catch (Exception e) {
352 common.warningMsg('running neutron state again')
353 salt.enforceState(saltMaster, 'ctl*', 'neutron')
354 }
355 // salt 'ctl*' state.sls heat
356 try {
357 salt.enforceState(saltMaster, 'ctl*', 'heat')
358 } catch (Exception e) {
359 common.warningMsg('running heat state again')
360 salt.enforceState(saltMaster, 'ctl*', 'heat')
361 }
362
Jiri Broulik3792c962017-05-17 18:26:36 +0200363 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200364 errorOccured = true
Jiri Broulik69de13a2017-05-18 13:53:58 +0200365 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik00d01092017-06-01 19:38:15 +0200366
367 // database restore section
368 try {
369 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
370 } catch (Exception er) {
371 common.warningMsg('Mysql service already stopped')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200372 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200373 try {
374 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
375 } catch (Exception er) {
376 common.warningMsg('Mysql service already stopped')
377 }
378 try {
379 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
380 } catch (Exception er) {
381 common.warningMsg('Files are not present')
382 }
383 try {
384 salt.cmdRun(saltMaster, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
385 } catch (Exception er) {
386 common.warningMsg('Directory already exists')
387 }
388 try {
389 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
390 } catch (Exception er) {
391 common.warningMsg('Directory already empty')
392 }
393 try {
394 salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
395 } catch (Exception er) {
396 common.warningMsg('Files were already moved')
397 }
398 try {
399 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
400 } catch (Exception er) {
401 common.warningMsg('File is not present')
402 }
403 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
404 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
405 backup_dir = _pillar['return'][0].values()[0]
406 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
407 print(backup_dir)
408 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
409 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
410 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
411 sleep(5)
412 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
413 //
414
Jiri Broulik5a13a652017-05-18 14:33:32 +0200415 common.errorMsg("Stage Real control upgrade failed")
Jiri Broulik3792c962017-05-17 18:26:36 +0200416 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200417 if(!errorOccured){
418 // salt 'cmp*' cmd.run 'service nova-compute restart'
419 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200420
Jiri Broulik00d01092017-06-01 19:38:15 +0200421 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
Jiri Broulik80d96752017-05-22 19:42:01 +0200422 // salt 'ctl*' state.sls keepalived
423 // salt 'prx*' state.sls keepalived
424 salt.enforceState(saltMaster, 'prx*', 'keepalived')
425 // salt 'prx*' state.sls horizon
426 salt.enforceState(saltMaster, 'prx*', 'horizon')
427 // salt 'prx*' state.sls nginx
428 salt.enforceState(saltMaster, 'prx*', 'nginx')
Jiri Broulik3792c962017-05-17 18:26:36 +0200429
Jiri Broulik80d96752017-05-22 19:42:01 +0200430 salt.cmdRun(saltMaster, 'ctl01*', '. /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')
431 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200432 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200433
Jiri Broulik08229c82017-05-22 23:35:32 +0200434 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
435 stage('Ask for manual confirmation') {
436 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?"
437 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200438 }
439 }
440
441 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
442 stage('Rollback upgrade') {
443
Jiri Broulik08229c82017-05-22 23:35:32 +0200444 stage('Ask for manual confirmation') {
445 input message: "Do you really want to continue with the rollback?"
446 }
447
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200448 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
449 domain = _pillar['return'][0].values()[0].values()[0]
450 print(_pillar)
451 print(domain)
452
Jiri Broulikd98364e2017-05-18 15:30:04 +0200453 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
454 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulikd98364e2017-05-18 15:30:04 +0200455 print(_pillar)
456 print(kvm01)
Jiri Broulikd98364e2017-05-18 15:30:04 +0200457
458 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
459 def ctl01NodeProvider = _pillar['return'][0].values()[0]
460
461 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
462 def ctl02NodeProvider = _pillar['return'][0].values()[0]
463
464 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
465 def ctl03NodeProvider = _pillar['return'][0].values()[0]
466
467 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
468 def prx01NodeProvider = _pillar['return'][0].values()[0]
469
470 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
471 def prx02NodeProvider = _pillar['return'][0].values()[0]
472
Jiri Broulik3792c962017-05-17 18:26:36 +0200473 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
474 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
475 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
476 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
477 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
478
479 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true)
480 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true)
481 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true)
482 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true)
483 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true)
484
485 try {
486 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
487 } catch (Exception e) {
488 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
489 }
490
Jiri Broulik00d01092017-06-01 19:38:15 +0200491 // database restore section
492 try {
493 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
494 } catch (Exception e) {
495 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200496 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200497 try {
498 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
499 } catch (Exception e) {
500 common.warningMsg('Mysql service already stopped')
501 }
502 try {
503 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
504 } catch (Exception e) {
505 common.warningMsg('Files are not present')
506 }
507 try {
508 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*")
509 } catch (Exception e) {
510 common.warningMsg('Directory already empty')
511 }
512 try {
513 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
514 } catch (Exception e) {
515 common.warningMsg('File is not present')
516 }
517 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
518 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
519 backup_dir = _pillar['return'][0].values()[0]
520 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
521 print(backup_dir)
522 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
523 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
524 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
525 sleep(5)
526 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
527 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200528
Jiri Broulik3792c962017-05-17 18:26:36 +0200529 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true)
530 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true)
531 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true)
532 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true)
533 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true)
534
535 // salt 'cmp*' cmd.run 'service nova-compute restart'
536 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
537
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200538 sleep(70)
Jiri Broulik3792c962017-05-17 18:26:36 +0200539
540 salt.cmdRun(saltMaster, 'ctl01*', '. /root/keystonerc; nova service-list; glance image-list; nova flavor-list; nova hypervisor-list; nova list; neutron net-list; cinder list; heat service-list')
541 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200542 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200543 }
544}