blob: d306e34a9c443476b5598a2b5da456a0ed41983d [file] [log] [blame]
Jiri Broulikbb447ac2017-05-04 15:36:22 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
Jiri Brouliked3a9e62018-02-13 16:08:40 +01005 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
7 * 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)
10 * SKIP_VM_RELAUNCH Set to true if vms should not be recreated (bool)
11 * OPERATING_SYSTEM_RELEASE_UPGRADE Set to true if operating system of vms should be upgraded to newer release (bool)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020012 *
13**/
14
15def common = new com.mirantis.mk.Common()
16def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020017def python = new com.mirantis.mk.Python()
Jiri Broulikbb447ac2017-05-04 15:36:22 +020018
Jiri Broulik0d111e92018-04-25 21:30:42 +020019def getNodeProvider(pepperEnv, name) {
20 def salt = new com.mirantis.mk.Salt()
21 def kvm = salt.getKvmMinionId(pepperEnv)
22 return salt.getReturnValues(salt.getPillar(pepperEnv, "${kvm}", "salt:control:cluster:internal:node:${name}:provider"))
23}
24
Jiri Brouliked3a9e62018-02-13 16:08:40 +010025def stopServices(pepperEnv, probe, target, type) {
26 def openstack = new com.mirantis.mk.Openstack()
27 def services = []
28 if (type == 'prx') {
29 services.add('keepalived')
30 services.add('nginx')
31 } else if (type == 'ctl') {
32 services.add('keepalived')
33 services.add('haproxy')
34 services.add('nova')
35 services.add('cinder')
36 services.add('glance')
37 services.add('heat')
38 services.add('neutron')
39 services.add('apache2')
40 }
41 openstack.stopServices(pepperEnv, probe, target, services)
42}
43
44def retryStateRun(pepperEnv, target, state) {
45 def common = new com.mirantis.mk.Common()
46 def salt = new com.mirantis.mk.Salt()
47 try {
48 salt.enforceState(pepperEnv, target, state)
49 } catch (Exception e) {
50 common.warningMsg("running ${state} state again")
51 salt.enforceState(pepperEnv, target, state)
52 }
53}
54
55def stateRun(pepperEnv, target, state) {
56 def common = new com.mirantis.mk.Common()
57 def salt = new com.mirantis.mk.Salt()
58 try {
59 salt.enforceState(pepperEnv, target, state)
60 } catch (Exception e) {
61 common.warningMsg("Some parts of ${state} state failed. We should continue to run.")
62 }
63}
64
65
66def vcpTestUpgrade(pepperEnv) {
67 def common = new com.mirantis.mk.Common()
68 def salt = new com.mirantis.mk.Salt()
69 def test_upgrade_node = "upg01"
70 salt.runSaltProcessStep(pepperEnv, 'I@salt:master', 'saltutil.refresh_pillar', [], null, true, 2)
71
72 stateRun(pepperEnv, 'I@salt:master', 'linux.system.repo')
73 stateRun(pepperEnv, 'I@salt:master', 'salt.master')
74 stateRun(pepperEnv, 'I@salt:master', 'reclass')
75 stateRun(pepperEnv, 'I@salt:master', 'linux.system.repo')
76
77 try {
78 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true, 2)
79 } catch (Exception e) {
80 common.warningMsg("No response from some minions. We should continue to run")
81 }
82
83 try {
84 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true, 2)
85 } catch (Exception e) {
86 common.warningMsg("No response from some minions. We should continue to run")
87 }
88
89 def domain = salt.getDomainName(pepperEnv)
90
91 def backupninja_backup_host = salt.getReturnValues(salt.getPillar(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', '_param:backupninja_backup_host'))
92
93 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
94
Jiri Broulik0d111e92018-04-25 21:30:42 +020095 def upgNodeProvider = getNodeProvider(pepperEnv, test_upgrade_node)
Jiri Brouliked3a9e62018-02-13 16:08:40 +010096
97 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["${test_upgrade_node}.${domain}"])
98 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["${test_upgrade_node}.${domain}"])
99
100 try {
101 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${test_upgrade_node}.${domain} -y")
102 } catch (Exception e) {
103 common.warningMsg("${test_upgrade_node}.${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")
104 }
105
106 // salt 'kvm02*' state.sls salt.control
Jiri Broulik3818cb22018-04-27 18:39:00 +0200107 stateRun(pepperEnv, "${upgNodeProvider}", 'salt.control')
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100108 // wait until upg node is registered in salt-key
109 salt.minionPresent(pepperEnv, 'I@salt:master', test_upgrade_node)
110 // salt '*' saltutil.refresh_pillar
111 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'saltutil.refresh_pillar', [])
112 // salt '*' saltutil.sync_all
113 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'saltutil.sync_all', [])
114 }
115
Jiri Broulik827d0112018-04-25 16:00:07 +0200116 stateRun(pepperEnv, "${test_upgrade_node}*", ['linux.network.proxy'])
117 try {
118 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'state.sls', ["salt.minion.base"], null, true, 60)
119 } catch (Exception e) {
120 common.warningMsg(e)
121 }
122
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100123 stateRun(pepperEnv, "${test_upgrade_node}*", ['linux', 'openssh'])
124
125 try {
Jiri Broulik827d0112018-04-25 16:00:07 +0200126 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'state.sls', ["salt.minion"], null, true, 60)
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100127 } catch (Exception e) {
128 common.warningMsg(e)
129 }
130 stateRun(pepperEnv, "${test_upgrade_node}*", ['ntp', 'rsyslog'])
131 salt.enforceState(pepperEnv, "${test_upgrade_node}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
132 salt.enforceState(pepperEnv, "${test_upgrade_node}*", ['rabbitmq', 'memcached'])
133 try {
134 salt.enforceState(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', ['openssh.client', 'salt.minion'])
135 } catch (Exception e) {
136 common.warningMsg('salt-minion was restarted. We should continue to run')
137 }
Jiri Broulik3818cb22018-04-27 18:39:00 +0200138 salt.runSaltProcessStep(master, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'saltutil.sync_grains')
139 salt.runSaltProcessStep(master, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'mine.flush')
140 salt.runSaltProcessStep(master, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'mine.update')
141 salt.enforceState(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'backupninja')
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100142 try {
143 salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion'])
144 } catch (Exception e) {
145 common.warningMsg('salt-minion was restarted. We should continue to run')
146 }
Jiri Broulik3818cb22018-04-27 18:39:00 +0200147
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100148 salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja')
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100149 salt.runSaltProcessStep(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"])
150 try {
151 salt.cmdRun(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', "arp -d ${backupninja_backup_host}")
152 } catch (Exception e) {
153 common.warningMsg('The ARP entry does not exist. We should continue to run.')
154 }
155 salt.runSaltProcessStep(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"])
156 salt.cmdRun(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
157 salt.cmdRun(pepperEnv, '( I@galera:master or I@galera:slave ) and I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
158
159 salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup')
160 salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client')
161 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100162 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh -f -s'")
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100163
164 def databases = salt.cmdRun(pepperEnv, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
165 if(databases && databases != ""){
166 def databasesList = salt.getReturnValues(databases).trim().tokenize("\n")
167 for( i = 0; i < databasesList.size(); i++){
168 if(databasesList[i].toLowerCase().contains('upgrade')){
169 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"])
170 common.warningMsg("removing database ${databasesList[i]}")
171 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"])
172 }
173 }
174 salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client')
175 }else{
176 common.errorMsg("No _upgrade databases were returned")
177 }
178
179 try {
180 salt.enforceState(pepperEnv, "${test_upgrade_node}*", 'keystone.server')
181 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'service.restart', ['apache2'])
182 } catch (Exception e) {
183 common.warningMsg('Restarting Apache2')
184 salt.runSaltProcessStep(pepperEnv, "${test_upgrade_node}*", 'service.restart', ['apache2'])
185 }
186 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'keystone.client')
187 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'glance')
188 salt.enforceState(pepperEnv, "${test_upgrade_node}*", 'keystone.server')
189
190 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'nova')
191 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'nova') // run nova state again as sometimes nova does not enforce itself for some reason
192 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'cinder')
193 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'neutron')
194 retryStateRun(pepperEnv, "${test_upgrade_node}*", 'heat')
195
196 salt.cmdRun(pepperEnv, "${test_upgrade_node}*", '. /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')
197
198 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
199 stage('Ask for manual confirmation') {
200 input message: "Do you want to continue with upgrade?"
201 }
202 }
203}
204
205
206def vcpRealUpgrade(pepperEnv) {
207 def common = new com.mirantis.mk.Common()
208 def salt = new com.mirantis.mk.Salt()
209 def openstack = new com.mirantis.mk.Openstack()
210 def virsh = new com.mirantis.mk.Virsh()
211
212 def upgrade_target = []
213 upgrade_target.add('I@horizon:server')
214 upgrade_target.add('I@keystone:server and not upg*')
215
216 def proxy_general_target = "I@horizon:server"
217 def control_general_target = "I@keystone:server and not upg*"
218 def upgrade_general_target = "( I@keystone:server and not upg* ) or I@horizon:server"
219
220 def snapshotName = "upgradeSnapshot1"
221
222 def domain = salt.getDomainName(pepperEnv)
223 def errorOccured = false
224
225 for (tgt in upgrade_target) {
226 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
227 def node = salt.getFirstMinion(pepperEnv, "${tgt}")
228 def general_target = ""
229
230 if (tgt.toString().contains('horizon:server')) {
231 general_target = 'prx'
232 } else if (tgt.toString().contains('keystone:server')) {
233 general_target = 'ctl'
234 }
235
236 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
237 stopServices(pepperEnv, node, tgt, general_target)
238 }
239
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100240 for (t in target_hosts) {
241 def target = salt.stripDomainName(t)
Jiri Broulikcaf721e2018-04-25 17:16:50 +0200242 def nodeProvider = salt.getNodeProvider(pepperEnv, t)
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100243 if ((OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == true) && (SKIP_VM_RELAUNCH.toBoolean() == false)) {
244 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"])
245 sleep(2)
246 try {
247 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
248 } catch (Exception e) {
249 common.warningMsg('File already exists')
250 }
251 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"])
252 try {
253 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
254 } catch (Exception e) {
255 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
256 }
257 } else if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
258 virsh.liveSnapshotPresent(pepperEnv, nodeProvider, target, snapshotName)
259 }
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100260 }
261 }
262
263 if ((OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == true) && (SKIP_VM_RELAUNCH.toBoolean() == false)) {
Jiri Broulik60dcab32018-03-08 17:42:06 +0100264 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh -f -s'")
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100265
266 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
267
268 for (tgt in upgrade_target) {
269 salt.minionsPresent(pepperEnv, 'I@salt:master', tgt)
270 }
271 }
272
273 // salt '*' saltutil.refresh_pillar
274 salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'saltutil.refresh_pillar', [])
275 // salt '*' saltutil.sync_all
276 salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'saltutil.sync_all', [])
277
Jiri Broulik827d0112018-04-25 16:00:07 +0200278 stateRun(pepperEnv, upgrade_general_target, ['linux.network.proxy'])
279 try {
280 salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'state.sls', ["salt.minion.base"], null, true, 60)
281 } catch (Exception e) {
282 common.warningMsg(e)
283 }
284
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100285 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
286
287 try {
288 salt.enforceState(pepperEnv, upgrade_general_target, ['linux.system.repo'])
289 } catch (Exception e) {
290 common.warningMsg(e)
291 }
292
293 salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'pkg.install', ['salt-minion'], null, true, 5)
294 salt.minionsReachable(pepperEnv, 'I@salt:master', upgrade_general_target)
295
296 // Apply package upgrades
297 args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades --allow-unauthenticated -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
298 common.warningMsg("Running apt dist-upgrade on ${proxy_general_target} and ${control_general_target}, this might take a while...")
299 out = salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'cmd.run', [args])
300 // stop services again
301 def proxy_node = salt.getFirstMinion(pepperEnv, proxy_general_target)
302 def control_node = salt.getFirstMinion(pepperEnv, control_general_target)
303 stopServices(pepperEnv, proxy_node, proxy_general_target, 'prx')
304 stopServices(pepperEnv, control_node, control_general_target, 'ctl')
305 salt.printSaltCommandResult(out)
306 if (out.toString().contains("dpkg returned an error code")) {
307 input message: "Apt dist-upgrade failed, please fix it manually and then click on proceed. If unable to fix it, click on abort and run the rollback stage."
308 }
309 // run base states
310 try {
311 salt.enforceState(pepperEnv, upgrade_general_target, ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
312 } catch (Exception e) {
313 common.warningMsg(e)
314 }
315 salt.enforceState(pepperEnv, control_general_target, ['keepalived', 'haproxy'])
316 } else {
317 // initial VM setup
318 try {
319 salt.enforceState(pepperEnv, upgrade_general_target, ['linux', 'openssh'])
320 } catch (Exception e) {
321 common.warningMsg(e)
322 }
323 try {
Jiri Broulik827d0112018-04-25 16:00:07 +0200324 salt.runSaltProcessStep(pepperEnv, upgrade_general_target, 'state.sls', ["salt.minion"], null, true, 60)
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100325 } catch (Exception e) {
326 common.warningMsg(e)
327 }
328 try {
329 salt.enforceState(pepperEnv, upgrade_general_target, ['ntp', 'rsyslog'])
330 } catch (Exception e) {
331 common.warningMsg(e)
332 }
333 salt.enforceState(pepperEnv, upgrade_general_target, ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
334 salt.enforceState(pepperEnv, control_general_target, ['keepalived', 'haproxy'])
335 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['rsyslog'])
336 }
337
338 try {
339 try {
340 salt.enforceState(pepperEnv, control_general_target, ['memcached', 'keystone.server'])
341 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['apache2'])
342 } catch (Exception e) {
343 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
344 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['apache2'])
345 salt.enforceState(pepperEnv, control_general_target, 'keystone.server')
346 }
347 // salt 'ctl01*' state.sls keystone.client
348 retryStateRun(pepperEnv, "I@keystone:client and ${control_general_target}", 'keystone.client')
349 retryStateRun(pepperEnv, control_general_target, 'glance')
350 salt.enforceState(pepperEnv, control_general_target, 'glusterfs.client')
351 salt.enforceState(pepperEnv, control_general_target, 'keystone.server')
352 retryStateRun(pepperEnv, control_general_target, 'nova')
353 retryStateRun(pepperEnv, control_general_target, 'cinder')
354 retryStateRun(pepperEnv, control_general_target, 'neutron')
355 retryStateRun(pepperEnv, control_general_target, 'heat')
356 } catch (Exception e) {
357 errorOccured = true
358 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
359 input message: "Some states that require syncdb failed. Please check the reason.Click proceed only if you want to restore database into it's pre-upgrade state. If you want restore production database and also the VMs into its pre-upgrade state please click on abort and run the rollback stage."
360 } else {
361 input message: "Some states that require syncdb failed. Please check the reason and click proceed only if you want to restore database into it's pre-upgrade state. Otherwise, click abort."
362 }
363 openstack.restoreGaleraDb(pepperEnv)
364 common.errorMsg("Stage Real control upgrade failed")
365 }
366 if(!errorOccured){
367
368 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == true) {
369
370 try {
371 if (salt.testTarget(pepperEnv, "I@ceph:client and ${control_general_target}*")) {
372 salt.enforceState(pepperEnv, "I@ceph:client and ${control_general_target}*", 'ceph.client')
373 }
374 } catch (Exception er) {
375 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
376 }
377 try {
378 if (salt.testTarget(pepperEnv, "I@ceph:common and ${control_general_target}*")) {
379 salt.enforceState(pepperEnv, "I@ceph:common and ${control_general_target}*", ['ceph.common', 'ceph.setup.keyring'])
380 }
381 } catch (Exception er) {
382 common.warningMsg("Ceph common state on controllers failed. Please fix it manually")
383 }
384 try {
385 if (salt.testTarget(pepperEnv, "I@ceph:common and ${control_general_target}*")) {
386 salt.runSaltProcessStep(master, "I@ceph:common and ${control_general_target}*", 'service.restart', ['glance-api', 'glance-glare', 'glance-registry'])
387 }
388 } catch (Exception er) {
389 common.warningMsg("Restarting Glance services on controllers failed. Please fix it manually")
390 }
391 }
392
393 // salt 'cmp*' cmd.run 'service nova-compute restart'
394 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'])
395 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['nova-conductor'])
396 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['nova-scheduler'])
397
398 retryStateRun(pepperEnv, proxy_general_target, 'keepalived')
399 retryStateRun(pepperEnv, proxy_general_target, 'horizon')
400 retryStateRun(pepperEnv, proxy_general_target, 'nginx')
401 retryStateRun(pepperEnv, proxy_general_target, 'memcached')
402
403 try {
404 salt.enforceHighstate(pepperEnv, control_general_target)
405 } catch (Exception er) {
406 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
407 }
408
409 try {
410 salt.enforceHighstate(pepperEnv, proxy_general_target)
411 } catch (Exception er) {
412 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
413 }
414
415 try {
416 salt.cmdRun(pepperEnv, "${control_general_target}01*", '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
417 } catch (Exception er) {
418 common.errorMsg(er)
419 }
420
421 /*
422 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
423 input message: "Please verify if the control upgrade was successful! If so, by clicking proceed the original VMs disk images will be backed up and snapshot will be merged to the upgraded VMs which will finalize the upgrade procedure"
424 node_count = 1
425 for (t in proxy_target_hosts) {
426 def target = salt.stripDomainName(t)
427 def nodeProvider = salt.getNodeProvider(pepperEnv, "${general_target}0${node_count}")
428 try {
429 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
430 } catch (Exception e) {
431 common.warningMsg('File already exists')
432 }
433 virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, snapshotName)
434 node_count++
435 }
436 node_count = 1
437 for (t in control_target_hosts) {
438 def target = salt.stripDomainName(t)
439 def nodeProvider = salt.getNodeProvider(pepperEnv, "${general_target}0${node_count}")
440 try {
441 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
442 } catch (Exception e) {
443 common.warningMsg('File already exists')
444 }
445 virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, snapshotName)
446 node_count++
447 }
448 input message: "Please scroll up and look for red highlighted messages containing 'virsh blockcommit' string.
449 If there are any fix it manually. Otherwise click on proceed."
450 }
451 */
452 }
453}
454
455
456def vcpRollback(pepperEnv) {
457 def common = new com.mirantis.mk.Common()
458 def salt = new com.mirantis.mk.Salt()
459 def openstack = new com.mirantis.mk.Openstack()
460 def virsh = new com.mirantis.mk.Virsh()
461 def snapshotName = "upgradeSnapshot1"
462 try {
463 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true, 2)
464 } catch (Exception e) {
465 common.warningMsg("No response from some minions. We should continue to run")
466 }
467
468 def domain = salt.getDomainName(pepperEnv)
469
470 def rollback_target = []
471 rollback_target.add('I@horizon:server')
472 rollback_target.add('I@keystone:server and not upg*')
473
474 def control_general_target = "I@keystone:server and not upg*"
475 def upgrade_general_target = "( I@keystone:server and not upg* ) or I@horizon:server"
476
477 openstack.restoreGaleraDb(pepperEnv)
478
479 for (tgt in rollback_target) {
480 def target_hosts = salt.getMinionsSorted(pepperEnv, "${tgt}")
481 def node = salt.getFirstMinion(pepperEnv, "${tgt}")
482 def general_target = salt.getMinionsGeneralName(pepperEnv, "${tgt}")
483
484 if (tgt.toString().contains('horizon:server')) {
485 general_target = 'prx'
486 } else if (tgt.toString().contains('keystone:server')) {
487 general_target = 'ctl'
488 }
489
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100490 for (t in target_hosts) {
491 def target = salt.stripDomainName(t)
Jiri Broulikcaf721e2018-04-25 17:16:50 +0200492 def nodeProvider = salt.getNodeProvider(pepperEnv, t)
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100493 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"])
494 sleep(2)
495 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == true) {
496 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"])
497 try {
498 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
499 } catch (Exception e) {
500 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
501 }
502 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"])
503 } else {
504 salt.cmdRun(pepperEnv, "${nodeProvider}", "virsh define /var/lib/libvirt/images/${target}.${domain}.xml")
505 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"])
506 virsh.liveSnapshotAbsent(pepperEnv, nodeProvider, target, snapshotName)
507 }
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100508 }
509 }
510
511 // salt 'cmp*' cmd.run 'service nova-compute restart'
512 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'])
513
514 if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == true) {
515 for (tgt in rollback_target) {
516 salt.minionsPresent(pepperEnv, 'I@salt:master', tgt)
517 }
518 }
519
520 salt.minionsReachable(pepperEnv, 'I@salt:master', upgrade_general_target)
521
522 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['nova-conductor'])
523 salt.runSaltProcessStep(pepperEnv, control_general_target, 'service.restart', ['nova-scheduler'])
524
525 def control_node = salt.getFirstMinion(pepperEnv, control_general_target)
526
527 salt.cmdRun(pepperEnv, "${control_node}*", '. /root/keystonerc; nova service-list; glance image-list; nova flavor-list; nova hypervisor-list; nova list; neutron net-list; cinder list; heat service-list')
528}
529
530
chnyda625f4b42017-10-11 14:10:31 +0200531def pepperEnv = "pepperEnv"
Jakub Josefa63f9862018-01-11 17:58:38 +0100532timeout(time: 12, unit: 'HOURS') {
533 node() {
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200534
Jakub Josefa63f9862018-01-11 17:58:38 +0100535 stage('Setup virtualenv for Pepper') {
536 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
537 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200538
Jakub Josefa63f9862018-01-11 17:58:38 +0100539 if (STAGE_TEST_UPGRADE.toBoolean() == true) {
540 stage('Test upgrade') {
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100541 vcpTestUpgrade(pepperEnv)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400542 }
543 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400544
Jakub Josefa63f9862018-01-11 17:58:38 +0100545 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
546 stage('Real upgrade') {
547 // # actual upgrade
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100548 vcpRealUpgrade(pepperEnv)
Jakub Josefa63f9862018-01-11 17:58:38 +0100549 }
550
551 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
552 stage('Ask for manual confirmation') {
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100553 input message: "Please verify if the control upgrade was successful. If it did not succeed, in the worst scenario, you can click on proceed to continue with control-upgrade-rollback. Do you want to continue with the rollback?"
Jakub Josefa63f9862018-01-11 17:58:38 +0100554 }
555 }
556 }
557
558 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
559 stage('Rollback upgrade') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100560 stage('Ask for manual confirmation') {
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100561 input message: "Before rollback please check the documentation for reclass model changes. Do you really want to continue with the rollback?"
Jakub Josefa63f9862018-01-11 17:58:38 +0100562 }
Jiri Brouliked3a9e62018-02-13 16:08:40 +0100563 vcpRollback(pepperEnv)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400564 }
565 }
566 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100567}