blob: b121d0bb02909d57346e9beef167d0e318508d1d [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 Broulik7cadf582017-11-13 17:35:31 +010010 * SKIP_VM_RELAUNCH Set to true if vms should not be recreated
Jiri Broulikbb447ac2017-05-04 15:36:22 +020011 *
12**/
13
14def common = new com.mirantis.mk.Common()
15def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020016def python = new com.mirantis.mk.Python()
Jiri Broulikbb447ac2017-05-04 15:36:22 +020017
chnyda625f4b42017-10-11 14:10:31 +020018def pepperEnv = "pepperEnv"
Jiri Broulikbb447ac2017-05-04 15:36:22 +020019
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040020node() {
Jiri Broulikbb447ac2017-05-04 15:36:22 +020021
chnyda625f4b42017-10-11 14:10:31 +020022 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070023 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040024 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020025
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040026 if (STAGE_TEST_UPGRADE.toBoolean() == true) {
27 stage('Test upgrade') {
Jiri Broulik3792c962017-05-17 18:26:36 +020028
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040029 try {
chnyda625f4b42017-10-11 14:10:31 +020030 salt.enforceState(pepperEnv, 'I@salt:master', 'reclass')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040031 } catch (Exception e) {
32 common.warningMsg("Some parts of Reclass state failed. The most probable reasons were uncommited changes. We should continue to run")
33 }
Jiri Broulik80d96752017-05-22 19:42:01 +020034
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040035 try {
chnyda625f4b42017-10-11 14:10:31 +020036 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040037 } catch (Exception e) {
38 common.warningMsg("No response from some minions. We should continue to run")
39 }
Jiri Broulik3792c962017-05-17 18:26:36 +020040
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040041 try {
chnyda625f4b42017-10-11 14:10:31 +020042 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040043 } catch (Exception e) {
44 common.warningMsg("No response from some minions. We should continue to run")
45 }
Jiri Broulik3792c962017-05-17 18:26:36 +020046
Jiri Broulik0798e512017-11-13 17:00:58 +010047 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
48 domain = domain['return'][0].values()[0]
Jiri Broulik3792c962017-05-17 18:26:36 +020049
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040050 // read backupninja variable
chnyda625f4b42017-10-11 14:10:31 +020051 _pillar = salt.getPillar(pepperEnv, 'I@backupninja:client', '_param:backupninja_backup_host')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040052 def backupninja_backup_host = _pillar['return'][0].values()[0]
Jiri Broulik3792c962017-05-17 18:26:36 +020053
Jiri Broulik7cadf582017-11-13 17:35:31 +010054 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040055
Jiri Broulik7cadf582017-11-13 17:35:31 +010056 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
57 def kvm01 = _pillar['return'][0].values()[0].values()[0]
58 print(_pillar)
59 print(kvm01)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020060
Jiri Broulik7cadf582017-11-13 17:35:31 +010061 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider')
62 def upgNodeProvider = _pillar['return'][0].values()[0]
63 print(_pillar)
64 print(upgNodeProvider)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020065
Jiri Broulik7cadf582017-11-13 17:35:31 +010066 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true)
67 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020068
Jiri Broulik7cadf582017-11-13 17:35:31 +010069 try {
70 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d upg01.${domain} -y")
71 } catch (Exception e) {
72 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")
73 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020074
Jiri Broulik7cadf582017-11-13 17:35:31 +010075 // salt 'kvm02*' state.sls salt.control
76 salt.enforceState(pepperEnv, "${upgNodeProvider}", 'salt.control')
77 // wait until upg node is registered in salt-key
78 salt.minionPresent(pepperEnv, 'I@salt:master', 'upg01')
79 // salt '*' saltutil.refresh_pillar
80 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.refresh_pillar', [], null, true)
81 // salt '*' saltutil.sync_all
82 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.sync_all', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040083 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020084
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040085 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
86 try {
Jiri Broulikc9b82f42017-11-13 18:50:36 +010087 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040088 } catch (Exception e) {
Jiri Broulikc9b82f42017-11-13 18:50:36 +010089 common.warningMsg(e)
90 }
91 try {
92 salt.runSaltProcessStep(master, 'upg*', 'state.sls', ["salt.minion"], null, true, 60)
93 } catch (Exception e) {
94 common.warningMsg(e)
95 }
96 try {
97 salt.enforceState(pepperEnv, 'upg*', ['ntp', 'rsyslog'])
98 } catch (Exception e) {
99 common.warningMsg(e)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400100 }
chnyda625f4b42017-10-11 14:10:31 +0200101 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200102
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400103 // salt "upg*" state.sls rabbitmq
chnyda625f4b42017-10-11 14:10:31 +0200104 salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400105 try {
chnyda625f4b42017-10-11 14:10:31 +0200106 salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400107 } catch (Exception e) {
108 common.warningMsg('salt-minion was restarted. We should continue to run')
109 }
110 try {
chnyda625f4b42017-10-11 14:10:31 +0200111 salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400112 } catch (Exception e) {
113 common.warningMsg('salt-minion was restarted. We should continue to run')
114 }
115 // salt '*' state.apply salt.minion.grains
chnyda625f4b42017-10-11 14:10:31 +0200116 //salt.enforceState(pepperEnv, '*', 'salt.minion.grains')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400117 // salt -C 'I@backupninja:server' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200118 salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400119 // salt -C 'I@backupninja:client' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200120 salt.enforceState(pepperEnv, 'I@backupninja:client', 'backupninja')
121 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400122 try {
chnyda625f4b42017-10-11 14:10:31 +0200123 salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400124 } catch (Exception e) {
125 common.warningMsg('The ARP entry does not exist. We should continue to run.')
126 }
chnyda625f4b42017-10-11 14:10:31 +0200127 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
128 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
129 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200130
chnyda625f4b42017-10-11 14:10:31 +0200131 salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup')
132 salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client')
133 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
134 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200135
chnyda625f4b42017-10-11 14:10:31 +0200136 def databases = salt.cmdRun(pepperEnv, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400137 if(databases && databases != ""){
138 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
139 for( i = 0; i < databasesList.size(); i++){
140 if(databasesList[i].toLowerCase().contains('upgrade')){
chnyda625f4b42017-10-11 14:10:31 +0200141 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400142 common.warningMsg("removing database ${databasesList[i]}")
chnyda625f4b42017-10-11 14:10:31 +0200143 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200144 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200145 }
chnyda625f4b42017-10-11 14:10:31 +0200146 salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400147 }else{
148 common.errorMsg("No _upgrade databases were returned")
149 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200150
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400151 try {
chnyda625f4b42017-10-11 14:10:31 +0200152 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
153 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400154 } catch (Exception e) {
155 common.warningMsg('Restarting Apache2')
chnyda625f4b42017-10-11 14:10:31 +0200156 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400157 }
158 try {
chnyda625f4b42017-10-11 14:10:31 +0200159 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400160 } catch (Exception e) {
161 common.warningMsg('running keystone.client state again')
chnyda625f4b42017-10-11 14:10:31 +0200162 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400163 }
164 try {
chnyda625f4b42017-10-11 14:10:31 +0200165 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400166 } catch (Exception e) {
167 common.warningMsg('running glance state again')
chnyda625f4b42017-10-11 14:10:31 +0200168 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400169 }
chnyda625f4b42017-10-11 14:10:31 +0200170 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400171 try {
chnyda625f4b42017-10-11 14:10:31 +0200172 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400173 } catch (Exception e) {
174 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200175 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400176 }
177 // run nova state again as sometimes nova does not enforce itself for some reason
178 try {
chnyda625f4b42017-10-11 14:10:31 +0200179 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400180 } catch (Exception e) {
181 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200182 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400183 }
184 try {
chnyda625f4b42017-10-11 14:10:31 +0200185 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400186 } catch (Exception e) {
187 common.warningMsg('running cinder state again')
chnyda625f4b42017-10-11 14:10:31 +0200188 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400189 }
190 try {
chnyda625f4b42017-10-11 14:10:31 +0200191 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400192 } catch (Exception e) {
193 common.warningMsg('running neutron state again')
chnyda625f4b42017-10-11 14:10:31 +0200194 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400195 }
196 try {
chnyda625f4b42017-10-11 14:10:31 +0200197 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400198 } catch (Exception e) {
199 common.warningMsg('running heat state again')
chnyda625f4b42017-10-11 14:10:31 +0200200 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400201 }
chnyda625f4b42017-10-11 14:10:31 +0200202 salt.cmdRun(pepperEnv, '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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400203
204 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
205 stage('Ask for manual confirmation') {
206 input message: "Do you want to continue with upgrade?"
Jiri Broulik3792c962017-05-17 18:26:36 +0200207 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400208 }
209 }
210 }
211
212 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
213 stage('Real upgrade') {
214 // # actual upgrade
215
Jiri Broulik0798e512017-11-13 17:00:58 +0100216 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
217 domain = domain['return'][0].values()[0]
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400218
chnyda625f4b42017-10-11 14:10:31 +0200219 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400220 kvm01 = _pillar['return'][0].values()[0].values()[0]
221 print(_pillar)
222 print(kvm01)
223
224 def errorOccured = false
225
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100226 def proxy_general_target = ""
Marek Celoudead57b92017-11-13 16:41:12 +0100227 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server').sort()
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100228 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400229
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100230 for (t in proxy_target_hosts) {
231 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100232 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100233 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
234 break
235 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100236 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100237 def nodeProvider = _pillar['return'][0].values()[0]
238 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
239 sleep(2)
240 try {
241 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
242 } catch (Exception e) {
243 common.warningMsg('File already exists')
244 }
245 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
246 try {
247 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
248 } catch (Exception e) {
249 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
250 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100251 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400252 }
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100253 def control_general_target = ""
Marek Celoud8c34fc52017-11-13 16:46:09 +0100254 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server and not upg*')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100255 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400256
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100257 for (t in control_target_hosts) {
258 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100259 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100260 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
261 break
262 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100263 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100264 def nodeProvider = _pillar['return'][0].values()[0]
265 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
266 sleep(2)
267 try {
268 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
269 } catch (Exception e) {
270 common.warningMsg('File already exists')
271 }
272 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
273 try {
274 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
275 } catch (Exception e) {
276 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
277 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100278 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100279 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400280
Jiri Broulik7cadf582017-11-13 17:35:31 +0100281 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
282 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400283
Jiri Broulik7cadf582017-11-13 17:35:31 +0100284 // salt 'kvm*' state.sls salt.control
285 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400286
Jiri Broulik7cadf582017-11-13 17:35:31 +0100287 for (t in control_target_hosts) {
288 def target = t.split("\\.")[0]
289 // wait until ctl and prx nodes are registered in salt-key
290 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
291 }
292 for (t in proxy_target_hosts) {
293 def target = t.split("\\.")[0]
294 // wait until ctl and prx nodes are registered in salt-key
295 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
296 }
297
298 // salt '*' saltutil.refresh_pillar
299 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
300 // salt '*' saltutil.sync_all
301 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100302 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400303 try {
Jiri Broulikc9b82f42017-11-13 18:50:36 +0100304 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400305 } catch (Exception e) {
Jiri Broulikc9b82f42017-11-13 18:50:36 +0100306 common.warningMsg(e)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400307 }
Jiri Broulikc9b82f42017-11-13 18:50:36 +0100308 try {
309 salt.runSaltProcessStep(master, "${proxy_general_target}* or ${control_general_target}*", 'state.sls', ["salt.minion"], null, true, 60)
310 } catch (Exception e) {
311 common.warningMsg(e)
312 }
313 try {
314 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['ntp', 'rsyslog'])
315 } catch (Exception e) {
316 common.warningMsg(e)
317 }
318
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100319 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400320
321 // salt 'ctl*' state.sls keepalived
322 // salt 'ctl*' state.sls haproxy
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100323 salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400324 // salt 'ctl*' service.restart rsyslog
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100325 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400326 // salt "ctl*" state.sls memcached
327 // salt "ctl*" state.sls keystone.server
328 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200329 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100330 salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server'])
331 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400332 } catch (Exception e) {
333 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100334 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
335 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400336 }
337 // salt 'ctl01*' state.sls keystone.client
338 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100339 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200340 } catch (Exception e) {
341 common.warningMsg('running keystone.client state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100342 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200343 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200344 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100345 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200346 } catch (Exception e) {
347 common.warningMsg('running glance state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100348 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400349 } // salt 'ctl*' state.sls glusterfs.client
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100350 salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400351 // salt 'ctl*' state.sls keystone.server
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100352 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400353 // salt 'ctl*' state.sls nova
Jiri Broulik5f83c292017-05-18 12:09:07 +0200354 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100355 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200356 } catch (Exception e) {
357 common.warningMsg('running nova state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100358 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200359 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400360 // salt 'ctl*' state.sls cinder
Jiri Broulik80d96752017-05-22 19:42:01 +0200361 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100362 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200363 } catch (Exception e) {
364 common.warningMsg('running cinder state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100365 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400366 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200367 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100368 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200369 } catch (Exception e) {
370 common.warningMsg('running neutron state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100371 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200372 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400373 // salt 'ctl*' state.sls heat
Jiri Broulikbda0a212017-05-18 12:54:51 +0200374 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100375 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200376 } catch (Exception e) {
377 common.warningMsg('running heat state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100378 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulik3792c962017-05-17 18:26:36 +0200379 }
380
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400381 } catch (Exception e) {
382 errorOccured = true
Jiri Broulik0798e512017-11-13 17:00:58 +0100383 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."
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400384 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik3792c962017-05-17 18:26:36 +0200385
Jiri Broulik00d01092017-06-01 19:38:15 +0200386 // database restore section
387 try {
chnyda625f4b42017-10-11 14:10:31 +0200388 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400389 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200390 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200391 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200392 try {
chnyda625f4b42017-10-11 14:10:31 +0200393 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400394 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200395 common.warningMsg('Mysql service already stopped')
396 }
397 try {
chnyda625f4b42017-10-11 14:10:31 +0200398 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400399 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200400 common.warningMsg('Files are not present')
401 }
402 try {
chnyda625f4b42017-10-11 14:10:31 +0200403 salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400404 } catch (Exception er) {
405 common.warningMsg('Directory already exists')
406 }
407 try {
chnyda625f4b42017-10-11 14:10:31 +0200408 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400409 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200410 common.warningMsg('Directory already empty')
411 }
412 try {
chnyda625f4b42017-10-11 14:10:31 +0200413 salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400414 } catch (Exception er) {
415 common.warningMsg('Files were already moved')
416 }
417 try {
chnyda625f4b42017-10-11 14:10:31 +0200418 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400419 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200420 common.warningMsg('File is not present')
421 }
chnyda625f4b42017-10-11 14:10:31 +0200422 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
423 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Jiri Broulik00d01092017-06-01 19:38:15 +0200424 backup_dir = _pillar['return'][0].values()[0]
425 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
426 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200427 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
428 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
429 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200430
431 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200432 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200433
chnyda625f4b42017-10-11 14:10:31 +0200434 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik00d01092017-06-01 19:38:15 +0200435 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200436
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400437 common.errorMsg("Stage Real control upgrade failed")
438 }
439 if(!errorOccured){
440
441 ceph = null
442
443 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100444 ceph = salt.cmdRun(pepperEnv, "${control_general_target}*", "salt-call grains.item roles | grep ceph.client")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400445
446 } catch (Exception er) {
447 common.infoMsg("Ceph is not used")
448 }
449
450 if(ceph != null) {
451 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100452 salt.enforceState(pepperEnv, "${control_general_target}*", 'ceph.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400453 } catch (Exception er) {
454 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
455 }
456 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200457
458 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100459 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
460 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
461 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Jiri Broulikf20c7672017-06-19 21:20:52 +0200462
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400463
464 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
465 // salt 'ctl*' state.sls keepalived
466 // salt 'prx*' state.sls keepalived
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100467 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'keepalived')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400468 // salt 'prx*' state.sls horizon
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100469 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'horizon')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400470 // salt 'prx*' state.sls nginx
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100471 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'nginx')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400472 // salt "prx*" state.sls memcached
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100473 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'memcached')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400474
475 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100476 salt.enforceHighstate(pepperEnv, "${control_general_target}*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400477 } catch (Exception er) {
478 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
479 }
480
481 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100482 salt.enforceHighstate(pepperEnv, "${proxy_general_target}*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400483 } catch (Exception er) {
484 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
485 }
486
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100487 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')
Jiri Broulik3792c962017-05-17 18:26:36 +0200488 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200489 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400490
491 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
492 stage('Ask for manual confirmation') {
493 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?"
494 }
495 }
496 }
497
498 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
499 stage('Rollback upgrade') {
500
501 stage('Ask for manual confirmation') {
502 input message: "Do you really want to continue with the rollback?"
503 }
504
Jiri Broulik0798e512017-11-13 17:00:58 +0100505 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
506 domain = domain['return'][0].values()[0]
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400507
chnyda625f4b42017-10-11 14:10:31 +0200508 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400509 kvm01 = _pillar['return'][0].values()[0].values()[0]
510 print(_pillar)
511 print(kvm01)
512
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100513 def proxy_general_target = ""
514 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100515 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400516
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100517 for (t in proxy_target_hosts) {
518 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100519 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100520 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
521 break
522 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100523 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100524 def nodeProvider = _pillar['return'][0].values()[0]
525 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
526 sleep(2)
527 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
528 try {
529 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
530 } catch (Exception e) {
531 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
532 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100533 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100534 }
535 def control_general_target = ""
Marek Celoudead57b92017-11-13 16:41:12 +0100536 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server').sort()
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100537 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400538
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100539 for (t in control_target_hosts) {
540 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100541 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100542 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
543 break
544 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100545 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100546 def nodeProvider = _pillar['return'][0].values()[0]
547 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
548 sleep(2)
549 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
550 try {
551 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
552 } catch (Exception e) {
553 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
554 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100555 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400556 }
557
558 // database restore section
559 try {
chnyda625f4b42017-10-11 14:10:31 +0200560 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400561 } catch (Exception e) {
562 common.warningMsg('Mysql service already stopped')
563 }
564 try {
chnyda625f4b42017-10-11 14:10:31 +0200565 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400566 } catch (Exception e) {
567 common.warningMsg('Mysql service already stopped')
568 }
569 try {
chnyda625f4b42017-10-11 14:10:31 +0200570 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400571 } catch (Exception e) {
572 common.warningMsg('Files are not present')
573 }
574 try {
chnyda625f4b42017-10-11 14:10:31 +0200575 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400576 } catch (Exception e) {
577 common.warningMsg('Directory already empty')
578 }
579 try {
chnyda625f4b42017-10-11 14:10:31 +0200580 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400581 } catch (Exception e) {
582 common.warningMsg('File is not present')
583 }
chnyda625f4b42017-10-11 14:10:31 +0200584 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
585 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400586 backup_dir = _pillar['return'][0].values()[0]
587 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
588 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200589 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
590 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
591 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400592
593 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200594 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400595
chnyda625f4b42017-10-11 14:10:31 +0200596 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400597 //
598
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100599 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100600 for (t in control_target_hosts) {
601 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100602 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100603 def nodeProvider = _pillar['return'][0].values()[0]
604 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100605 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100606 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100607 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100608 for (t in proxy_target_hosts) {
609 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100610 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100611 def nodeProvider = _pillar['return'][0].values()[0]
612 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100613 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100614 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400615
616 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100617 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400618
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100619 for (t in control_target_hosts) {
620 def target = t.split("\\.")[0]
621 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
622 }
623 for (t in proxy_target_hosts) {
624 def target = t.split("\\.")[0]
625 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
626 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400627
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100628 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
629 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400630
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100631 salt.cmdRun(pepperEnv, "${control_general_target}01*", '. /root/keystonerc; nova service-list; glance image-list; nova flavor-list; nova hypervisor-list; nova list; neutron net-list; cinder list; heat service-list')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400632 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200633 }
634}