blob: 76960e9f517cdb06d8f2576ceb6018c8d0ebce1e [file] [log] [blame]
Jiri Broulikbb447ac2017-05-04 15:36:22 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
Jiri Broulik3792c962017-05-17 18:26:36 +02007 * STAGE_TEST_UPGRADE Run test upgrade stage (bool)
8 * STAGE_REAL_UPGRADE Run real upgrade stage (bool)
9 * STAGE_ROLLBACK_UPGRADE Run rollback upgrade stage (bool)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020010 *
11**/
12
13def common = new com.mirantis.mk.Common()
14def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020015def python = new com.mirantis.mk.Python()
Jiri Broulikbb447ac2017-05-04 15:36:22 +020016
chnyda625f4b42017-10-11 14:10:31 +020017def pepperEnv = "pepperEnv"
Jiri Broulikbb447ac2017-05-04 15:36:22 +020018
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040019node() {
Jiri Broulikbb447ac2017-05-04 15:36:22 +020020
chnyda625f4b42017-10-11 14:10:31 +020021 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070022 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040023 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020024
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040025 if (STAGE_TEST_UPGRADE.toBoolean() == true) {
26 stage('Test upgrade') {
Jiri Broulik3792c962017-05-17 18:26:36 +020027
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
chnyda625f4b42017-10-11 14:10:31 +020047 def _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040048 def domain = _pillar['return'][0].values()[0].values()[0]
49 print(_pillar)
50 print(domain)
Jiri Broulik3792c962017-05-17 18:26:36 +020051
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040052 // read backupninja variable
chnyda625f4b42017-10-11 14:10:31 +020053 _pillar = salt.getPillar(pepperEnv, 'I@backupninja:client', '_param:backupninja_backup_host')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040054 def backupninja_backup_host = _pillar['return'][0].values()[0]
55 print(_pillar)
56 print(backupninja_backup_host)
Jiri Broulik3792c962017-05-17 18:26:36 +020057
chnyda625f4b42017-10-11 14:10:31 +020058 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040059 def kvm01 = _pillar['return'][0].values()[0].values()[0]
60 print(_pillar)
61 print(kvm01)
62
chnyda625f4b42017-10-11 14:10:31 +020063 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040064 def upgNodeProvider = _pillar['return'][0].values()[0]
65 print(_pillar)
66 print(upgNodeProvider)
Jiri Broulikbb447ac2017-05-04 15:36:22 +020067
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020068
chnyda625f4b42017-10-11 14:10:31 +020069 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true)
70 salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true)
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +020071
72
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040073 try {
chnyda625f4b42017-10-11 14:10:31 +020074 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d upg01.${domain} -y")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040075 } catch (Exception e) {
76 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")
77 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +020078
Jiri Broulikbb447ac2017-05-04 15:36:22 +020079
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040080 // salt 'kvm02*' state.sls salt.control
chnyda625f4b42017-10-11 14:10:31 +020081 salt.enforceState(pepperEnv, "${upgNodeProvider}", 'salt.control')
Jiri Broulikbb447ac2017-05-04 15:36:22 +020082
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040083 // wait until upg node is registered in salt-key
chnyda625f4b42017-10-11 14:10:31 +020084 salt.minionPresent(pepperEnv, 'I@salt:master', 'upg01')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040085
86 // salt '*' saltutil.refresh_pillar
chnyda625f4b42017-10-11 14:10:31 +020087 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.refresh_pillar', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040088 // salt '*' saltutil.sync_all
chnyda625f4b42017-10-11 14:10:31 +020089 salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.sync_all', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040090
91 // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog
92 try {
chnyda625f4b42017-10-11 14:10:31 +020093 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040094 } catch (Exception e) {
95 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
96 }
chnyda625f4b42017-10-11 14:10:31 +020097 salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Jiri Broulikbb447ac2017-05-04 15:36:22 +020098
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040099 // salt "upg*" state.sls rabbitmq
chnyda625f4b42017-10-11 14:10:31 +0200100 salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400101 try {
chnyda625f4b42017-10-11 14:10:31 +0200102 salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400103 } catch (Exception e) {
104 common.warningMsg('salt-minion was restarted. We should continue to run')
105 }
106 try {
chnyda625f4b42017-10-11 14:10:31 +0200107 salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400108 } catch (Exception e) {
109 common.warningMsg('salt-minion was restarted. We should continue to run')
110 }
111 // salt '*' state.apply salt.minion.grains
chnyda625f4b42017-10-11 14:10:31 +0200112 //salt.enforceState(pepperEnv, '*', 'salt.minion.grains')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400113 // salt -C 'I@backupninja:server' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200114 salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400115 // salt -C 'I@backupninja:client' state.sls backupninja
chnyda625f4b42017-10-11 14:10:31 +0200116 salt.enforceState(pepperEnv, 'I@backupninja:client', 'backupninja')
117 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400118 try {
chnyda625f4b42017-10-11 14:10:31 +0200119 salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400120 } catch (Exception e) {
121 common.warningMsg('The ARP entry does not exist. We should continue to run.')
122 }
chnyda625f4b42017-10-11 14:10:31 +0200123 salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true)
124 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql')
125 salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog')
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200126
chnyda625f4b42017-10-11 14:10:31 +0200127 salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup')
128 salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client')
129 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
130 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200131
chnyda625f4b42017-10-11 14:10:31 +0200132 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 +0400133 if(databases && databases != ""){
134 def databasesList = databases['return'][0].values()[0].trim().tokenize("\n")
135 for( i = 0; i < databasesList.size(); i++){
136 if(databasesList[i].toLowerCase().contains('upgrade')){
chnyda625f4b42017-10-11 14:10:31 +0200137 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400138 common.warningMsg("removing database ${databasesList[i]}")
chnyda625f4b42017-10-11 14:10:31 +0200139 salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true)
Jiri Broulik3792c962017-05-17 18:26:36 +0200140 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200141 }
chnyda625f4b42017-10-11 14:10:31 +0200142 salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400143 }else{
144 common.errorMsg("No _upgrade databases were returned")
145 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200146
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400147 try {
chnyda625f4b42017-10-11 14:10:31 +0200148 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
149 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400150 } catch (Exception e) {
151 common.warningMsg('Restarting Apache2')
chnyda625f4b42017-10-11 14:10:31 +0200152 salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400153 }
154 try {
chnyda625f4b42017-10-11 14:10:31 +0200155 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400156 } catch (Exception e) {
157 common.warningMsg('running keystone.client state again')
chnyda625f4b42017-10-11 14:10:31 +0200158 salt.enforceState(pepperEnv, 'upg*', 'keystone.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400159 }
160 try {
chnyda625f4b42017-10-11 14:10:31 +0200161 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400162 } catch (Exception e) {
163 common.warningMsg('running glance state again')
chnyda625f4b42017-10-11 14:10:31 +0200164 salt.enforceState(pepperEnv, 'upg*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400165 }
chnyda625f4b42017-10-11 14:10:31 +0200166 salt.enforceState(pepperEnv, 'upg*', 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400167 try {
chnyda625f4b42017-10-11 14:10:31 +0200168 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400169 } catch (Exception e) {
170 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200171 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400172 }
173 // run nova state again as sometimes nova does not enforce itself for some reason
174 try {
chnyda625f4b42017-10-11 14:10:31 +0200175 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400176 } catch (Exception e) {
177 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200178 salt.enforceState(pepperEnv, 'upg*', 'nova')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400179 }
180 try {
chnyda625f4b42017-10-11 14:10:31 +0200181 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400182 } catch (Exception e) {
183 common.warningMsg('running cinder state again')
chnyda625f4b42017-10-11 14:10:31 +0200184 salt.enforceState(pepperEnv, 'upg*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400185 }
186 try {
chnyda625f4b42017-10-11 14:10:31 +0200187 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400188 } catch (Exception e) {
189 common.warningMsg('running neutron state again')
chnyda625f4b42017-10-11 14:10:31 +0200190 salt.enforceState(pepperEnv, 'upg*', 'neutron')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400191 }
192 try {
chnyda625f4b42017-10-11 14:10:31 +0200193 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400194 } catch (Exception e) {
195 common.warningMsg('running heat state again')
chnyda625f4b42017-10-11 14:10:31 +0200196 salt.enforceState(pepperEnv, 'upg*', 'heat')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400197 }
chnyda625f4b42017-10-11 14:10:31 +0200198 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 +0400199
200 if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
201 stage('Ask for manual confirmation') {
202 input message: "Do you want to continue with upgrade?"
Jiri Broulik3792c962017-05-17 18:26:36 +0200203 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400204 }
205 }
206 }
207
208 if (STAGE_REAL_UPGRADE.toBoolean() == true) {
209 stage('Real upgrade') {
210 // # actual upgrade
211
chnyda625f4b42017-10-11 14:10:31 +0200212 _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400213 domain = _pillar['return'][0].values()[0].values()[0]
214 print(_pillar)
215 print(domain)
216
chnyda625f4b42017-10-11 14:10:31 +0200217 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400218 kvm01 = _pillar['return'][0].values()[0].values()[0]
219 print(_pillar)
220 print(kvm01)
221
222 def errorOccured = false
223
chnyda625f4b42017-10-11 14:10:31 +0200224 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400225 def ctl01NodeProvider = _pillar['return'][0].values()[0]
226
chnyda625f4b42017-10-11 14:10:31 +0200227 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400228 def ctl02NodeProvider = _pillar['return'][0].values()[0]
229
chnyda625f4b42017-10-11 14:10:31 +0200230 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400231 def ctl03NodeProvider = _pillar['return'][0].values()[0]
232
chnyda625f4b42017-10-11 14:10:31 +0200233 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400234 def prx01NodeProvider = _pillar['return'][0].values()[0]
235
chnyda625f4b42017-10-11 14:10:31 +0200236 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400237 def prx02NodeProvider = _pillar['return'][0].values()[0]
238
239
chnyda625f4b42017-10-11 14:10:31 +0200240 salt.runSaltProcessStep(pepperEnv, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
241 salt.runSaltProcessStep(pepperEnv, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
242 salt.runSaltProcessStep(pepperEnv, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
243 salt.runSaltProcessStep(pepperEnv, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
244 salt.runSaltProcessStep(pepperEnv, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400245
246
247 try {
chnyda625f4b42017-10-11 14:10:31 +0200248 salt.cmdRun(pepperEnv, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400249 } catch (Exception e) {
250 common.warningMsg('File already exists')
251 }
252 try {
chnyda625f4b42017-10-11 14:10:31 +0200253 salt.cmdRun(pepperEnv, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400254 } catch (Exception e) {
255 common.warningMsg('File already exists')
256 }
257 try {
chnyda625f4b42017-10-11 14:10:31 +0200258 salt.cmdRun(pepperEnv, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400259 } catch (Exception e) {
260 common.warningMsg('File already exists')
261 }
262 try {
chnyda625f4b42017-10-11 14:10:31 +0200263 salt.cmdRun(pepperEnv, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400264 } catch (Exception e) {
265 common.warningMsg('File already exists')
266 }
267 try {
chnyda625f4b42017-10-11 14:10:31 +0200268 salt.cmdRun(pepperEnv, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400269 } catch (Exception e) {
270 common.warningMsg('File already exists')
271 }
272
273
chnyda625f4b42017-10-11 14:10:31 +0200274 salt.runSaltProcessStep(pepperEnv, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true)
275 salt.runSaltProcessStep(pepperEnv, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true)
276 salt.runSaltProcessStep(pepperEnv, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true)
277 salt.runSaltProcessStep(pepperEnv, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true)
278 salt.runSaltProcessStep(pepperEnv, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400279
chnyda625f4b42017-10-11 14:10:31 +0200280 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400281
282 try {
chnyda625f4b42017-10-11 14:10:31 +0200283 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400284 } catch (Exception e) {
285 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
286 }
287
288 // salt 'kvm*' state.sls salt.control
chnyda625f4b42017-10-11 14:10:31 +0200289 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400290
291 // wait until ctl and prx nodes are registered in salt-key
chnyda625f4b42017-10-11 14:10:31 +0200292 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl01')
293 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl02')
294 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl03')
295 salt.minionPresent(pepperEnv, 'I@salt:master', 'prx01')
296 salt.minionPresent(pepperEnv, 'I@salt:master', 'prx02')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400297
298
299 // salt '*' saltutil.refresh_pillar
chnyda625f4b42017-10-11 14:10:31 +0200300 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400301 // salt '*' saltutil.sync_all
chnyda625f4b42017-10-11 14:10:31 +0200302 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400303
304 try {
chnyda625f4b42017-10-11 14:10:31 +0200305 salt.enforceState(pepperEnv, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400306 } catch (Exception e) {
307 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
308 }
chnyda625f4b42017-10-11 14:10:31 +0200309 salt.enforceState(pepperEnv, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400310
311 // salt 'ctl*' state.sls keepalived
312 // salt 'ctl*' state.sls haproxy
chnyda625f4b42017-10-11 14:10:31 +0200313 salt.enforceState(pepperEnv, 'ctl*', ['keepalived', 'haproxy'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400314 // salt 'ctl*' service.restart rsyslog
chnyda625f4b42017-10-11 14:10:31 +0200315 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['rsyslog'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400316 // salt "ctl*" state.sls memcached
317 // salt "ctl*" state.sls keystone.server
318 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200319 try {
chnyda625f4b42017-10-11 14:10:31 +0200320 salt.enforceState(pepperEnv, 'ctl*', ['memcached', 'keystone.server'])
321 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400322 } catch (Exception e) {
323 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
chnyda625f4b42017-10-11 14:10:31 +0200324 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['apache2'], null, true)
325 salt.enforceState(pepperEnv, 'ctl*', 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400326 }
327 // salt 'ctl01*' state.sls keystone.client
328 try {
chnyda625f4b42017-10-11 14:10:31 +0200329 salt.enforceState(pepperEnv, 'I@keystone:client and ctl*', 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200330 } catch (Exception e) {
331 common.warningMsg('running keystone.client state again')
chnyda625f4b42017-10-11 14:10:31 +0200332 salt.enforceState(pepperEnv, 'I@keystone:client and ctl*', 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200333 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200334 try {
chnyda625f4b42017-10-11 14:10:31 +0200335 salt.enforceState(pepperEnv, 'ctl*', 'glance')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200336 } catch (Exception e) {
337 common.warningMsg('running glance state again')
chnyda625f4b42017-10-11 14:10:31 +0200338 salt.enforceState(pepperEnv, 'ctl*', 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400339 } // salt 'ctl*' state.sls glusterfs.client
chnyda625f4b42017-10-11 14:10:31 +0200340 salt.enforceState(pepperEnv, 'ctl*', 'glusterfs.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400341 // salt 'ctl*' state.sls keystone.server
chnyda625f4b42017-10-11 14:10:31 +0200342 salt.enforceState(pepperEnv, 'ctl*', 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400343 // salt 'ctl*' state.sls nova
Jiri Broulik5f83c292017-05-18 12:09:07 +0200344 try {
chnyda625f4b42017-10-11 14:10:31 +0200345 salt.enforceState(pepperEnv, 'ctl*', 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200346 } catch (Exception e) {
347 common.warningMsg('running nova state again')
chnyda625f4b42017-10-11 14:10:31 +0200348 salt.enforceState(pepperEnv, 'ctl*', 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200349 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400350 // salt 'ctl*' state.sls cinder
Jiri Broulik80d96752017-05-22 19:42:01 +0200351 try {
chnyda625f4b42017-10-11 14:10:31 +0200352 salt.enforceState(pepperEnv, 'ctl*', 'cinder')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200353 } catch (Exception e) {
354 common.warningMsg('running cinder state again')
chnyda625f4b42017-10-11 14:10:31 +0200355 salt.enforceState(pepperEnv, 'ctl*', 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400356 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200357 try {
chnyda625f4b42017-10-11 14:10:31 +0200358 salt.enforceState(pepperEnv, 'ctl*', 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200359 } catch (Exception e) {
360 common.warningMsg('running neutron state again')
chnyda625f4b42017-10-11 14:10:31 +0200361 salt.enforceState(pepperEnv, 'ctl*', 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200362 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400363 // salt 'ctl*' state.sls heat
Jiri Broulikbda0a212017-05-18 12:54:51 +0200364 try {
chnyda625f4b42017-10-11 14:10:31 +0200365 salt.enforceState(pepperEnv, 'ctl*', 'heat')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200366 } catch (Exception e) {
367 common.warningMsg('running heat state again')
chnyda625f4b42017-10-11 14:10:31 +0200368 salt.enforceState(pepperEnv, 'ctl*', 'heat')
Jiri Broulik3792c962017-05-17 18:26:36 +0200369 }
370
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400371 } catch (Exception e) {
372 errorOccured = true
373 common.warningMsg('Some states that require syncdb failed. Restoring production databases')
Jiri Broulik3792c962017-05-17 18:26:36 +0200374
Jiri Broulik00d01092017-06-01 19:38:15 +0200375 // database restore section
376 try {
chnyda625f4b42017-10-11 14:10:31 +0200377 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400378 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200379 common.warningMsg('Mysql service already stopped')
Jiri Broulik3792c962017-05-17 18:26:36 +0200380 }
Jiri Broulik00d01092017-06-01 19:38:15 +0200381 try {
chnyda625f4b42017-10-11 14:10:31 +0200382 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400383 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200384 common.warningMsg('Mysql service already stopped')
385 }
386 try {
chnyda625f4b42017-10-11 14:10:31 +0200387 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400388 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200389 common.warningMsg('Files are not present')
390 }
391 try {
chnyda625f4b42017-10-11 14:10:31 +0200392 salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400393 } catch (Exception er) {
394 common.warningMsg('Directory already exists')
395 }
396 try {
chnyda625f4b42017-10-11 14:10:31 +0200397 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400398 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200399 common.warningMsg('Directory already empty')
400 }
401 try {
chnyda625f4b42017-10-11 14:10:31 +0200402 salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400403 } catch (Exception er) {
404 common.warningMsg('Files were already moved')
405 }
406 try {
chnyda625f4b42017-10-11 14:10:31 +0200407 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400408 } catch (Exception er) {
Jiri Broulik00d01092017-06-01 19:38:15 +0200409 common.warningMsg('File is not present')
410 }
chnyda625f4b42017-10-11 14:10:31 +0200411 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
412 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Jiri Broulik00d01092017-06-01 19:38:15 +0200413 backup_dir = _pillar['return'][0].values()[0]
414 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
415 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200416 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
417 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
418 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200419
420 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200421 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200422
chnyda625f4b42017-10-11 14:10:31 +0200423 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik00d01092017-06-01 19:38:15 +0200424 //
Jiri Broulik3792c962017-05-17 18:26:36 +0200425
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400426 common.errorMsg("Stage Real control upgrade failed")
427 }
428 if(!errorOccured){
429
430 ceph = null
431
432 try {
chnyda625f4b42017-10-11 14:10:31 +0200433 ceph = salt.cmdRun(pepperEnv, 'ctl*', "salt-call grains.item roles | grep ceph.client")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400434
435 } catch (Exception er) {
436 common.infoMsg("Ceph is not used")
437 }
438
439 if(ceph != null) {
440 try {
chnyda625f4b42017-10-11 14:10:31 +0200441 salt.enforceState(pepperEnv, 'ctl*', 'ceph.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400442 } catch (Exception er) {
443 common.warningMsg("Ceph client state on controllers failed. Please fix it manually")
444 }
445 }
Jiri Broulik3792c962017-05-17 18:26:36 +0200446
447 // salt 'cmp*' cmd.run 'service nova-compute restart'
chnyda625f4b42017-10-11 14:10:31 +0200448 salt.runSaltProcessStep(pepperEnv, 'cmp*', 'service.restart', ['nova-compute'], null, true)
449 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['nova-conductor'], null, true)
450 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['nova-scheduler'], null, true)
Jiri Broulikf20c7672017-06-19 21:20:52 +0200451
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400452
453 // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog
454 // salt 'ctl*' state.sls keepalived
455 // salt 'prx*' state.sls keepalived
chnyda625f4b42017-10-11 14:10:31 +0200456 salt.enforceState(pepperEnv, 'prx*', 'keepalived')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400457 // salt 'prx*' state.sls horizon
chnyda625f4b42017-10-11 14:10:31 +0200458 salt.enforceState(pepperEnv, 'prx*', 'horizon')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400459 // salt 'prx*' state.sls nginx
chnyda625f4b42017-10-11 14:10:31 +0200460 salt.enforceState(pepperEnv, 'prx*', 'nginx')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400461 // salt "prx*" state.sls memcached
chnyda625f4b42017-10-11 14:10:31 +0200462 salt.enforceState(pepperEnv, 'prx*', 'memcached')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400463
464 try {
chnyda625f4b42017-10-11 14:10:31 +0200465 salt.enforceHighstate(pepperEnv, 'ctl*')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400466 } catch (Exception er) {
467 common.errorMsg("Highstate was executed on controller nodes but something failed. Please check it and fix it accordingly.")
468 }
469
470 try {
chnyda625f4b42017-10-11 14:10:31 +0200471 salt.enforceHighstate(pepperEnv, 'prx*')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400472 } catch (Exception er) {
473 common.errorMsg("Highstate was executed on proxy nodes but something failed. Please check it and fix it accordingly.")
474 }
475
chnyda625f4b42017-10-11 14:10:31 +0200476 salt.cmdRun(pepperEnv, 'ctl01*', '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
Jiri Broulik3792c962017-05-17 18:26:36 +0200477 }
Jiri Broulik6fc9d3f2017-05-12 07:11:29 +0200478 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400479
480 if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
481 stage('Ask for manual confirmation') {
482 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?"
483 }
484 }
485 }
486
487 if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
488 stage('Rollback upgrade') {
489
490 stage('Ask for manual confirmation') {
491 input message: "Do you really want to continue with the rollback?"
492 }
493
chnyda625f4b42017-10-11 14:10:31 +0200494 _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400495 domain = _pillar['return'][0].values()[0].values()[0]
496 print(_pillar)
497 print(domain)
498
chnyda625f4b42017-10-11 14:10:31 +0200499 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400500 kvm01 = _pillar['return'][0].values()[0].values()[0]
501 print(_pillar)
502 print(kvm01)
503
chnyda625f4b42017-10-11 14:10:31 +0200504 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400505 def ctl01NodeProvider = _pillar['return'][0].values()[0]
506
chnyda625f4b42017-10-11 14:10:31 +0200507 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400508 def ctl02NodeProvider = _pillar['return'][0].values()[0]
509
chnyda625f4b42017-10-11 14:10:31 +0200510 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400511 def ctl03NodeProvider = _pillar['return'][0].values()[0]
512
chnyda625f4b42017-10-11 14:10:31 +0200513 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400514 def prx01NodeProvider = _pillar['return'][0].values()[0]
515
chnyda625f4b42017-10-11 14:10:31 +0200516 _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400517 def prx02NodeProvider = _pillar['return'][0].values()[0]
518
chnyda625f4b42017-10-11 14:10:31 +0200519 salt.runSaltProcessStep(pepperEnv, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true)
520 salt.runSaltProcessStep(pepperEnv, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true)
521 salt.runSaltProcessStep(pepperEnv, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true)
522 salt.runSaltProcessStep(pepperEnv, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true)
523 salt.runSaltProcessStep(pepperEnv, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400524
chnyda625f4b42017-10-11 14:10:31 +0200525 salt.runSaltProcessStep(pepperEnv, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true)
526 salt.runSaltProcessStep(pepperEnv, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true)
527 salt.runSaltProcessStep(pepperEnv, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true)
528 salt.runSaltProcessStep(pepperEnv, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true)
529 salt.runSaltProcessStep(pepperEnv, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400530
531 try {
chnyda625f4b42017-10-11 14:10:31 +0200532 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400533 } catch (Exception e) {
534 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
535 }
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
chnyda625f4b42017-10-11 14:10:31 +0200578 salt.runSaltProcessStep(pepperEnv, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true)
579 salt.runSaltProcessStep(pepperEnv, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true)
580 salt.runSaltProcessStep(pepperEnv, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true)
581 salt.runSaltProcessStep(pepperEnv, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true)
582 salt.runSaltProcessStep(pepperEnv, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400583
584 // salt 'cmp*' cmd.run 'service nova-compute restart'
chnyda625f4b42017-10-11 14:10:31 +0200585 salt.runSaltProcessStep(pepperEnv, 'cmp*', 'service.restart', ['nova-compute'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400586
587 // wait until ctl and prx nodes are registered in salt-key
chnyda625f4b42017-10-11 14:10:31 +0200588 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl01')
589 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl02')
590 salt.minionPresent(pepperEnv, 'I@salt:master', 'ctl03')
591 salt.minionPresent(pepperEnv, 'I@salt:master', 'prx01')
592 salt.minionPresent(pepperEnv, 'I@salt:master', 'prx02')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400593
chnyda625f4b42017-10-11 14:10:31 +0200594 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['nova-conductor'], null, true)
595 salt.runSaltProcessStep(pepperEnv, 'ctl*', 'service.restart', ['nova-scheduler'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400596
chnyda625f4b42017-10-11 14:10:31 +0200597 salt.cmdRun(pepperEnv, 'ctl01*', '. /root/keystonerc; nova service-list; glance image-list; nova flavor-list; nova hypervisor-list; nova list; neutron net-list; cinder list; heat service-list')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400598 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200599 }
600}