blob: 63a8f1b588fc1e7c86bba518df21b288a2dd737f [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 {
chnyda625f4b42017-10-11 14:10:31 +020087 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040088 } catch (Exception e) {
89 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
90 }
chnyda625f4b42017-10-11 14:10:31 +020091 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +020092
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040093 // salt "upg*" state.sls rabbitmq
chnyda625f4b42017-10-11 14:10:31 +020094 salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040095 try {
chnyda625f4b42017-10-11 14:10:31 +020096 salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040097 } catch (Exception e) {
98 common.warningMsg('salt-minion was restarted. We should continue to run')
99 }
100 try {
chnyda625f4b42017-10-11 14:10:31 +0200101 salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400102 } catch (Exception e) {
103 common.warningMsg('salt-minion was restarted. We should continue to run')
104 }
105 // salt '*' state.apply salt.minion.grains
chnyda625f4b42017-10-11 14:10:31 +0200106 //salt.enforceState(pepperEnv, '*', 'salt.minion.grains')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400107 // salt -C 'I@backupninja:server' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200108 salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400109 // salt -C 'I@backupninja:client' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200110 salt.enforceState(pepperEnv, 'I@backupninja:client', 'backupninja')
111 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400112 try {
chnyda625f4b42017-10-11 14:10:31 +0200113 salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400114 } catch (Exception e) {
115 common.warningMsg('The ARP entry does not exist. We should continue to run.')
116 }
chnyda625f4b42017-10-11 14:10:31 +0200117 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
118 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
119 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200120
chnyda625f4b42017-10-11 14:10:31 +0200121 salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup')
122 salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client')
123 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
124 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200125
chnyda625f4b42017-10-11 14:10:31 +0200126 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 +0400127 if(databases && databases != ""){
128 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
129 for( i = 0; i < databasesList.size(); i++){
130 if(databasesList[i].toLowerCase().contains('upgrade')){
chnyda625f4b42017-10-11 14:10:31 +0200131 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400132 common.warningMsg("removing database ${databasesList[i]}")
chnyda625f4b42017-10-11 14:10:31 +0200133 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200134 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200135 }
chnyda625f4b42017-10-11 14:10:31 +0200136 salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400137 }else{
138 common.errorMsg("No _upgrade databases were returned")
139 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200140
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400141 try {
chnyda625f4b42017-10-11 14:10:31 +0200142 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
143 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400144 } catch (Exception e) {
145 common.warningMsg('Restarting Apache2')
chnyda625f4b42017-10-11 14:10:31 +0200146 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400147 }
148 try {
chnyda625f4b42017-10-11 14:10:31 +0200149 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400150 } catch (Exception e) {
151 common.warningMsg('running keystone.client state again')
chnyda625f4b42017-10-11 14:10:31 +0200152 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400153 }
154 try {
chnyda625f4b42017-10-11 14:10:31 +0200155 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400156 } catch (Exception e) {
157 common.warningMsg('running glance state again')
chnyda625f4b42017-10-11 14:10:31 +0200158 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400159 }
chnyda625f4b42017-10-11 14:10:31 +0200160 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400161 try {
chnyda625f4b42017-10-11 14:10:31 +0200162 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400163 } catch (Exception e) {
164 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200165 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400166 }
167 // run nova state again as sometimes nova does not enforce itself for some reason
168 try {
chnyda625f4b42017-10-11 14:10:31 +0200169 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400170 } catch (Exception e) {
171 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200172 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400173 }
174 try {
chnyda625f4b42017-10-11 14:10:31 +0200175 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400176 } catch (Exception e) {
177 common.warningMsg('running cinder state again')
chnyda625f4b42017-10-11 14:10:31 +0200178 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400179 }
180 try {
chnyda625f4b42017-10-11 14:10:31 +0200181 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400182 } catch (Exception e) {
183 common.warningMsg('running neutron state again')
chnyda625f4b42017-10-11 14:10:31 +0200184 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400185 }
186 try {
chnyda625f4b42017-10-11 14:10:31 +0200187 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400188 } catch (Exception e) {
189 common.warningMsg('running heat state again')
chnyda625f4b42017-10-11 14:10:31 +0200190 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400191 }
chnyda625f4b42017-10-11 14:10:31 +0200192 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 +0400193
194 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
195 stage('Ask for manual confirmation') {
196 input message: "Do you want to continue with upgrade?"
Jiri Broulik3792c962017-05-17 18:26:36 +0200197 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400198 }
199 }
200 }
201
202 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
203 stage('Real upgrade') {
204 // # actual upgrade
205
Jiri Broulik0798e512017-11-13 17:00:58 +0100206 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
207 domain = domain['return'][0].values()[0]
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400208
chnyda625f4b42017-10-11 14:10:31 +0200209 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400210 kvm01 = _pillar['return'][0].values()[0].values()[0]
211 print(_pillar)
212 print(kvm01)
213
214 def errorOccured = false
215
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100216 def proxy_general_target = ""
Marek Celoudead57b92017-11-13 16:41:12 +0100217 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server').sort()
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100218 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400219
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100220 for (t in proxy_target_hosts) {
221 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100222 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100223 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
224 break
225 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100226 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100227 def nodeProvider = _pillar['return'][0].values()[0]
228 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
229 sleep(2)
230 try {
231 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
232 } catch (Exception e) {
233 common.warningMsg('File already exists')
234 }
235 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
236 try {
237 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
238 } catch (Exception e) {
239 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
240 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100241 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400242 }
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100243 def control_general_target = ""
Marek Celoud8c34fc52017-11-13 16:46:09 +0100244 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server and not upg*')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100245 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400246
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100247 for (t in control_target_hosts) {
248 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100249 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100250 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
251 break
252 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100253 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100254 def nodeProvider = _pillar['return'][0].values()[0]
255 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
256 sleep(2)
257 try {
258 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
259 } catch (Exception e) {
260 common.warningMsg('File already exists')
261 }
262 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
263 try {
264 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
265 } catch (Exception e) {
266 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
267 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100268 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100269 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400270
Jiri Broulik7cadf582017-11-13 17:35:31 +0100271 if (SKIP_VM_RELAUNCH.toBoolean() == false) {
272 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400273
Jiri Broulik7cadf582017-11-13 17:35:31 +0100274 // salt 'kvm*' state.sls salt.control
275 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400276
Jiri Broulik7cadf582017-11-13 17:35:31 +0100277 for (t in control_target_hosts) {
278 def target = t.split("\\.")[0]
279 // wait until ctl and prx nodes are registered in salt-key
280 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
281 }
282 for (t in proxy_target_hosts) {
283 def target = t.split("\\.")[0]
284 // wait until ctl and prx nodes are registered in salt-key
285 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
286 }
287
288 // salt '*' saltutil.refresh_pillar
289 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
290 // salt '*' saltutil.sync_all
291 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100292 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400293 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100294 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400295 } catch (Exception e) {
296 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
297 }
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100298 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400299
300 // salt 'ctl*' state.sls keepalived
301 // salt 'ctl*' state.sls haproxy
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100302 salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400303 // salt 'ctl*' service.restart rsyslog
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100304 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400305 // salt "ctl*" state.sls memcached
306 // salt "ctl*" state.sls keystone.server
307 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200308 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100309 salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server'])
310 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400311 } catch (Exception e) {
312 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100313 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
314 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400315 }
316 // salt 'ctl01*' state.sls keystone.client
317 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100318 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200319 } catch (Exception e) {
320 common.warningMsg('running keystone.client state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100321 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200322 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200323 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100324 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200325 } catch (Exception e) {
326 common.warningMsg('running glance state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100327 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400328 } // salt 'ctl*' state.sls glusterfs.client
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100329 salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400330 // salt 'ctl*' state.sls keystone.server
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100331 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400332 // salt 'ctl*' state.sls nova
Jiri Broulik5f83c292017-05-18 12:09:07 +0200333 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100334 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200335 } catch (Exception e) {
336 common.warningMsg('running nova state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100337 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200338 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400339 // salt 'ctl*' state.sls cinder
Jiri Broulik80d96752017-05-22 19:42:01 +0200340 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100341 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200342 } catch (Exception e) {
343 common.warningMsg('running cinder state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100344 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400345 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200346 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100347 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200348 } catch (Exception e) {
349 common.warningMsg('running neutron state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100350 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200351 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400352 // salt 'ctl*' state.sls heat
Jiri Broulikbda0a212017-05-18 12:54:51 +0200353 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100354 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200355 } catch (Exception e) {
356 common.warningMsg('running heat state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100357 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulik3792c962017-05-17 18:26:36 +0200358 }
359
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400360 } catch (Exception e) {
361 errorOccured = true
Jiri Broulik0798e512017-11-13 17:00:58 +0100362 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 +0400363 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik3792c962017-05-17 18:26:36 +0200364
Jiri Broulik00d01092017-06-01 19:38:15 +0200365 // database restore section
366 try {
chnyda625f4b42017-10-11 14:10:31 +0200367 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400368 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200369 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200370 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200371 try {
chnyda625f4b42017-10-11 14:10:31 +0200372 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400373 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200374 common.warningMsg('Mysql service already stopped')
375 }
376 try {
chnyda625f4b42017-10-11 14:10:31 +0200377 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400378 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200379 common.warningMsg('Files are not present')
380 }
381 try {
chnyda625f4b42017-10-11 14:10:31 +0200382 salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400383 } catch (Exception er) {
384 common.warningMsg('Directory already exists')
385 }
386 try {
chnyda625f4b42017-10-11 14:10:31 +0200387 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400388 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200389 common.warningMsg('Directory already empty')
390 }
391 try {
chnyda625f4b42017-10-11 14:10:31 +0200392 salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400393 } catch (Exception er) {
394 common.warningMsg('Files were already moved')
395 }
396 try {
chnyda625f4b42017-10-11 14:10:31 +0200397 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400398 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200399 common.warningMsg('File is not present')
400 }
chnyda625f4b42017-10-11 14:10:31 +0200401 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
402 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Jiri Broulik00d01092017-06-01 19:38:15 +0200403 backup_dir = _pillar['return'][0].values()[0]
404 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
405 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200406 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
407 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
408 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200409
410 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200411 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200412
chnyda625f4b42017-10-11 14:10:31 +0200413 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik00d01092017-06-01 19:38:15 +0200414 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200415
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400416 common.errorMsg("Stage Real control upgrade failed")
417 }
418 if(!errorOccured){
419
420 ceph = null
421
422 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100423 ceph = salt.cmdRun(pepperEnv, "${control_general_target}*", "salt-call grains.item roles | grep ceph.client")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400424
425 } catch (Exception er) {
426 common.infoMsg("Ceph is not used")
427 }
428
429 if(ceph != null) {
430 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100431 salt.enforceState(pepperEnv, "${control_general_target}*", 'ceph.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400432 } catch (Exception er) {
433 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
434 }
435 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200436
437 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100438 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
439 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
440 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Jiri Broulikf20c7672017-06-19 21:20:52 +0200441
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400442
443 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
444 // salt 'ctl*' state.sls keepalived
445 // salt 'prx*' state.sls keepalived
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100446 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'keepalived')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400447 // salt 'prx*' state.sls horizon
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100448 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'horizon')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400449 // salt 'prx*' state.sls nginx
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100450 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'nginx')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400451 // salt "prx*" state.sls memcached
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100452 salt.enforceState(pepperEnv, "${proxy_general_target}*", 'memcached')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400453
454 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100455 salt.enforceHighstate(pepperEnv, "${control_general_target}*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400456 } catch (Exception er) {
457 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
458 }
459
460 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100461 salt.enforceHighstate(pepperEnv, "${proxy_general_target}*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400462 } catch (Exception er) {
463 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
464 }
465
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100466 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 +0200467 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200468 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400469
470 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
471 stage('Ask for manual confirmation') {
472 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?"
473 }
474 }
475 }
476
477 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
478 stage('Rollback upgrade') {
479
480 stage('Ask for manual confirmation') {
481 input message: "Do you really want to continue with the rollback?"
482 }
483
Jiri Broulik0798e512017-11-13 17:00:58 +0100484 def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain')
485 domain = domain['return'][0].values()[0]
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400486
chnyda625f4b42017-10-11 14:10:31 +0200487 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400488 kvm01 = _pillar['return'][0].values()[0].values()[0]
489 print(_pillar)
490 print(kvm01)
491
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100492 def proxy_general_target = ""
493 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100494 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400495
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100496 for (t in proxy_target_hosts) {
497 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100498 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100499 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
500 break
501 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100502 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100503 def nodeProvider = _pillar['return'][0].values()[0]
504 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
505 sleep(2)
506 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
507 try {
508 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
509 } catch (Exception e) {
510 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
511 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100512 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100513 }
514 def control_general_target = ""
Marek Celoudead57b92017-11-13 16:41:12 +0100515 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server').sort()
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100516 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400517
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100518 for (t in control_target_hosts) {
519 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100520 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik7cadf582017-11-13 17:35:31 +0100521 if (SKIP_VM_RELAUNCH.toBoolean() == true) {
522 break
523 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100524 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100525 def nodeProvider = _pillar['return'][0].values()[0]
526 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
527 sleep(2)
528 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
529 try {
530 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
531 } catch (Exception e) {
532 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
533 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100534 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400535 }
536
537 // database restore section
538 try {
chnyda625f4b42017-10-11 14:10:31 +0200539 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400540 } catch (Exception e) {
541 common.warningMsg('Mysql service already stopped')
542 }
543 try {
chnyda625f4b42017-10-11 14:10:31 +0200544 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400545 } catch (Exception e) {
546 common.warningMsg('Mysql service already stopped')
547 }
548 try {
chnyda625f4b42017-10-11 14:10:31 +0200549 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400550 } catch (Exception e) {
551 common.warningMsg('Files are not present')
552 }
553 try {
chnyda625f4b42017-10-11 14:10:31 +0200554 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400555 } catch (Exception e) {
556 common.warningMsg('Directory already empty')
557 }
558 try {
chnyda625f4b42017-10-11 14:10:31 +0200559 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400560 } catch (Exception e) {
561 common.warningMsg('File is not present')
562 }
chnyda625f4b42017-10-11 14:10:31 +0200563 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
564 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400565 backup_dir = _pillar['return'][0].values()[0]
566 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
567 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200568 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
569 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
570 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400571
572 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200573 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400574
chnyda625f4b42017-10-11 14:10:31 +0200575 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400576 //
577
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100578 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100579 for (t in control_target_hosts) {
580 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100581 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100582 def nodeProvider = _pillar['return'][0].values()[0]
583 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100584 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100585 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100586 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100587 for (t in proxy_target_hosts) {
588 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100589 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100590 def nodeProvider = _pillar['return'][0].values()[0]
591 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100592 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100593 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400594
595 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100596 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400597
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100598 for (t in control_target_hosts) {
599 def target = t.split("\\.")[0]
600 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
601 }
602 for (t in proxy_target_hosts) {
603 def target = t.split("\\.")[0]
604 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
605 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400606
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100607 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
608 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400609
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100610 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 +0400611 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200612 }
613}