Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 1 | /** |
| 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 Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 7 | * STAGE_TEST_UPGRADE Run test upgrade stage (bool) |
| 8 | * STAGE_REAL_UPGRADE Run real upgrade stage (bool) |
| 9 | * STAGE_ROLLBACK_UPGRADE Run rollback upgrade stage (bool) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 10 | * |
| 11 | **/ |
| 12 | |
| 13 | def common = new com.mirantis.mk.Common() |
| 14 | def salt = new com.mirantis.mk.Salt() |
| 15 | |
| 16 | |
| 17 | def saltMaster |
| 18 | |
| 19 | timestamps { |
| 20 | node() { |
| 21 | |
| 22 | stage('Connect to Salt API') { |
| 23 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 24 | } |
| 25 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 26 | if (STAGE_TEST_UPGRADE.toBoolean() == true) { |
| 27 | stage('Test upgrade') { |
| 28 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 29 | |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 30 | try { |
| 31 | salt.enforceState(saltMaster, 'I@salt:master', 'reclass') |
| 32 | } catch (Exception e) { |
Jiri Broulik | 3467432 | 2017-05-25 19:10:57 +0200 | [diff] [blame] | 33 | common.warningMsg("Some parts of Reclass state failed. The most probable reasons were uncommited changes. We should continue to run") |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Jiri Broulik | 3467432 | 2017-05-25 19:10:57 +0200 | [diff] [blame] | 36 | try { |
| 37 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 38 | } catch (Exception e) { |
| 39 | common.warningMsg("No response from some minions. We should continue to run") |
| 40 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 41 | |
Jiri Broulik | 3467432 | 2017-05-25 19:10:57 +0200 | [diff] [blame] | 42 | try { |
| 43 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true) |
| 44 | } catch (Exception e) { |
| 45 | common.warningMsg("No response from some minions. We should continue to run") |
| 46 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 47 | |
| 48 | def _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 49 | def domain = _pillar['return'][0].values()[0].values()[0] |
| 50 | print(_pillar) |
| 51 | print(domain) |
| 52 | |
| 53 | // read backupninja variable |
| 54 | _pillar = salt.getPillar(saltMaster, 'I@backupninja:client', '_param:backupninja_backup_host') |
| 55 | def backupninja_backup_host = _pillar['return'][0].values()[0] |
| 56 | print(_pillar) |
| 57 | print(backupninja_backup_host) |
| 58 | |
| 59 | _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id') |
| 60 | def kvm01 = _pillar['return'][0].values()[0].values()[0] |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 61 | print(_pillar) |
| 62 | print(kvm01) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 63 | |
| 64 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider') |
| 65 | def upgNodeProvider = _pillar['return'][0].values()[0] |
| 66 | print(_pillar) |
| 67 | print(upgNodeProvider) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 68 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 69 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 70 | salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true) |
| 71 | salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 72 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 73 | |
| 74 | try { |
Jiri Broulik | d6bc138 | 2017-05-17 18:46:27 +0200 | [diff] [blame] | 75 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d upg01.${domain} -y") |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 76 | } catch (Exception e) { |
Jiri Broulik | d6bc138 | 2017-05-17 18:46:27 +0200 | [diff] [blame] | 77 | 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") |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 78 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 79 | |
| 80 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 81 | // salt 'kvm02*' state.sls salt.control |
| 82 | salt.enforceState(saltMaster, "${upgNodeProvider}", 'salt.control') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 83 | |
Jiri Broulik | 9b73d6c | 2017-06-02 12:27:05 +0200 | [diff] [blame] | 84 | sleep(70) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 85 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 86 | // salt '*' saltutil.refresh_pillar |
| 87 | salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.refresh_pillar', [], null, true) |
| 88 | // salt '*' saltutil.sync_all |
| 89 | salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.sync_all', [], null, true) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 90 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 91 | // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog |
| 92 | try { |
| 93 | salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 94 | } catch (Exception e) { |
| 95 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 96 | } |
| 97 | salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 98 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 99 | // salt "upg*" state.sls rabbitmq |
| 100 | salt.enforceState(saltMaster, 'upg*', ['rabbitmq', 'memcached']) |
| 101 | try { |
| 102 | salt.enforceState(saltMaster, 'I@backupninja:client', ['openssh.client', 'salt.minion']) |
| 103 | } catch (Exception e) { |
| 104 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 105 | } |
| 106 | try { |
| 107 | salt.enforceState(saltMaster, 'I@backupninja:server', ['salt.minion']) |
| 108 | } catch (Exception e) { |
| 109 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 110 | } |
| 111 | // salt '*' state.apply salt.minion.grains |
| 112 | //salt.enforceState(saltMaster, '*', 'salt.minion.grains') |
| 113 | // salt -C 'I@backupninja:server' state.sls backupninja |
| 114 | salt.enforceState(saltMaster, 'I@backupninja:server', 'backupninja') |
| 115 | // salt -C 'I@backupninja:client' state.sls backupninja |
| 116 | salt.enforceState(saltMaster, 'I@backupninja:client', 'backupninja') |
| 117 | salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true) |
| 118 | salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}") |
| 119 | salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true) |
| 120 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql') |
Jiri Broulik | 2be7f67 | 2017-05-25 11:07:06 +0200 | [diff] [blame] | 121 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync > /tmp/backupninjalog') |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 122 | |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 123 | salt.enforceState(saltMaster, 'I@xtrabackup:server', 'xtrabackup') |
| 124 | salt.enforceState(saltMaster, 'I@xtrabackup:client', 'openssh.client') |
| 125 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 126 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'") |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 127 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 128 | def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'') |
| 129 | if(databases && databases != ""){ |
| 130 | def databasesList = databases['return'][0].values()[0].trim().tokenize("\n") |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 131 | for( i = 0; i < databasesList.size(); i++){ |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 132 | if(databasesList[i].toLowerCase().contains('upgrade')){ |
| 133 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true) |
| 134 | common.warningMsg("removing database ${databasesList[i]}") |
| 135 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true) |
| 136 | } |
| 137 | } |
Jiri Broulik | 5a13a65 | 2017-05-18 14:33:32 +0200 | [diff] [blame] | 138 | salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 139 | }else{ |
| 140 | common.errorMsg("No _upgrade databases were returned") |
| 141 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 142 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 143 | try { |
| 144 | salt.enforceState(saltMaster, 'upg*', 'keystone.server') |
| 145 | } catch (Exception e) { |
Jiri Broulik | 08229c8 | 2017-05-22 23:35:32 +0200 | [diff] [blame] | 146 | common.warningMsg('Restarting Apache2') |
Jiri Broulik | 5a13a65 | 2017-05-18 14:33:32 +0200 | [diff] [blame] | 147 | salt.runSaltProcessStep(saltMaster, 'upg*', 'service.restart', ['apache2'], null, true) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 148 | } |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 149 | try { |
| 150 | salt.enforceState(saltMaster, 'upg*', 'keystone.client') |
| 151 | } catch (Exception e) { |
| 152 | common.warningMsg('running keystone.client state again') |
| 153 | salt.enforceState(saltMaster, 'upg*', 'keystone.client') |
| 154 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 155 | try { |
| 156 | salt.enforceState(saltMaster, 'upg*', 'glance') |
| 157 | } catch (Exception e) { |
| 158 | common.warningMsg('running glance state again') |
| 159 | salt.enforceState(saltMaster, 'upg*', 'glance') |
| 160 | } |
| 161 | salt.enforceState(saltMaster, 'upg*', 'keystone.server') |
| 162 | try { |
| 163 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 164 | } catch (Exception e) { |
| 165 | common.warningMsg('running nova state again') |
| 166 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 167 | } |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 168 | // run nova state again as sometimes nova does not enforce itself for some reason |
| 169 | try { |
| 170 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 171 | } catch (Exception e) { |
| 172 | common.warningMsg('running nova state again') |
| 173 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 174 | } |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 175 | try { |
| 176 | salt.enforceState(saltMaster, 'upg*', 'cinder') |
| 177 | } catch (Exception e) { |
| 178 | common.warningMsg('running cinder state again') |
| 179 | salt.enforceState(saltMaster, 'upg*', 'cinder') |
| 180 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 181 | try { |
| 182 | salt.enforceState(saltMaster, 'upg*', 'neutron') |
| 183 | } catch (Exception e) { |
| 184 | common.warningMsg('running neutron state again') |
| 185 | salt.enforceState(saltMaster, 'upg*', 'neutron') |
| 186 | } |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 187 | try { |
| 188 | salt.enforceState(saltMaster, 'upg*', 'heat') |
| 189 | } catch (Exception e) { |
| 190 | common.warningMsg('running heat state again') |
| 191 | salt.enforceState(saltMaster, 'upg*', 'heat') |
| 192 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 193 | salt.cmdRun(saltMaster, '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') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 194 | |
Jiri Broulik | 08229c8 | 2017-05-22 23:35:32 +0200 | [diff] [blame] | 195 | if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 196 | stage('Ask for manual confirmation') { |
| 197 | input message: "Do you want to continue with upgrade?" |
| 198 | } |
| 199 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 200 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 203 | if (STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 204 | stage('Real upgrade') { |
| 205 | // # actual upgrade |
| 206 | |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 207 | _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 208 | domain = _pillar['return'][0].values()[0].values()[0] |
| 209 | print(_pillar) |
| 210 | print(domain) |
| 211 | |
| 212 | _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id') |
| 213 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 214 | print(_pillar) |
| 215 | print(kvm01) |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 216 | |
| 217 | def errorOccured = false |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 218 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 219 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider') |
| 220 | def ctl01NodeProvider = _pillar['return'][0].values()[0] |
| 221 | |
| 222 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider') |
| 223 | def ctl02NodeProvider = _pillar['return'][0].values()[0] |
| 224 | |
| 225 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider') |
| 226 | def ctl03NodeProvider = _pillar['return'][0].values()[0] |
| 227 | |
| 228 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider') |
| 229 | def prx01NodeProvider = _pillar['return'][0].values()[0] |
| 230 | |
| 231 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider') |
| 232 | def prx02NodeProvider = _pillar['return'][0].values()[0] |
| 233 | |
| 234 | |
| 235 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true) |
| 236 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true) |
| 237 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true) |
| 238 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true) |
| 239 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true) |
| 240 | |
| 241 | |
| 242 | try { |
| 243 | salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak") |
| 244 | } catch (Exception e) { |
| 245 | common.warningMsg('File already exists') |
| 246 | } |
| 247 | try { |
| 248 | salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak") |
| 249 | } catch (Exception e) { |
| 250 | common.warningMsg('File already exists') |
| 251 | } |
| 252 | try { |
| 253 | salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak") |
| 254 | } catch (Exception e) { |
| 255 | common.warningMsg('File already exists') |
| 256 | } |
| 257 | try { |
| 258 | salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak") |
| 259 | } catch (Exception e) { |
| 260 | common.warningMsg('File already exists') |
| 261 | } |
| 262 | try { |
| 263 | salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak") |
| 264 | } catch (Exception e) { |
| 265 | common.warningMsg('File already exists') |
| 266 | } |
| 267 | |
| 268 | |
| 269 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true) |
| 270 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true) |
| 271 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true) |
| 272 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true) |
| 273 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true) |
| 274 | |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 275 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'") |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 276 | |
| 277 | try { |
| 278 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y") |
| 279 | } catch (Exception e) { |
| 280 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 281 | } |
| 282 | |
| 283 | // salt 'kvm*' state.sls salt.control |
| 284 | salt.enforceState(saltMaster, 'I@salt:control', 'salt.control') |
| 285 | |
Jiri Broulik | 9b73d6c | 2017-06-02 12:27:05 +0200 | [diff] [blame] | 286 | sleep(70) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 287 | |
| 288 | // salt '*' saltutil.refresh_pillar |
| 289 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 290 | // salt '*' saltutil.sync_all |
| 291 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true) |
| 292 | |
| 293 | try { |
| 294 | salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 295 | } catch (Exception e) { |
| 296 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 297 | } |
| 298 | salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 299 | |
| 300 | // salt 'ctl*' state.sls keepalived |
| 301 | // salt 'ctl*' state.sls haproxy |
| 302 | salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy']) |
| 303 | // salt 'ctl*' service.restart rsyslog |
| 304 | salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true) |
| 305 | // salt "ctl*" state.sls memcached |
| 306 | // salt "ctl*" state.sls keystone.server |
| 307 | try { |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 308 | try { |
| 309 | salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server']) |
| 310 | } catch (Exception e) { |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 311 | common.warningMsg('Restarting Apache2 and enforcing keystone.server state again') |
Jiri Broulik | 5a13a65 | 2017-05-18 14:33:32 +0200 | [diff] [blame] | 312 | salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['apache2'], null, true) |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 313 | salt.enforceState(saltMaster, 'ctl*', 'keystone.server') |
| 314 | } |
| 315 | // salt 'ctl01*' state.sls keystone.client |
| 316 | try { |
| 317 | salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client') |
| 318 | } catch (Exception e) { |
| 319 | common.warningMsg('running keystone.client state again') |
| 320 | salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client') |
| 321 | } |
| 322 | try { |
| 323 | salt.enforceState(saltMaster, 'ctl*', 'glance') |
| 324 | } catch (Exception e) { |
| 325 | common.warningMsg('running glance state again') |
| 326 | salt.enforceState(saltMaster, 'ctl*', 'glance') |
| 327 | } // salt 'ctl*' state.sls glusterfs.client |
| 328 | salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client') |
| 329 | // salt 'ctl*' state.sls keystone.server |
| 330 | salt.enforceState(saltMaster, 'ctl*', 'keystone.server') |
| 331 | // salt 'ctl*' state.sls nova |
| 332 | try { |
| 333 | salt.enforceState(saltMaster, 'ctl*', 'nova') |
| 334 | } catch (Exception e) { |
| 335 | common.warningMsg('running nova state again') |
| 336 | salt.enforceState(saltMaster, 'ctl*', 'nova') |
| 337 | } |
| 338 | // salt 'ctl*' state.sls cinder |
| 339 | try { |
| 340 | salt.enforceState(saltMaster, 'ctl*', 'cinder') |
| 341 | } catch (Exception e) { |
| 342 | common.warningMsg('running cinder state again') |
| 343 | salt.enforceState(saltMaster, 'ctl*', 'cinder') |
| 344 | } |
| 345 | try { |
| 346 | salt.enforceState(saltMaster, 'ctl*', 'neutron') |
| 347 | } catch (Exception e) { |
| 348 | common.warningMsg('running neutron state again') |
| 349 | salt.enforceState(saltMaster, 'ctl*', 'neutron') |
| 350 | } |
| 351 | // salt 'ctl*' state.sls heat |
| 352 | try { |
| 353 | salt.enforceState(saltMaster, 'ctl*', 'heat') |
| 354 | } catch (Exception e) { |
| 355 | common.warningMsg('running heat state again') |
| 356 | salt.enforceState(saltMaster, 'ctl*', 'heat') |
| 357 | } |
| 358 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 359 | } catch (Exception e) { |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 360 | errorOccured = true |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 361 | common.warningMsg('Some states that require syncdb failed. Restoring production databases') |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 362 | |
| 363 | // database restore section |
| 364 | try { |
| 365 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
| 366 | } catch (Exception er) { |
| 367 | common.warningMsg('Mysql service already stopped') |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 368 | } |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 369 | try { |
| 370 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
| 371 | } catch (Exception er) { |
| 372 | common.warningMsg('Mysql service already stopped') |
| 373 | } |
| 374 | try { |
| 375 | salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
| 376 | } catch (Exception er) { |
| 377 | common.warningMsg('Files are not present') |
| 378 | } |
| 379 | try { |
| 380 | salt.cmdRun(saltMaster, 'I@galera:master', "mkdir /root/mysql/mysql.bak") |
| 381 | } catch (Exception er) { |
| 382 | common.warningMsg('Directory already exists') |
| 383 | } |
| 384 | try { |
| 385 | salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*") |
| 386 | } catch (Exception er) { |
| 387 | common.warningMsg('Directory already empty') |
| 388 | } |
| 389 | try { |
| 390 | salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak") |
| 391 | } catch (Exception er) { |
| 392 | common.warningMsg('Files were already moved') |
| 393 | } |
| 394 | try { |
| 395 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true) |
| 396 | } catch (Exception er) { |
| 397 | common.warningMsg('File is not present') |
| 398 | } |
| 399 | salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf") |
| 400 | _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir') |
| 401 | backup_dir = _pillar['return'][0].values()[0] |
| 402 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' } |
| 403 | print(backup_dir) |
| 404 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 405 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 406 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true) |
| 407 | sleep(5) |
| 408 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
| 409 | // |
| 410 | |
Jiri Broulik | 5a13a65 | 2017-05-18 14:33:32 +0200 | [diff] [blame] | 411 | common.errorMsg("Stage Real control upgrade failed") |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 412 | } |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 413 | if(!errorOccured){ |
| 414 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
| 415 | salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 416 | |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 417 | // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 418 | // salt 'ctl*' state.sls keepalived |
| 419 | // salt 'prx*' state.sls keepalived |
| 420 | salt.enforceState(saltMaster, 'prx*', 'keepalived') |
| 421 | // salt 'prx*' state.sls horizon |
| 422 | salt.enforceState(saltMaster, 'prx*', 'horizon') |
| 423 | // salt 'prx*' state.sls nginx |
| 424 | salt.enforceState(saltMaster, 'prx*', 'nginx') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 425 | |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 426 | salt.cmdRun(saltMaster, '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') |
| 427 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 428 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 429 | |
Jiri Broulik | 08229c8 | 2017-05-22 23:35:32 +0200 | [diff] [blame] | 430 | if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) { |
| 431 | stage('Ask for manual confirmation') { |
| 432 | 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?" |
| 433 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
| 437 | if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) { |
| 438 | stage('Rollback upgrade') { |
| 439 | |
Jiri Broulik | 08229c8 | 2017-05-22 23:35:32 +0200 | [diff] [blame] | 440 | stage('Ask for manual confirmation') { |
| 441 | input message: "Do you really want to continue with the rollback?" |
| 442 | } |
| 443 | |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 444 | _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 445 | domain = _pillar['return'][0].values()[0].values()[0] |
| 446 | print(_pillar) |
| 447 | print(domain) |
| 448 | |
Jiri Broulik | d98364e | 2017-05-18 15:30:04 +0200 | [diff] [blame] | 449 | _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id') |
| 450 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
Jiri Broulik | d98364e | 2017-05-18 15:30:04 +0200 | [diff] [blame] | 451 | print(_pillar) |
| 452 | print(kvm01) |
Jiri Broulik | d98364e | 2017-05-18 15:30:04 +0200 | [diff] [blame] | 453 | |
| 454 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider') |
| 455 | def ctl01NodeProvider = _pillar['return'][0].values()[0] |
| 456 | |
| 457 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider') |
| 458 | def ctl02NodeProvider = _pillar['return'][0].values()[0] |
| 459 | |
| 460 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider') |
| 461 | def ctl03NodeProvider = _pillar['return'][0].values()[0] |
| 462 | |
| 463 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider') |
| 464 | def prx01NodeProvider = _pillar['return'][0].values()[0] |
| 465 | |
| 466 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider') |
| 467 | def prx02NodeProvider = _pillar['return'][0].values()[0] |
| 468 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 469 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true) |
| 470 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true) |
| 471 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true) |
| 472 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true) |
| 473 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true) |
| 474 | |
| 475 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true) |
| 476 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true) |
| 477 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true) |
| 478 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true) |
| 479 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true) |
| 480 | |
| 481 | try { |
| 482 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y") |
| 483 | } catch (Exception e) { |
| 484 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 485 | } |
| 486 | |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 487 | // database restore section |
| 488 | try { |
| 489 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
| 490 | } catch (Exception e) { |
| 491 | common.warningMsg('Mysql service already stopped') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 492 | } |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 493 | try { |
| 494 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
| 495 | } catch (Exception e) { |
| 496 | common.warningMsg('Mysql service already stopped') |
| 497 | } |
| 498 | try { |
| 499 | salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
| 500 | } catch (Exception e) { |
| 501 | common.warningMsg('Files are not present') |
| 502 | } |
| 503 | try { |
| 504 | salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*") |
| 505 | } catch (Exception e) { |
| 506 | common.warningMsg('Directory already empty') |
| 507 | } |
| 508 | try { |
| 509 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true) |
| 510 | } catch (Exception e) { |
| 511 | common.warningMsg('File is not present') |
| 512 | } |
| 513 | salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf") |
| 514 | _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir') |
| 515 | backup_dir = _pillar['return'][0].values()[0] |
| 516 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' } |
| 517 | print(backup_dir) |
| 518 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 519 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 520 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true) |
| 521 | sleep(5) |
| 522 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
| 523 | // |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 524 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 525 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true) |
| 526 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true) |
| 527 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true) |
| 528 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true) |
| 529 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true) |
| 530 | |
| 531 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
| 532 | salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true) |
| 533 | |
Jiri Broulik | 9b73d6c | 2017-06-02 12:27:05 +0200 | [diff] [blame] | 534 | sleep(70) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 535 | |
| 536 | salt.cmdRun(saltMaster, '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') |
| 537 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 538 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 539 | } |
| 540 | } |