blob: 333c16b7a9d5d6cab7d7efbabbb0fe75f5399ee0 [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
29 //salt.enforceState(saltMaster, 'I@salt:master', 'reclass')
30
31 // salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
32 // salt '*' saltutil.sync_all
33 // salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
34
35
36 def _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain')
37 def domain = _pillar['return'][0].values()[0].values()[0]
38 print(_pillar)
39 print(domain)
40
41 // read backupninja variable
42 _pillar = salt.getPillar(saltMaster, 'I@backupninja:client', '_param:backupninja_backup_host')
43 def backupninja_backup_host = _pillar['return'][0].values()[0]
44 print(_pillar)
45 print(backupninja_backup_host)
46
47 _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id')
48 def kvm01 = _pillar['return'][0].values()[0].values()[0]
49 def kvm03 = _pillar['return'][0].values()[2].values()[0]
50 def kvm02 = _pillar['return'][0].values()[1].values()[0]
51 print(_pillar)
52 print(kvm01)
53 print(kvm02)
54 print(kvm03)
55
56 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider')
57 def upgNodeProvider = _pillar['return'][0].values()[0]
58 print(_pillar)
59 print(upgNodeProvider)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020060
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020061
Jiri Broulik3792c962017-05-17 18:26:36 +020062 salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true)
63 salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020064
Jiri Broulik3792c962017-05-17 18:26:36 +020065
66 try {
Jiri Broulikd6bc1382017-05-17 18:46:27 +020067 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d upg01.${domain} -y")
Jiri Broulik3792c962017-05-17 18:26:36 +020068 } catch (Exception e) {
Jiri Broulikd6bc1382017-05-17 18:46:27 +020069 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 +020070 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020071
72
Jiri Broulik3792c962017-05-17 18:26:36 +020073 // salt 'kvm02*' state.sls salt.control
74 salt.enforceState(saltMaster, "${upgNodeProvider}", 'salt.control')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020075
Jiri Broulik3792c962017-05-17 18:26:36 +020076 sleep(60)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020077
Jiri Broulik3792c962017-05-17 18:26:36 +020078 // salt '*' saltutil.refresh_pillar
79 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.refresh_pillar', [], null, true)
80 // salt '*' saltutil.sync_all
81 salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.sync_all', [], null, true)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020082
Jiri Broulik3792c962017-05-17 18:26:36 +020083 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
84 try {
85 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
86 } catch (Exception e) {
87 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
88 }
89 salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +020090
Jiri Broulik3792c962017-05-17 18:26:36 +020091 // salt "upg*" state.sls rabbitmq
92 salt.enforceState(saltMaster, 'upg*', ['rabbitmq', 'memcached'])
93 try {
94 salt.enforceState(saltMaster, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
95 } catch (Exception e) {
96 common.warningMsg('salt-minion was restarted. We should continue to run')
97 }
98 try {
99 salt.enforceState(saltMaster, 'I@backupninja:server', ['salt.minion'])
100 } catch (Exception e) {
101 common.warningMsg('salt-minion was restarted. We should continue to run')
102 }
103 // salt '*' state.apply salt.minion.grains
104 //salt.enforceState(saltMaster, '*', 'salt.minion.grains')
105 // salt -C 'I@backupninja:server' state.sls backupninja
106 salt.enforceState(saltMaster, 'I@backupninja:server', 'backupninja')
107 // salt -C 'I@backupninja:client' state.sls backupninja
108 salt.enforceState(saltMaster, 'I@backupninja:client', 'backupninja')
109 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
110 salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
111 salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
112 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
113 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200114
115
Jiri Broulik3792c962017-05-17 18:26:36 +0200116 def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
117 if(databases && databases != ""){
118 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
119 for( i = 0; i < databasesList.size(); i++){
120 if(databasesList[i].toLowerCase().contains('upgrade')){
121 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
122 common.warningMsg("removing database ${databasesList[i]}")
123 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
124 }
125 }
126 }else{
127 common.errorMsg("No _upgrade databases were returned")
128 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200129
Jiri Broulik3792c962017-05-17 18:26:36 +0200130 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200131
Jiri Broulik3792c962017-05-17 18:26:36 +0200132 try {
133 salt.enforceState(saltMaster, 'upg*', 'keystone.server')
134 } catch (Exception e) {
135 salt.runSaltProcessStep(saltMaster, 'upg*', 'service.reload', ['apache2'], null, true)
136 common.warningMsg('reload of apache2. We should continue to run')
137 }
138 salt.enforceState(saltMaster, 'upg*', ['keystone.client', 'glance', 'keystone.server'])
139 salt.enforceState(saltMaster, 'upg*', 'nova')
140 salt.enforceState(saltMaster, 'upg*', ['cinder', 'neutron', 'heat'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200141
Jiri Broulik3792c962017-05-17 18:26:36 +0200142 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')
143 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200144 }
145
Jiri Broulik3792c962017-05-17 18:26:36 +0200146 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
147 stage('Ask for manual confirmation') {
148 input message: "Do you want to continue with upgrade?"
149 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200150 }
151
Jiri Broulik3792c962017-05-17 18:26:36 +0200152
153 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
154 stage('Real upgrade') {
155 // # actual upgrade
156
157 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
158 def ctl01NodeProvider = _pillar['return'][0].values()[0]
159
160 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
161 def ctl02NodeProvider = _pillar['return'][0].values()[0]
162
163 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
164 def ctl03NodeProvider = _pillar['return'][0].values()[0]
165
166 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
167 def prx01NodeProvider = _pillar['return'][0].values()[0]
168
169 _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
170 def prx02NodeProvider = _pillar['return'][0].values()[0]
171
172
173 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
174 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
175 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
176 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
177 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
178
179
180 try {
181 salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak")
182 } catch (Exception e) {
183 common.warningMsg('File already exists')
184 }
185 try {
186 salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak")
187 } catch (Exception e) {
188 common.warningMsg('File already exists')
189 }
190 try {
191 salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak")
192 } catch (Exception e) {
193 common.warningMsg('File already exists')
194 }
195 try {
196 salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak")
197 } catch (Exception e) {
198 common.warningMsg('File already exists')
199 }
200 try {
201 salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak")
202 } catch (Exception e) {
203 common.warningMsg('File already exists')
204 }
205
206
207 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true)
208 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true)
209 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true)
210 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true)
211 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true)
212
213
214 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
215 salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync')
216
217
218 try {
219 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
220 } catch (Exception e) {
221 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
222 }
223
224 // salt 'kvm*' state.sls salt.control
225 salt.enforceState(saltMaster, 'I@salt:control', 'salt.control')
226
227 sleep(60)
228
229 // salt '*' saltutil.refresh_pillar
230 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
231 // salt '*' saltutil.sync_all
232 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true)
233
234 try {
235 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
236 } catch (Exception e) {
237 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
238 }
239 salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
240
241 // salt 'ctl*' state.sls keepalived
242 // salt 'ctl*' state.sls haproxy
243 salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy'])
244 // salt 'ctl*' service.restart rsyslog
245 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true)
246 // salt "ctl*" state.sls memcached
247 // salt "ctl*" state.sls keystone.server
248 try {
249 salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server'])
250 } catch (Exception e) {
251 salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.reload', ['apache2'], null, true)
252 common.warningMsg('reload of apache2. We should continue to run')
253 }
254 // salt 'ctl01*' state.sls keystone.client
255 salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client')
256 // salt 'ctl*' state.sls glance
257 salt.enforceState(saltMaster, 'ctl*', 'glance')
258 // salt 'ctl*' state.sls glusterfs.client
259 salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client')
260 // salt 'ctl*' state.sls keystone.server
261 salt.enforceState(saltMaster, 'ctl*', 'keystone.server')
262 // salt 'ctl*' state.sls nova
263 salt.enforceState(saltMaster, 'ctl*', 'nova')
264 // salt 'ctl*' state.sls cinder
265 salt.enforceState(saltMaster, 'ctl*', 'cinder')
266 // salt 'ctl*' state.sls neutron
267 salt.enforceState(saltMaster, 'ctl*', 'neutron')
268 // salt 'ctl*' state.sls heat
269 salt.enforceState(saltMaster, 'ctl*', 'heat')
270
271 // salt 'cmp*' cmd.run 'service nova-compute restart'
272 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
273
274 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog - TODO: proč? už to jednou projelo
275 // salt 'ctl*' state.sls keepalived
276 // salt 'prx*' state.sls keepalived
277 salt.enforceState(saltMaster, 'prx*', 'keepalived')
278 // salt 'prx*' state.sls horizon
279 salt.enforceState(saltMaster, 'prx*', 'horizon')
280 // salt 'prx*' state.sls nginx
281 salt.enforceState(saltMaster, 'prx*', 'nginx')
282
283 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')
284 }
285
286 }
287
288
289 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
290 stage('Ask for manual confirmation') {
291 input message: "Please verify that 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?"
292 }
293 stage('Ask for manual confirmation') {
294 input message: "Do you really want to continue with the rollback?"
295 }
296 }
297
298 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
299 stage('Rollback upgrade') {
300
301 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
302 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
303 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
304 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
305 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
306
307 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true)
308 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true)
309 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true)
310 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true)
311 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true)
312
313 try {
314 salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
315 } catch (Exception e) {
316 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
317 }
318
319 databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep -v \'upgrade\' | grep -v \'schema\' | awk \'/-/ {print \$2}\'')
320 if(databases && databases != ""){
321 databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
322 for( i = 0; i < databasesList.size(); i++){
323 if(!databasesList[i].toLowerCase().contains('upgrade') && !databasesList[i].toLowerCase().contains('command execution')){
324 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
325 common.warningMsg("removing database ${databasesList[i]}")
326 salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
327 }
328 }
329 }else{
330 common.errorMsg("No none _upgrade databases were returned")
331 }
332
333 salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client')
334
335 salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true)
336 salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true)
337 salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true)
338 salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true)
339 salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true)
340
341 // salt 'cmp*' cmd.run 'service nova-compute restart'
342 salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true)
343
344 sleep(60)
345
346 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')
347 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200348 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200349 }
350}