blob: 7bf646c7b6a316e7a9a240b09f17e456c338c0b4 [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 Broulik8dabbfd2017-07-25 10:49:45 +020084 // wait until upg node is registered in salt-key
85 salt.minionPresent(saltMaster, 'I@salt:master', 'upg01')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020086
Jiri Broulik3792c962017-05-17 18:26:36 +020087 // salt '*' saltutil.refresh_pillar
88 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.refresh_pillar', [], null, true)
89 // salt '*' saltutil.sync_all
90 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.sync_all', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020091
Jiri Broulik3792c962017-05-17 18:26:36 +020092 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
93 try {
94 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
95 } catch (Exception e) {
96 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
97 }
98 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +020099
Jiri Broulik3792c962017-05-17 18:26:36 +0200100 // salt "upg*" state.sls rabbitmq
101 salt.enforceState(saltMaster, 'upg*', ['rabbitmq', 'memcached'])
102 try {
103 salt.enforceState(saltMaster, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
104 } catch (Exception e) {
105 common.warningMsg('salt-minion was restarted. We should continue to run')
106 }
107 try {
108 salt.enforceState(saltMaster, 'I@backupninja:server', ['salt.minion'])
109 } catch (Exception e) {
110 common.warningMsg('salt-minion was restarted. We should continue to run')
111 }
112 // salt '*' state.apply salt.minion.grains
113 //salt.enforceState(saltMaster, '*', 'salt.minion.grains')
114 // salt -C 'I@backupninja:server' state.sls backupninja
115 salt.enforceState(saltMaster, 'I@backupninja:server', 'backupninja')
116 // salt -C 'I@backupninja:client' state.sls backupninja
117 salt.enforceState(saltMaster, 'I@backupninja:client', 'backupninja')
118 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
Jiri Broulik90c6c7f2017-06-12 13:05:46 +0200119 try {
120 salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
121 } catch (Exception e) {
Jiri Broulik29cffe32017-06-12 14:15:19 +0200122 common.warningMsg('The ARP entry does not exist. We should continue to run.')
Jiri Broulik90c6c7f2017-06-12 13:05:46 +0200123 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200124 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
125 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
Jiri Broulik2be7f672017-05-25 11:07:06 +0200126 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200127
Jiri Broulik00d01092017-06-01 19:38:15 +0200128 salt.enforceState(saltMaster, 'I@xtrabackup:server', 'xtrabackup')
129 salt.enforceState(saltMaster, 'I@xtrabackup:client', 'openssh.client')
130 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
131 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200132
Jiri Broulik3792c962017-05-17 18:26:36 +0200133 def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
134 if(databases && databases != ""){
135 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
Jiri Broulik00d01092017-06-01 19:38:15 +0200136 for( i = 0; i < databasesList.size(); i++){
Jiri Broulik3792c962017-05-17 18:26:36 +0200137 if(databasesList[i].toLowerCase().contains('upgrade')){
138 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
139 common.warningMsg("removing database ${databasesList[i]}")
140 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
141 }
142 }
Jiri Broulik5a13a652017-05-18 14:33:32 +0200143 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client')
Jiri Broulik3792c962017-05-17 18:26:36 +0200144 }else{
145 common.errorMsg("No _upgrade databases were returned")
146 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200147
Jiri Broulik3792c962017-05-17 18:26:36 +0200148 try {
149 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
Jiri Broulik29cffe32017-06-12 14:15:19 +0200150 salt.runSaltProcessStep(saltMaster, 'upg*', 'service.restart', ['apache2'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200151 } catch (Exception e) {
Jiri Broulik08229c82017-05-22 23:35:32 +0200152 common.warningMsg('Restarting Apache2')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200153 salt.runSaltProcessStep(saltMaster, 'upg*', 'service.restart', ['apache2'], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200154 }
Jiri Broulik69de13a2017-05-18 13:53:58 +0200155 try {
156 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
157 } catch (Exception e) {
158 common.warningMsg('running keystone.client state again')
159 salt.enforceState(saltMaster, 'upg*', 'keystone.client')
160 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200161 try {
162 salt.enforceState(saltMaster, 'upg*', 'glance')
163 } catch (Exception e) {
164 common.warningMsg('running glance state again')
165 salt.enforceState(saltMaster, 'upg*', 'glance')
166 }
167 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
168 try {
169 salt.enforceState(saltMaster, 'upg*', 'nova')
170 } catch (Exception e) {
171 common.warningMsg('running nova state again')
172 salt.enforceState(saltMaster, 'upg*', 'nova')
173 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200174 // run nova state again as sometimes nova does not enforce itself for some reason
175 try {
176 salt.enforceState(saltMaster, 'upg*', 'nova')
177 } catch (Exception e) {
178 common.warningMsg('running nova state again')
179 salt.enforceState(saltMaster, 'upg*', 'nova')
180 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200181 try {
182 salt.enforceState(saltMaster, 'upg*', 'cinder')
183 } catch (Exception e) {
184 common.warningMsg('running cinder state again')
185 salt.enforceState(saltMaster, 'upg*', 'cinder')
186 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200187 try {
188 salt.enforceState(saltMaster, 'upg*', 'neutron')
189 } catch (Exception e) {
190 common.warningMsg('running neutron state again')
191 salt.enforceState(saltMaster, 'upg*', 'neutron')
192 }
Jiri Broulikbda0a212017-05-18 12:54:51 +0200193 try {
194 salt.enforceState(saltMaster, 'upg*', 'heat')
195 } catch (Exception e) {
196 common.warningMsg('running heat state again')
197 salt.enforceState(saltMaster, 'upg*', 'heat')
198 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200199 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 +0200200
Jiri Broulik08229c82017-05-22 23:35:32 +0200201 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
202 stage('Ask for manual confirmation') {
203 input message: "Do you want to continue with upgrade?"
204 }
205 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200206 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200207 }
208
Jiri Broulik3792c962017-05-17 18:26:36 +0200209 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
210 stage('Real upgrade') {
211 // # actual upgrade
212
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200213 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
214 domain = _pillar['return'][0].values()[0].values()[0]
215 print(_pillar)
216 print(domain)
217
218 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
219 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200220 print(_pillar)
221 print(kvm01)
Jiri Broulik80d96752017-05-22 19:42:01 +0200222
223 def errorOccured = false
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200224
Jiri Broulik3792c962017-05-17 18:26:36 +0200225 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
226 def ctl01NodeProvider = _pillar['return'][0].values()[0]
227
228 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
229 def ctl02NodeProvider = _pillar['return'][0].values()[0]
230
231 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
232 def ctl03NodeProvider = _pillar['return'][0].values()[0]
233
234 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
235 def prx01NodeProvider = _pillar['return'][0].values()[0]
236
237 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
238 def prx02NodeProvider = _pillar['return'][0].values()[0]
239
240
241 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
242 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
243 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
244 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
245 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
246
247
248 try {
249 salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak")
250 } catch (Exception e) {
251 common.warningMsg('File already exists')
252 }
253 try {
254 salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak")
255 } catch (Exception e) {
256 common.warningMsg('File already exists')
257 }
258 try {
259 salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak")
260 } catch (Exception e) {
261 common.warningMsg('File already exists')
262 }
263 try {
264 salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak")
265 } catch (Exception e) {
266 common.warningMsg('File already exists')
267 }
268 try {
269 salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak")
270 } catch (Exception e) {
271 common.warningMsg('File already exists')
272 }
273
274
275 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true)
276 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true)
277 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true)
278 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true)
279 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true)
280
Jiri Broulik00d01092017-06-01 19:38:15 +0200281 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik3792c962017-05-17 18:26:36 +0200282
283 try {
284 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
285 } catch (Exception e) {
286 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
287 }
288
289 // salt 'kvm*' state.sls salt.control
290 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control')
291
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200292 // wait until ctl and prx nodes are registered in salt-key
293 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl01')
294 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl02')
295 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl03')
296 salt.minionPresent(saltMaster, 'I@salt:master', 'prx01')
297 salt.minionPresent(saltMaster, 'I@salt:master', 'prx02')
298
Jiri Broulik3792c962017-05-17 18:26:36 +0200299
300 // salt '*' saltutil.refresh_pillar
301 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
302 // salt '*' saltutil.sync_all
303 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
304
305 try {
306 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
307 } catch (Exception e) {
308 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
309 }
310 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
311
312 // salt 'ctl*' state.sls keepalived
313 // salt 'ctl*' state.sls haproxy
314 salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy'])
315 // salt 'ctl*' service.restart rsyslog
316 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true)
317 // salt "ctl*" state.sls memcached
318 // salt "ctl*" state.sls keystone.server
319 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200320 try {
321 salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server'])
Jiri Broulik29cffe32017-06-12 14:15:19 +0200322 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['apache2'], null, true)
Jiri Broulik69de13a2017-05-18 13:53:58 +0200323 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200324 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik5a13a652017-05-18 14:33:32 +0200325 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['apache2'], null, true)
Jiri Broulik69de13a2017-05-18 13:53:58 +0200326 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
327 }
328 // salt 'ctl01*' state.sls keystone.client
329 try {
330 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
331 } catch (Exception e) {
332 common.warningMsg('running keystone.client state again')
333 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
334 }
335 try {
336 salt.enforceState(saltMaster, 'ctl*', 'glance')
337 } catch (Exception e) {
338 common.warningMsg('running glance state again')
339 salt.enforceState(saltMaster, 'ctl*', 'glance')
340 } // salt 'ctl*' state.sls glusterfs.client
341 salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client')
342 // salt 'ctl*' state.sls keystone.server
343 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
344 // salt 'ctl*' state.sls nova
345 try {
346 salt.enforceState(saltMaster, 'ctl*', 'nova')
347 } catch (Exception e) {
348 common.warningMsg('running nova state again')
349 salt.enforceState(saltMaster, 'ctl*', 'nova')
350 }
351 // salt 'ctl*' state.sls cinder
352 try {
353 salt.enforceState(saltMaster, 'ctl*', 'cinder')
354 } catch (Exception e) {
355 common.warningMsg('running cinder state again')
356 salt.enforceState(saltMaster, 'ctl*', 'cinder')
357 }
358 try {
359 salt.enforceState(saltMaster, 'ctl*', 'neutron')
360 } catch (Exception e) {
361 common.warningMsg('running neutron state again')
362 salt.enforceState(saltMaster, 'ctl*', 'neutron')
363 }
364 // salt 'ctl*' state.sls heat
365 try {
366 salt.enforceState(saltMaster, 'ctl*', 'heat')
367 } catch (Exception e) {
368 common.warningMsg('running heat state again')
369 salt.enforceState(saltMaster, 'ctl*', 'heat')
370 }
371
Jiri Broulik3792c962017-05-17 18:26:36 +0200372 } catch (Exception e) {
Jiri Broulik80d96752017-05-22 19:42:01 +0200373 errorOccured = true
Jiri Broulik69de13a2017-05-18 13:53:58 +0200374 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik00d01092017-06-01 19:38:15 +0200375
376 // database restore section
377 try {
378 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
379 } catch (Exception er) {
380 common.warningMsg('Mysql service already stopped')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200381 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200382 try {
383 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
384 } catch (Exception er) {
385 common.warningMsg('Mysql service already stopped')
386 }
387 try {
388 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
389 } catch (Exception er) {
390 common.warningMsg('Files are not present')
391 }
392 try {
393 salt.cmdRun(saltMaster, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
394 } catch (Exception er) {
395 common.warningMsg('Directory already exists')
396 }
397 try {
398 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
399 } catch (Exception er) {
400 common.warningMsg('Directory already empty')
401 }
402 try {
403 salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
404 } catch (Exception er) {
405 common.warningMsg('Files were already moved')
406 }
407 try {
408 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
409 } catch (Exception er) {
410 common.warningMsg('File is not present')
411 }
412 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
413 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
414 backup_dir = _pillar['return'][0].values()[0]
415 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
416 print(backup_dir)
417 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
418 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
419 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200420
421 // wait until mysql service on galera master is up
422 salt.commandStatus(saltMaster, 'I@galera:master', 'service mysql status', 'running')
423
Jiri Broulik00d01092017-06-01 19:38:15 +0200424 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
425 //
426
Jiri Broulik5a13a652017-05-18 14:33:32 +0200427 common.errorMsg("Stage Real control upgrade failed")
Jiri Broulik3792c962017-05-17 18:26:36 +0200428 }
Jiri Broulik80d96752017-05-22 19:42:01 +0200429 if(!errorOccured){
Jiri Broulik52a6b832017-06-16 13:05:08 +0200430
431 ceph = null
432
433 try {
434 ceph = salt.cmdRun(saltMaster, 'ctl*', "salt-call grains.item roles | grep ceph.client")
435
436 } catch (Exception er) {
437 common.infoMsg("Ceph is not used")
438 }
439
440 if(ceph != null) {
441 try {
442 salt.enforceState(saltMaster, 'ctl*', 'ceph.client')
443 } catch (Exception er) {
444 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
445 }
446 }
447
Jiri Broulik80d96752017-05-22 19:42:01 +0200448 // salt 'cmp*' cmd.run 'service nova-compute restart'
449 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
Jiri Broulikf20c7672017-06-19 21:20:52 +0200450 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['nova-conductor'], null, true)
451 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['nova-scheduler'], null, true)
452
Jiri Broulik3792c962017-05-17 18:26:36 +0200453
Jiri Broulik00d01092017-06-01 19:38:15 +0200454 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
Jiri Broulik80d96752017-05-22 19:42:01 +0200455 // salt 'ctl*' state.sls keepalived
456 // salt 'prx*' state.sls keepalived
457 salt.enforceState(saltMaster, 'prx*', 'keepalived')
458 // salt 'prx*' state.sls horizon
459 salt.enforceState(saltMaster, 'prx*', 'horizon')
460 // salt 'prx*' state.sls nginx
461 salt.enforceState(saltMaster, 'prx*', 'nginx')
Tatyana Leontovich09616cd2017-07-10 14:19:46 +0300462 // salt "prx*" state.sls memcached
463 salt.enforceState(saltMaster, 'prx*', 'memcached')
Jiri Broulik3792c962017-05-17 18:26:36 +0200464
Jiri Broulik4df0c1f2017-06-23 11:29:29 +0200465 try {
466 salt.enforceHighstate(saltMaster, 'ctl*')
467 } catch (Exception er) {
468 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
469 }
470
471 try {
472 salt.enforceHighstate(saltMaster, 'prx*')
473 } catch (Exception er) {
474 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
475 }
476
Jiri Broulik80d96752017-05-22 19:42:01 +0200477 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')
478 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200479 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200480
Jiri Broulik08229c82017-05-22 23:35:32 +0200481 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
482 stage('Ask for manual confirmation') {
483 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?"
484 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200485 }
486 }
487
488 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
489 stage('Rollback upgrade') {
490
Jiri Broulik08229c82017-05-22 23:35:32 +0200491 stage('Ask for manual confirmation') {
492 input message: "Do you really want to continue with the rollback?"
493 }
494
Jiri Broulike2f1e4a2017-05-17 23:59:52 +0200495 _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
496 domain = _pillar['return'][0].values()[0].values()[0]
497 print(_pillar)
498 print(domain)
499
Jiri Broulikd98364e2017-05-18 15:30:04 +0200500 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
501 kvm01 = _pillar['return'][0].values()[0].values()[0]
Jiri Broulikd98364e2017-05-18 15:30:04 +0200502 print(_pillar)
503 print(kvm01)
Jiri Broulikd98364e2017-05-18 15:30:04 +0200504
505 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
506 def ctl01NodeProvider = _pillar['return'][0].values()[0]
507
508 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
509 def ctl02NodeProvider = _pillar['return'][0].values()[0]
510
511 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
512 def ctl03NodeProvider = _pillar['return'][0].values()[0]
513
514 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
515 def prx01NodeProvider = _pillar['return'][0].values()[0]
516
517 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
518 def prx02NodeProvider = _pillar['return'][0].values()[0]
519
Jiri Broulik3792c962017-05-17 18:26:36 +0200520 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
521 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
522 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
523 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
524 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
525
526 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true)
527 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true)
528 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true)
529 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true)
530 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true)
531
532 try {
533 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
534 } catch (Exception e) {
535 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
536 }
537
Jiri Broulik00d01092017-06-01 19:38:15 +0200538 // database restore section
539 try {
540 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
541 } catch (Exception e) {
542 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200543 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200544 try {
545 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
546 } catch (Exception e) {
547 common.warningMsg('Mysql service already stopped')
548 }
549 try {
550 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
551 } catch (Exception e) {
552 common.warningMsg('Files are not present')
553 }
554 try {
555 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*")
556 } catch (Exception e) {
557 common.warningMsg('Directory already empty')
558 }
559 try {
560 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
561 } catch (Exception e) {
562 common.warningMsg('File is not present')
563 }
564 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
565 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
566 backup_dir = _pillar['return'][0].values()[0]
567 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
568 print(backup_dir)
569 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
570 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
571 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200572
573 // wait until mysql service on galera master is up
574 salt.commandStatus(saltMaster, 'I@galera:master', 'service mysql status', 'running')
575
Jiri Broulik00d01092017-06-01 19:38:15 +0200576 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
577 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200578
Jiri Broulik3792c962017-05-17 18:26:36 +0200579 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true)
580 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true)
581 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true)
582 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true)
583 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true)
584
585 // salt 'cmp*' cmd.run 'service nova-compute restart'
586 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
587
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200588 // wait until ctl and prx nodes are registered in salt-key
589 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl01')
590 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl02')
591 salt.minionPresent(saltMaster, 'I@salt:master', 'ctl03')
592 salt.minionPresent(saltMaster, 'I@salt:master', 'prx01')
593 salt.minionPresent(saltMaster, 'I@salt:master', 'prx02')
Jiri Broulik3792c962017-05-17 18:26:36 +0200594
Jiri Broulikf20c7672017-06-19 21:20:52 +0200595 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['nova-conductor'], null, true)
596 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['nova-scheduler'], null, true)
597
Jiri Broulik3792c962017-05-17 18:26:36 +0200598 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')
599 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200600 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200601 }
602}