blob: 0e305987e59ee5c080b974e07ea10ce39a158490 [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
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100224 def proxy_general_target = ""
225 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100226 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400227
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100228 for (t in proxy_target_hosts) {
229 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100230 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100231 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100232 def nodeProvider = _pillar['return'][0].values()[0]
233 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
234 sleep(2)
235 try {
236 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
237 } catch (Exception e) {
238 common.warningMsg('File already exists')
239 }
240 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
241 try {
242 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
243 } catch (Exception e) {
244 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
245 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100246 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400247 }
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100248 def control_general_target = ""
249 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100250 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400251
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100252 for (t in control_target_hosts) {
253 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100254 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100255 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100256 def nodeProvider = _pillar['return'][0].values()[0]
257 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
258 sleep(2)
259 try {
260 salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak")
261 } catch (Exception e) {
262 common.warningMsg('File already exists')
263 }
264 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true)
265 try {
266 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
267 } catch (Exception e) {
268 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
269 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100270 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100271 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400272
chnyda625f4b42017-10-11 14:10:31 +0200273 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400274
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400275 // salt 'kvm*' state.sls salt.control
chnyda625f4b42017-10-11 14:10:31 +0200276 salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400277
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100278 for (t in control_target_hosts) {
279 def target = t.split("\\.")[0]
280 // wait until ctl and prx nodes are registered in salt-key
281 salt.minionPresent(pepperEnv, 'I@salt:master', '${target}')
282 }
283 for (t in proxy_target_hosts) {
284 def target = t.split("\\.")[0]
285 // wait until ctl and prx nodes are registered in salt-key
286 salt.minionPresent(pepperEnv, 'I@salt:master', '${target}')
287 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400288
289 // salt '*' saltutil.refresh_pillar
chnyda625f4b42017-10-11 14:10:31 +0200290 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400291 // salt '*' saltutil.sync_all
chnyda625f4b42017-10-11 14:10:31 +0200292 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400293
294 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100295 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400296 } catch (Exception e) {
297 common.warningMsg('Received no response because salt-minion was restarted. We should continue to run')
298 }
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100299 salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400300
301 // salt 'ctl*' state.sls keepalived
302 // salt 'ctl*' state.sls haproxy
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100303 salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy'])
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400304 // salt 'ctl*' service.restart rsyslog
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100305 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400306 // salt "ctl*" state.sls memcached
307 // salt "ctl*" state.sls keystone.server
308 try {
Jiri Broulik69de13a2017-05-18 13:53:58 +0200309 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100310 salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server'])
311 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400312 } catch (Exception e) {
313 common.warningMsg('Restarting Apache2 and enforcing keystone.server state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100314 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true)
315 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400316 }
317 // salt 'ctl01*' state.sls keystone.client
318 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100319 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200320 } catch (Exception e) {
321 common.warningMsg('running keystone.client state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100322 salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client')
Jiri Broulik69de13a2017-05-18 13:53:58 +0200323 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200324 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100325 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200326 } catch (Exception e) {
327 common.warningMsg('running glance state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100328 salt.enforceState(pepperEnv, "${control_general_target}*", 'glance')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400329 } // salt 'ctl*' state.sls glusterfs.client
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100330 salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400331 // salt 'ctl*' state.sls keystone.server
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100332 salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400333 // salt 'ctl*' state.sls nova
Jiri Broulik5f83c292017-05-18 12:09:07 +0200334 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100335 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200336 } catch (Exception e) {
337 common.warningMsg('running nova state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100338 salt.enforceState(pepperEnv, "${control_general_target}*", 'nova')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200339 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400340 // salt 'ctl*' state.sls cinder
Jiri Broulik80d96752017-05-22 19:42:01 +0200341 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100342 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200343 } catch (Exception e) {
344 common.warningMsg('running cinder state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100345 salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400346 }
Jiri Broulik5f83c292017-05-18 12:09:07 +0200347 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100348 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200349 } catch (Exception e) {
350 common.warningMsg('running neutron state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100351 salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron')
Jiri Broulik5f83c292017-05-18 12:09:07 +0200352 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400353 // salt 'ctl*' state.sls heat
Jiri Broulikbda0a212017-05-18 12:54:51 +0200354 try {
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100355 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulikbda0a212017-05-18 12:54:51 +0200356 } catch (Exception e) {
357 common.warningMsg('running heat state again')
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100358 salt.enforceState(pepperEnv, "${control_general_target}*", 'heat')
Jiri Broulik3792c962017-05-17 18:26:36 +0200359 }
360
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400361 } catch (Exception e) {
362 errorOccured = true
363 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
chnyda625f4b42017-10-11 14:10:31 +0200484 _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400485 domain = _pillar['return'][0].values()[0].values()[0]
486 print(_pillar)
487 print(domain)
488
chnyda625f4b42017-10-11 14:10:31 +0200489 _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400490 kvm01 = _pillar['return'][0].values()[0].values()[0]
491 print(_pillar)
492 print(kvm01)
493
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100494 def proxy_general_target = ""
495 def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100496 def node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400497
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100498 for (t in proxy_target_hosts) {
499 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100500 proxy_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100501 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100502 def nodeProvider = _pillar['return'][0].values()[0]
503 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
504 sleep(2)
505 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
506 try {
507 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
508 } catch (Exception e) {
509 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
510 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100511 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100512 }
513 def control_general_target = ""
514 def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server')
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100515 node_count = 1
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400516
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100517 for (t in control_target_hosts) {
518 def target = t.split("\\.")[0]
Jiri Broulik42dfbb12017-11-13 11:27:45 +0100519 control_general_target = target.replaceAll('\\d+$', "")
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100520 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100521 def nodeProvider = _pillar['return'][0].values()[0]
522 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true)
523 sleep(2)
524 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true)
525 try {
526 salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y")
527 } catch (Exception e) {
528 common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run')
529 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100530 node_count++
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400531 }
532
533 // database restore section
534 try {
chnyda625f4b42017-10-11 14:10:31 +0200535 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400536 } catch (Exception e) {
537 common.warningMsg('Mysql service already stopped')
538 }
539 try {
chnyda625f4b42017-10-11 14:10:31 +0200540 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400541 } catch (Exception e) {
542 common.warningMsg('Mysql service already stopped')
543 }
544 try {
chnyda625f4b42017-10-11 14:10:31 +0200545 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400546 } catch (Exception e) {
547 common.warningMsg('Files are not present')
548 }
549 try {
chnyda625f4b42017-10-11 14:10:31 +0200550 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400551 } catch (Exception e) {
552 common.warningMsg('Directory already empty')
553 }
554 try {
chnyda625f4b42017-10-11 14:10:31 +0200555 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400556 } catch (Exception e) {
557 common.warningMsg('File is not present')
558 }
chnyda625f4b42017-10-11 14:10:31 +0200559 salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
560 _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400561 backup_dir = _pillar['return'][0].values()[0]
562 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
563 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +0200564 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
565 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
566 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400567
568 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +0200569 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400570
chnyda625f4b42017-10-11 14:10:31 +0200571 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400572 //
573
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100574 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100575 for (t in control_target_hosts) {
576 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100577 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100578 def nodeProvider = _pillar['return'][0].values()[0]
579 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100580 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100581 }
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100582 node_count = 1
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100583 for (t in proxy_target_hosts) {
584 def target = t.split("\\.")[0]
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100585 _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider")
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100586 def nodeProvider = _pillar['return'][0].values()[0]
587 salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true)
Jiri Broulik21b4f4d2017-11-13 14:04:46 +0100588 node_count++
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100589 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400590
591 // salt 'cmp*' cmd.run 'service nova-compute restart'
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100592 salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400593
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100594 for (t in control_target_hosts) {
595 def target = t.split("\\.")[0]
596 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
597 }
598 for (t in proxy_target_hosts) {
599 def target = t.split("\\.")[0]
600 salt.minionPresent(pepperEnv, 'I@salt:master', "${target}")
601 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400602
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100603 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true)
604 salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400605
Jiri Broulik3f5ed1a2017-11-10 17:35:52 +0100606 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 +0400607 }
Jiri Broulikbb447ac2017-05-04 15:36:22 +0200608 }
609}