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 | |
| 29 | //salt.enforceState(saltMaster, 'I@salt:master', 'reclass') |
| 30 | |
| 31 | // salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 32 | // salt '*' saltutil.sync_all |
| 33 | // salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true) |
| 34 | |
| 35 | |
| 36 | def _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 37 | def domain = _pillar['return'][0].values()[0].values()[0] |
| 38 | print(_pillar) |
| 39 | print(domain) |
| 40 | |
| 41 | // read backupninja variable |
| 42 | _pillar = salt.getPillar(saltMaster, 'I@backupninja:client', '_param:backupninja_backup_host') |
| 43 | def backupninja_backup_host = _pillar['return'][0].values()[0] |
| 44 | print(_pillar) |
| 45 | print(backupninja_backup_host) |
| 46 | |
| 47 | _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id') |
| 48 | def kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 49 | def kvm03 = _pillar['return'][0].values()[2].values()[0] |
| 50 | def kvm02 = _pillar['return'][0].values()[1].values()[0] |
| 51 | print(_pillar) |
| 52 | print(kvm01) |
| 53 | print(kvm02) |
| 54 | print(kvm03) |
| 55 | |
| 56 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider') |
| 57 | def upgNodeProvider = _pillar['return'][0].values()[0] |
| 58 | print(_pillar) |
| 59 | print(upgNodeProvider) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 60 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 61 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 62 | salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true) |
| 63 | salt.runSaltProcessStep(saltMaster, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 64 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 65 | |
| 66 | try { |
Jiri Broulik | d6bc138 | 2017-05-17 18:46:27 +0200 | [diff] [blame] | 67 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d upg01.${domain} -y") |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 68 | } catch (Exception e) { |
Jiri Broulik | d6bc138 | 2017-05-17 18:46:27 +0200 | [diff] [blame] | 69 | 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] | 70 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 71 | |
| 72 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 73 | // salt 'kvm02*' state.sls salt.control |
| 74 | salt.enforceState(saltMaster, "${upgNodeProvider}", 'salt.control') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 75 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 76 | sleep(60) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 77 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 78 | // salt '*' saltutil.refresh_pillar |
| 79 | salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.refresh_pillar', [], null, true) |
| 80 | // salt '*' saltutil.sync_all |
| 81 | salt.runSaltProcessStep(saltMaster, 'upg*', 'saltutil.sync_all', [], null, true) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 82 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 83 | // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog |
| 84 | try { |
| 85 | salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 86 | } catch (Exception e) { |
| 87 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 88 | } |
| 89 | salt.enforceState(saltMaster, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
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 rabbitmq |
| 92 | salt.enforceState(saltMaster, 'upg*', ['rabbitmq', 'memcached']) |
| 93 | try { |
| 94 | salt.enforceState(saltMaster, 'I@backupninja:client', ['openssh.client', 'salt.minion']) |
| 95 | } catch (Exception e) { |
| 96 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 97 | } |
| 98 | try { |
| 99 | salt.enforceState(saltMaster, 'I@backupninja:server', ['salt.minion']) |
| 100 | } catch (Exception e) { |
| 101 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 102 | } |
| 103 | // salt '*' state.apply salt.minion.grains |
| 104 | //salt.enforceState(saltMaster, '*', 'salt.minion.grains') |
| 105 | // salt -C 'I@backupninja:server' state.sls backupninja |
| 106 | salt.enforceState(saltMaster, 'I@backupninja:server', 'backupninja') |
| 107 | // salt -C 'I@backupninja:client' state.sls backupninja |
| 108 | salt.enforceState(saltMaster, 'I@backupninja:client', 'backupninja') |
| 109 | salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.rm_known_host', ["root", "${backupninja_backup_host}"], null, true) |
| 110 | salt.cmdRun(saltMaster, 'I@backupninja:client', "arp -d ${backupninja_backup_host}") |
| 111 | salt.runSaltProcessStep(saltMaster, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true) |
| 112 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql') |
| 113 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync') |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 114 | |
| 115 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 116 | def databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'') |
| 117 | if(databases && databases != ""){ |
| 118 | def databasesList = databases['return'][0].values()[0].trim().tokenize("\n") |
| 119 | for( i = 0; i < databasesList.size(); i++){ |
| 120 | if(databasesList[i].toLowerCase().contains('upgrade')){ |
| 121 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true) |
| 122 | common.warningMsg("removing database ${databasesList[i]}") |
| 123 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true) |
| 124 | } |
| 125 | } |
| 126 | }else{ |
| 127 | common.errorMsg("No _upgrade databases were returned") |
| 128 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 129 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 130 | salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client') |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 131 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 132 | try { |
| 133 | salt.enforceState(saltMaster, 'upg*', 'keystone.server') |
| 134 | } catch (Exception e) { |
| 135 | salt.runSaltProcessStep(saltMaster, 'upg*', 'service.reload', ['apache2'], null, true) |
| 136 | common.warningMsg('reload of apache2. We should continue to run') |
| 137 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 138 | salt.enforceState(saltMaster, 'upg*', 'keystone.client') |
| 139 | try { |
| 140 | salt.enforceState(saltMaster, 'upg*', 'glance') |
| 141 | } catch (Exception e) { |
| 142 | common.warningMsg('running glance state again') |
| 143 | salt.enforceState(saltMaster, 'upg*', 'glance') |
| 144 | } |
| 145 | salt.enforceState(saltMaster, 'upg*', 'keystone.server') |
| 146 | try { |
| 147 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 148 | } catch (Exception e) { |
| 149 | common.warningMsg('running nova state again') |
| 150 | salt.enforceState(saltMaster, 'upg*', 'nova') |
| 151 | } |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame^] | 152 | try { |
| 153 | salt.enforceState(saltMaster, 'upg*', 'cinder') |
| 154 | } catch (Exception e) { |
| 155 | common.warningMsg('running cinder state again') |
| 156 | salt.enforceState(saltMaster, 'upg*', 'cinder') |
| 157 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 158 | try { |
| 159 | salt.enforceState(saltMaster, 'upg*', 'neutron') |
| 160 | } catch (Exception e) { |
| 161 | common.warningMsg('running neutron state again') |
| 162 | salt.enforceState(saltMaster, 'upg*', 'neutron') |
| 163 | } |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame^] | 164 | try { |
| 165 | salt.enforceState(saltMaster, 'upg*', 'heat') |
| 166 | } catch (Exception e) { |
| 167 | common.warningMsg('running heat state again') |
| 168 | salt.enforceState(saltMaster, 'upg*', 'heat') |
| 169 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 170 | 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') |
| 171 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 174 | if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 175 | stage('Ask for manual confirmation') { |
| 176 | input message: "Do you want to continue with upgrade?" |
| 177 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 180 | |
| 181 | if (STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 182 | stage('Real upgrade') { |
| 183 | // # actual upgrade |
| 184 | |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 185 | _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 186 | domain = _pillar['return'][0].values()[0].values()[0] |
| 187 | print(_pillar) |
| 188 | print(domain) |
| 189 | |
| 190 | _pillar = salt.getGrain(saltMaster, 'I@salt:control', 'id') |
| 191 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 192 | kvm03 = _pillar['return'][0].values()[2].values()[0] |
| 193 | kvm02 = _pillar['return'][0].values()[1].values()[0] |
| 194 | print(_pillar) |
| 195 | print(kvm01) |
| 196 | print(kvm02) |
| 197 | print(kvm03) |
| 198 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 199 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl01:provider') |
| 200 | def ctl01NodeProvider = _pillar['return'][0].values()[0] |
| 201 | |
| 202 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl02:provider') |
| 203 | def ctl02NodeProvider = _pillar['return'][0].values()[0] |
| 204 | |
| 205 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:ctl03:provider') |
| 206 | def ctl03NodeProvider = _pillar['return'][0].values()[0] |
| 207 | |
| 208 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx01:provider') |
| 209 | def prx01NodeProvider = _pillar['return'][0].values()[0] |
| 210 | |
| 211 | _pillar = salt.getPillar(saltMaster, "${kvm01}", 'salt:control:cluster:internal:node:prx02:provider') |
| 212 | def prx02NodeProvider = _pillar['return'][0].values()[0] |
| 213 | |
| 214 | |
| 215 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true) |
| 216 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true) |
| 217 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true) |
| 218 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true) |
| 219 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true) |
| 220 | |
| 221 | |
| 222 | try { |
| 223 | salt.cmdRun(saltMaster, "${prx01NodeProvider}", "[ ! -f /root/prx01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx01.${domain}/system.qcow2 ./prx01.${domain}.qcow2.bak") |
| 224 | } catch (Exception e) { |
| 225 | common.warningMsg('File already exists') |
| 226 | } |
| 227 | try { |
| 228 | salt.cmdRun(saltMaster, "${prx02NodeProvider}", "[ ! -f /root/prx02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/prx02.${domain}/system.qcow2 ./prx02.${domain}.qcow2.bak") |
| 229 | } catch (Exception e) { |
| 230 | common.warningMsg('File already exists') |
| 231 | } |
| 232 | try { |
| 233 | salt.cmdRun(saltMaster, "${ctl01NodeProvider}", "[ ! -f /root/ctl01.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl01.${domain}/system.qcow2 ./ctl01.${domain}.qcow2.bak") |
| 234 | } catch (Exception e) { |
| 235 | common.warningMsg('File already exists') |
| 236 | } |
| 237 | try { |
| 238 | salt.cmdRun(saltMaster, "${ctl02NodeProvider}", "[ ! -f /root/ctl02.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl02.${domain}/system.qcow2 ./ctl02.${domain}.qcow2.bak") |
| 239 | } catch (Exception e) { |
| 240 | common.warningMsg('File already exists') |
| 241 | } |
| 242 | try { |
| 243 | salt.cmdRun(saltMaster, "${ctl03NodeProvider}", "[ ! -f /root/ctl03.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/ctl03.${domain}/system.qcow2 ./ctl03.${domain}.qcow2.bak") |
| 244 | } catch (Exception e) { |
| 245 | common.warningMsg('File already exists') |
| 246 | } |
| 247 | |
| 248 | |
| 249 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.undefine', ["prx01.${domain}"], null, true) |
| 250 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.undefine', ["prx02.${domain}"], null, true) |
| 251 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.undefine', ["ctl01.${domain}"], null, true) |
| 252 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.undefine', ["ctl02.${domain}"], null, true) |
| 253 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.undefine', ["ctl03.${domain}"], null, true) |
| 254 | |
| 255 | |
| 256 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql') |
| 257 | salt.cmdRun(saltMaster, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/200.backup.rsync') |
| 258 | |
| 259 | |
| 260 | try { |
| 261 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y") |
| 262 | } catch (Exception e) { |
| 263 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 264 | } |
| 265 | |
| 266 | // salt 'kvm*' state.sls salt.control |
| 267 | salt.enforceState(saltMaster, 'I@salt:control', 'salt.control') |
| 268 | |
| 269 | sleep(60) |
| 270 | |
| 271 | // salt '*' saltutil.refresh_pillar |
| 272 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true) |
| 273 | // salt '*' saltutil.sync_all |
| 274 | salt.runSaltProcessStep(saltMaster, '*', 'saltutil.sync_all', [], null, true) |
| 275 | |
| 276 | try { |
| 277 | salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 278 | } catch (Exception e) { |
| 279 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 280 | } |
| 281 | salt.enforceState(saltMaster, 'ctl* or prx* or ctl*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
| 282 | |
| 283 | // salt 'ctl*' state.sls keepalived |
| 284 | // salt 'ctl*' state.sls haproxy |
| 285 | salt.enforceState(saltMaster, 'ctl*', ['keepalived', 'haproxy']) |
| 286 | // salt 'ctl*' service.restart rsyslog |
| 287 | salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.restart', ['rsyslog'], null, true) |
| 288 | // salt "ctl*" state.sls memcached |
| 289 | // salt "ctl*" state.sls keystone.server |
| 290 | try { |
| 291 | salt.enforceState(saltMaster, 'ctl*', ['memcached', 'keystone.server']) |
| 292 | } catch (Exception e) { |
| 293 | salt.runSaltProcessStep(saltMaster, 'ctl*', 'service.reload', ['apache2'], null, true) |
| 294 | common.warningMsg('reload of apache2. We should continue to run') |
| 295 | } |
| 296 | // salt 'ctl01*' state.sls keystone.client |
| 297 | salt.enforceState(saltMaster, 'I@keystone:client and ctl*', 'keystone.client') |
| 298 | // salt 'ctl*' state.sls glance |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 299 | try { |
| 300 | salt.enforceState(saltMaster, 'ctl*', 'glance') |
| 301 | } catch (Exception e) { |
| 302 | common.warningMsg('running glance state again') |
| 303 | salt.enforceState(saltMaster, 'ctl*', 'glance') |
| 304 | } // salt 'ctl*' state.sls glusterfs.client |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 305 | salt.enforceState(saltMaster, 'ctl*', 'glusterfs.client') |
| 306 | // salt 'ctl*' state.sls keystone.server |
| 307 | salt.enforceState(saltMaster, 'ctl*', 'keystone.server') |
| 308 | // salt 'ctl*' state.sls nova |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 309 | try { |
| 310 | salt.enforceState(saltMaster, 'ctl*', 'nova') |
| 311 | } catch (Exception e) { |
| 312 | common.warningMsg('running nova state again') |
| 313 | salt.enforceState(saltMaster, 'ctl*', 'nova') |
| 314 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 315 | // salt 'ctl*' state.sls cinder |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame^] | 316 | try { |
| 317 | salt.enforceState(saltMaster, 'ctl*', 'cinder') |
| 318 | } catch (Exception e) { |
| 319 | common.warningMsg('running cinder state again') |
| 320 | salt.enforceState(saltMaster, 'ctl*', 'cinder') |
| 321 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 322 | try { |
| 323 | salt.enforceState(saltMaster, 'ctl*', 'neutron') |
| 324 | } catch (Exception e) { |
| 325 | common.warningMsg('running neutron state again') |
| 326 | salt.enforceState(saltMaster, 'ctl*', 'neutron') |
| 327 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 328 | // salt 'ctl*' state.sls heat |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame^] | 329 | try { |
| 330 | salt.enforceState(saltMaster, 'ctl*', 'heat') |
| 331 | } catch (Exception e) { |
| 332 | common.warningMsg('running heat state again') |
| 333 | salt.enforceState(saltMaster, 'ctl*', 'heat') |
| 334 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 335 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
| 336 | salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true) |
| 337 | |
| 338 | // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog - TODO: proč? už to jednou projelo |
| 339 | // salt 'ctl*' state.sls keepalived |
| 340 | // salt 'prx*' state.sls keepalived |
| 341 | salt.enforceState(saltMaster, 'prx*', 'keepalived') |
| 342 | // salt 'prx*' state.sls horizon |
| 343 | salt.enforceState(saltMaster, 'prx*', 'horizon') |
| 344 | // salt 'prx*' state.sls nginx |
| 345 | salt.enforceState(saltMaster, 'prx*', 'nginx') |
| 346 | |
| 347 | 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') |
| 348 | } |
| 349 | |
| 350 | } |
| 351 | |
| 352 | |
| 353 | if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) { |
| 354 | stage('Ask for manual confirmation') { |
| 355 | input message: "Please verify that 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?" |
| 356 | } |
| 357 | stage('Ask for manual confirmation') { |
| 358 | input message: "Do you really want to continue with the rollback?" |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) { |
| 363 | stage('Rollback upgrade') { |
| 364 | |
Jiri Broulik | e2f1e4a | 2017-05-17 23:59:52 +0200 | [diff] [blame] | 365 | _pillar = salt.getGrain(saltMaster, 'I@salt:master', 'domain') |
| 366 | domain = _pillar['return'][0].values()[0].values()[0] |
| 367 | print(_pillar) |
| 368 | print(domain) |
| 369 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 370 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.destroy', ["prx01.${domain}"], null, true) |
| 371 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.destroy', ["prx02.${domain}"], null, true) |
| 372 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.destroy', ["ctl01.${domain}"], null, true) |
| 373 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.destroy', ["ctl02.${domain}"], null, true) |
| 374 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.destroy', ["ctl03.${domain}"], null, true) |
| 375 | |
| 376 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'file.copy', ["/root/prx01.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx01.${domain}/system.qcow2"], null, true) |
| 377 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'file.copy', ["/root/prx02.${domain}.qcow2.bak", "/var/lib/libvirt/images/prx02.${domain}/system.qcow2"], null, true) |
| 378 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'file.copy', ["/root/ctl01.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl01.${domain}/system.qcow2"], null, true) |
| 379 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'file.copy', ["/root/ctl02.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl02.${domain}/system.qcow2"], null, true) |
| 380 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'file.copy', ["/root/ctl03.${domain}.qcow2.bak", "/var/lib/libvirt/images/ctl03.${domain}/system.qcow2"], null, true) |
| 381 | |
| 382 | try { |
| 383 | salt.cmdRun(saltMaster, 'I@salt:master', "salt-key -d ctl01.${domain},ctl02.${domain},ctl03.${domain},prx01.${domain},prx02.${domain} -y") |
| 384 | } catch (Exception e) { |
| 385 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 386 | } |
| 387 | |
| 388 | databases = salt.cmdRun(saltMaster, 'I@mysql:client','salt-call mysql.db_list | grep -v \'upgrade\' | grep -v \'schema\' | awk \'/-/ {print \$2}\'') |
| 389 | if(databases && databases != ""){ |
| 390 | databasesList = databases['return'][0].values()[0].trim().tokenize("\n") |
| 391 | for( i = 0; i < databasesList.size(); i++){ |
| 392 | if(!databasesList[i].toLowerCase().contains('upgrade') && !databasesList[i].toLowerCase().contains('command execution')){ |
| 393 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true) |
| 394 | common.warningMsg("removing database ${databasesList[i]}") |
| 395 | salt.runSaltProcessStep(saltMaster, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true) |
| 396 | } |
| 397 | } |
| 398 | }else{ |
| 399 | common.errorMsg("No none _upgrade databases were returned") |
| 400 | } |
| 401 | |
| 402 | salt.enforceState(saltMaster, 'I@mysql:client', 'mysql.client') |
| 403 | |
| 404 | salt.runSaltProcessStep(saltMaster, "${prx01NodeProvider}", 'virt.start', ["prx01.${domain}"], null, true) |
| 405 | salt.runSaltProcessStep(saltMaster, "${prx02NodeProvider}", 'virt.start', ["prx02.${domain}"], null, true) |
| 406 | salt.runSaltProcessStep(saltMaster, "${ctl01NodeProvider}", 'virt.start', ["ctl01.${domain}"], null, true) |
| 407 | salt.runSaltProcessStep(saltMaster, "${ctl02NodeProvider}", 'virt.start', ["ctl02.${domain}"], null, true) |
| 408 | salt.runSaltProcessStep(saltMaster, "${ctl03NodeProvider}", 'virt.start', ["ctl03.${domain}"], null, true) |
| 409 | |
| 410 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
| 411 | salt.runSaltProcessStep(saltMaster, 'cmp*', 'service.restart', ['nova-compute'], null, true) |
| 412 | |
| 413 | sleep(60) |
| 414 | |
| 415 | 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') |
| 416 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 417 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 418 | } |
| 419 | } |