blob: 66cdebb0c4f04f494a9f4cab686ce7d910110059 [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)
118 salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
119 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
120 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
Jiri Broulik2be7f672017-05-25 11:07:06 +0200121 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200122
Jiri Broulik00d01092017-06-01 19:38:15 +0200123 salt.enforceState(saltMaster, 'I@xtrabackup:server', 'xtrabackup')
124 salt.enforceState(saltMaster, 'I@xtrabackup:client', 'openssh.client')
125 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
126 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200127
Jiri Broulik3792c962017-05-17 18:26:36 +0200128 def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
129 if(databases && databases != ""){
130 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
Jiri Broulik00d01092017-06-01 19:38:15 +0200131 for( i = 0; i < databasesList.size(); i++){
Jiri Broulik3792c962017-05-17 18:26:36 +0200132 if(databasesList[i].toLowerCase().contains('upgrade')){
133 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
134 common.warningMsg("removing database ${databasesList[i]}")
135 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
136 }
137 }
Jiri Broulik5a13a652017-05-18 14:33:32 +0200138 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client')
Jiri Broulik3792c962017-05-17 18:26:36 +0200139 }else{
140 common.errorMsg("No _upgrade databases were returned")
141 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200142
Jiri Broulik3792c962017-05-17 18:26:36 +0200143 try {
144 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
145 } catch (Exception e) {
Jiri Broulik08229c82017-05-22 23:35:32 +0200146 common.warningMsg('Restarting Apache2')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200147 salt.runSaltProcessStep(saltMaster, 'upg*', 'service.restart', ['apache2'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200148 }
Jiri Broulik69de13a2017-05-18 13:53:58 +0200149 try {
150 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
151 } catch (Exception e) {
152 common.warningMsg('running keystone.client state again')
153 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
154 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200155 try {
156 salt.enforceState(saltMaster, 'upg*', 'glance')
157 } catch (Exception e) {
158 common.warningMsg('running glance state again')
159 salt.enforceState(saltMaster, 'upg*', 'glance')
160 }
161 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
162 try {
163 salt.enforceState(saltMaster, 'upg*', 'nova')
164 } catch (Exception e) {
165 common.warningMsg('running nova state again')
166 salt.enforceState(saltMaster, 'upg*', 'nova')
167 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200168 // run nova state again as sometimes nova does not enforce itself for some reason
169 try {
170 salt.enforceState(saltMaster, 'upg*', 'nova')
171 } catch (Exception e) {
172 common.warningMsg('running nova state again')
173 salt.enforceState(saltMaster, 'upg*', 'nova')
174 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200175 try {
176 salt.enforceState(saltMaster, 'upg*', 'cinder')
177 } catch (Exception e) {
178 common.warningMsg('running cinder state again')
179 salt.enforceState(saltMaster, 'upg*', 'cinder')
180 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200181 try {
182 salt.enforceState(saltMaster, 'upg*', 'neutron')
183 } catch (Exception e) {
184 common.warningMsg('running neutron state again')
185 salt.enforceState(saltMaster, 'upg*', 'neutron')
186 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200187 try {
188 salt.enforceState(saltMaster, 'upg*', 'heat')
189 } catch (Exception e) {
190 common.warningMsg('running heat state again')
191 salt.enforceState(saltMaster, 'upg*', 'heat')
192 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200193 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 +0200194
Jiri Broulik08229c82017-05-22 23:35:32 +0200195 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
196 stage('Ask for manual confirmation') {
197 input message: "Do you want to continue with upgrade?"
198 }
199 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200200 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200201 }
202
Jiri Broulik3792c962017-05-17 18:26:36 +0200203 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
204 stage('Real upgrade') {
205 // # actual upgrade
206
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200207 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
208 domain = _pillar['return'][0].values()[0].values()[0]
209 print(_pillar)
210 print(domain)
211
212 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
213 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200214 print(_pillar)
215 print(kvm01)
Jiri Broulik80d96752017-05-22 19:42:01 +0200216
217 def errorOccured = false
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200218
Jiri Broulik3792c962017-05-17 18:26:36 +0200219 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
220 def ctl01NodeProvider = _pillar['return'][0].values()[0]
221
222 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
223 def ctl02NodeProvider = _pillar['return'][0].values()[0]
224
225 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
226 def ctl03NodeProvider = _pillar['return'][0].values()[0]
227
228 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
229 def prx01NodeProvider = _pillar['return'][0].values()[0]
230
231 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
232 def prx02NodeProvider = _pillar['return'][0].values()[0]
233
234
235 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
236 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
237 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
238 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
239 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
240
241
242 try {
243 salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak")
244 } catch (Exception e) {
245 common.warningMsg('File already exists')
246 }
247 try {
248 salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak")
249 } catch (Exception e) {
250 common.warningMsg('File already exists')
251 }
252 try {
253 salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak")
254 } catch (Exception e) {
255 common.warningMsg('File already exists')
256 }
257 try {
258 salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak")
259 } catch (Exception e) {
260 common.warningMsg('File already exists')
261 }
262 try {
263 salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak")
264 } catch (Exception e) {
265 common.warningMsg('File already exists')
266 }
267
268
269 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true)
270 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true)
271 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true)
272 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true)
273 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true)
274
Jiri Broulik00d01092017-06-01 19:38:15 +0200275 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik3792c962017-05-17 18:26:36 +0200276
277 try {
278 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
279 } catch (Exception e) {
280 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
281 }
282
283 // salt 'kvm*' state.sls salt.control
284 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control')
285
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200286 sleep(70)
Jiri Broulik3792c962017-05-17 18:26:36 +0200287
288 // salt '*' saltutil.refresh_pillar
289 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
290 // salt '*' saltutil.sync_all
291 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
292
293 try {
294 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
295 } catch (Exception e) {
296 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
297 }
298 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
299
300 // salt 'ctl*' state.sls keepalived
301 // salt 'ctl*' state.sls haproxy
302 salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy'])
303 // salt 'ctl*' service.restart rsyslog
304 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true)
305 // salt "ctl*" state.sls memcached
306 // salt "ctl*" state.sls keystone.server
307 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200308 try {
309 salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server'])
310 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200311 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200312 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['apache2'], null, true)
Jiri Broulik69de13a2017-05-18 13:53:58 +0200313 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
314 }
315 // salt 'ctl01*' state.sls keystone.client
316 try {
317 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
318 } catch (Exception e) {
319 common.warningMsg('running keystone.client state again')
320 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
321 }
322 try {
323 salt.enforceState(saltMaster, 'ctl*', 'glance')
324 } catch (Exception e) {
325 common.warningMsg('running glance state again')
326 salt.enforceState(saltMaster, 'ctl*', 'glance')
327 } // salt 'ctl*' state.sls glusterfs.client
328 salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client')
329 // salt 'ctl*' state.sls keystone.server
330 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
331 // salt 'ctl*' state.sls nova
332 try {
333 salt.enforceState(saltMaster, 'ctl*', 'nova')
334 } catch (Exception e) {
335 common.warningMsg('running nova state again')
336 salt.enforceState(saltMaster, 'ctl*', 'nova')
337 }
338 // salt 'ctl*' state.sls cinder
339 try {
340 salt.enforceState(saltMaster, 'ctl*', 'cinder')
341 } catch (Exception e) {
342 common.warningMsg('running cinder state again')
343 salt.enforceState(saltMaster, 'ctl*', 'cinder')
344 }
345 try {
346 salt.enforceState(saltMaster, 'ctl*', 'neutron')
347 } catch (Exception e) {
348 common.warningMsg('running neutron state again')
349 salt.enforceState(saltMaster, 'ctl*', 'neutron')
350 }
351 // salt 'ctl*' state.sls heat
352 try {
353 salt.enforceState(saltMaster, 'ctl*', 'heat')
354 } catch (Exception e) {
355 common.warningMsg('running heat state again')
356 salt.enforceState(saltMaster, 'ctl*', 'heat')
357 }
358
Jiri Broulik3792c962017-05-17 18:26:36 +0200359 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200360 errorOccured = true
Jiri Broulik69de13a2017-05-18 13:53:58 +0200361 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik00d01092017-06-01 19:38:15 +0200362
363 // database restore section
364 try {
365 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
366 } catch (Exception er) {
367 common.warningMsg('Mysql service already stopped')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200368 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200369 try {
370 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
371 } catch (Exception er) {
372 common.warningMsg('Mysql service already stopped')
373 }
374 try {
375 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
376 } catch (Exception er) {
377 common.warningMsg('Files are not present')
378 }
379 try {
380 salt.cmdRun(saltMaster, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
381 } catch (Exception er) {
382 common.warningMsg('Directory already exists')
383 }
384 try {
385 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
386 } catch (Exception er) {
387 common.warningMsg('Directory already empty')
388 }
389 try {
390 salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
391 } catch (Exception er) {
392 common.warningMsg('Files were already moved')
393 }
394 try {
395 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
396 } catch (Exception er) {
397 common.warningMsg('File is not present')
398 }
399 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
400 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
401 backup_dir = _pillar['return'][0].values()[0]
402 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
403 print(backup_dir)
404 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
405 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
406 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
407 sleep(5)
408 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
409 //
410
Jiri Broulik5a13a652017-05-18 14:33:32 +0200411 common.errorMsg("Stage Real control upgrade failed")
Jiri Broulik3792c962017-05-17 18:26:36 +0200412 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200413 if(!errorOccured){
414 // salt 'cmp*' cmd.run 'service nova-compute restart'
415 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200416
Jiri Broulik00d01092017-06-01 19:38:15 +0200417 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
Jiri Broulik80d96752017-05-22 19:42:01 +0200418 // salt 'ctl*' state.sls keepalived
419 // salt 'prx*' state.sls keepalived
420 salt.enforceState(saltMaster, 'prx*', 'keepalived')
421 // salt 'prx*' state.sls horizon
422 salt.enforceState(saltMaster, 'prx*', 'horizon')
423 // salt 'prx*' state.sls nginx
424 salt.enforceState(saltMaster, 'prx*', 'nginx')
Jiri Broulik3792c962017-05-17 18:26:36 +0200425
Jiri Broulik80d96752017-05-22 19:42:01 +0200426 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')
427 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200428 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200429
Jiri Broulik08229c82017-05-22 23:35:32 +0200430 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
431 stage('Ask for manual confirmation') {
432 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?"
433 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200434 }
435 }
436
437 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
438 stage('Rollback upgrade') {
439
Jiri Broulik08229c82017-05-22 23:35:32 +0200440 stage('Ask for manual confirmation') {
441 input message: "Do you really want to continue with the rollback?"
442 }
443
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200444 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
445 domain = _pillar['return'][0].values()[0].values()[0]
446 print(_pillar)
447 print(domain)
448
Jiri Broulikd98364e2017-05-18 15:30:04 +0200449 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
450 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulikd98364e2017-05-18 15:30:04 +0200451 print(_pillar)
452 print(kvm01)
Jiri Broulikd98364e2017-05-18 15:30:04 +0200453
454 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
455 def ctl01NodeProvider = _pillar['return'][0].values()[0]
456
457 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
458 def ctl02NodeProvider = _pillar['return'][0].values()[0]
459
460 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
461 def ctl03NodeProvider = _pillar['return'][0].values()[0]
462
463 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
464 def prx01NodeProvider = _pillar['return'][0].values()[0]
465
466 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
467 def prx02NodeProvider = _pillar['return'][0].values()[0]
468
Jiri Broulik3792c962017-05-17 18:26:36 +0200469 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
470 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
471 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
472 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
473 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
474
475 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true)
476 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true)
477 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true)
478 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true)
479 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true)
480
481 try {
482 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
483 } catch (Exception e) {
484 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
485 }
486
Jiri Broulik00d01092017-06-01 19:38:15 +0200487 // database restore section
488 try {
489 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
490 } catch (Exception e) {
491 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200492 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200493 try {
494 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
495 } catch (Exception e) {
496 common.warningMsg('Mysql service already stopped')
497 }
498 try {
499 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
500 } catch (Exception e) {
501 common.warningMsg('Files are not present')
502 }
503 try {
504 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*")
505 } catch (Exception e) {
506 common.warningMsg('Directory already empty')
507 }
508 try {
509 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
510 } catch (Exception e) {
511 common.warningMsg('File is not present')
512 }
513 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
514 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
515 backup_dir = _pillar['return'][0].values()[0]
516 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
517 print(backup_dir)
518 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
519 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
520 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
521 sleep(5)
522 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
523 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200524
Jiri Broulik3792c962017-05-17 18:26:36 +0200525 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true)
526 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true)
527 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true)
528 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true)
529 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true)
530
531 // salt 'cmp*' cmd.run 'service nova-compute restart'
532 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
533
Jiri Broulik9b73d6c2017-06-02 12:27:05 +0200534 sleep(70)
Jiri Broulik3792c962017-05-17 18:26:36 +0200535
536 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')
537 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200538 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200539 }
540}