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() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 15 | def python = new com.mirantis.mk.Python() |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 16 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 17 | def pepperEnv = "pepperEnv" |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 18 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 19 | node() { |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 20 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 21 | stage('Setup virtualenv for Pepper') { |
Dmitrii Kabanov | f31c896 | 2017-10-12 21:00:30 -0700 | [diff] [blame] | 22 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 23 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 24 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 25 | if (STAGE_TEST_UPGRADE.toBoolean() == true) { |
| 26 | stage('Test upgrade') { |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 27 | |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 28 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 29 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 30 | salt.enforceState(pepperEnv, 'I@salt:master', 'reclass') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 31 | } 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 Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 34 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 35 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 36 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 37 | } catch (Exception e) { |
| 38 | common.warningMsg("No response from some minions. We should continue to run") |
| 39 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 40 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 41 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 42 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 43 | } catch (Exception e) { |
| 44 | common.warningMsg("No response from some minions. We should continue to run") |
| 45 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 46 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 47 | def _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 48 | def domain = _pillar['return'][0].values()[0].values()[0] |
| 49 | print(_pillar) |
| 50 | print(domain) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 51 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 52 | // read backupninja variable |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 53 | _pillar = salt.getPillar(pepperEnv, 'I@backupninja:client', '_param:backupninja_backup_host') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 54 | def backupninja_backup_host = _pillar['return'][0].values()[0] |
| 55 | print(_pillar) |
| 56 | print(backupninja_backup_host) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 57 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 58 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 59 | def kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 60 | print(_pillar) |
| 61 | print(kvm01) |
| 62 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 63 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 64 | def upgNodeProvider = _pillar['return'][0].values()[0] |
| 65 | print(_pillar) |
| 66 | print(upgNodeProvider) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 67 | |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 68 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 69 | salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true) |
| 70 | salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 71 | |
| 72 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 73 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 74 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d upg01.${domain} -y") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 75 | } 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 Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 78 | |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 79 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 80 | // salt 'kvm02*' state.sls salt.control |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 81 | salt.enforceState(pepperEnv, "${upgNodeProvider}", 'salt.control') |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 82 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 83 | // wait until upg node is registered in salt-key |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 84 | salt.minionPresent(pepperEnv, 'I@salt:master', 'upg01') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 85 | |
| 86 | // salt '*' saltutil.refresh_pillar |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 87 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.refresh_pillar', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 88 | // salt '*' saltutil.sync_all |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 89 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.sync_all', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 90 | |
| 91 | // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog |
| 92 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 93 | salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 94 | } catch (Exception e) { |
| 95 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 96 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 97 | salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 98 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 99 | // salt "upg*" state.sls rabbitmq |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 100 | salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 101 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 102 | salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 103 | } catch (Exception e) { |
| 104 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 105 | } |
| 106 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 107 | salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 108 | } catch (Exception e) { |
| 109 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 110 | } |
| 111 | // salt '*' state.apply salt.minion.grains |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 112 | //salt.enforceState(pepperEnv, '*', 'salt.minion.grains') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 113 | // salt -C 'I@backupninja:server' state.sls backupninja |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 114 | salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 115 | // salt -C 'I@backupninja:client' state.sls backupninja |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 116 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 118 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 119 | salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 120 | } catch (Exception e) { |
| 121 | common.warningMsg('The ARP entry does not exist. We should continue to run.') |
| 122 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 123 | 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 126 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 127 | 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 Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 131 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 132 | def databases = salt.cmdRun(pepperEnv, 'I@mysql:client','salt-call mysql.db_list | grep upgrade | awk \'/-/ {print \$2}\'') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 133 | 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')){ |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 137 | salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'mysql.db_remove', ["${databasesList[i]}"], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 138 | common.warningMsg("removing database ${databasesList[i]}") |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 139 | salt.runSaltProcessStep(pepperEnv, 'I@mysql:client', 'file.remove', ["/root/mysql/flags/${databasesList[i]}-installed"], null, true) |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 140 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 141 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 142 | salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 143 | }else{ |
| 144 | common.errorMsg("No _upgrade databases were returned") |
| 145 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 146 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 147 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 148 | salt.enforceState(pepperEnv, 'upg*', 'keystone.server') |
| 149 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 150 | } catch (Exception e) { |
| 151 | common.warningMsg('Restarting Apache2') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 152 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 153 | } |
| 154 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 155 | salt.enforceState(pepperEnv, 'upg*', 'keystone.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 156 | } catch (Exception e) { |
| 157 | common.warningMsg('running keystone.client state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 158 | salt.enforceState(pepperEnv, 'upg*', 'keystone.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 159 | } |
| 160 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 161 | salt.enforceState(pepperEnv, 'upg*', 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 162 | } catch (Exception e) { |
| 163 | common.warningMsg('running glance state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 164 | salt.enforceState(pepperEnv, 'upg*', 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 165 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 166 | salt.enforceState(pepperEnv, 'upg*', 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 167 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 168 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 169 | } catch (Exception e) { |
| 170 | common.warningMsg('running nova state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 171 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 172 | } |
| 173 | // run nova state again as sometimes nova does not enforce itself for some reason |
| 174 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 175 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 176 | } catch (Exception e) { |
| 177 | common.warningMsg('running nova state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 178 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 179 | } |
| 180 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 181 | salt.enforceState(pepperEnv, 'upg*', 'cinder') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 182 | } catch (Exception e) { |
| 183 | common.warningMsg('running cinder state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 184 | salt.enforceState(pepperEnv, 'upg*', 'cinder') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 185 | } |
| 186 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 187 | salt.enforceState(pepperEnv, 'upg*', 'neutron') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 188 | } catch (Exception e) { |
| 189 | common.warningMsg('running neutron state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 190 | salt.enforceState(pepperEnv, 'upg*', 'neutron') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 191 | } |
| 192 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 193 | salt.enforceState(pepperEnv, 'upg*', 'heat') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 194 | } catch (Exception e) { |
| 195 | common.warningMsg('running heat state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 196 | salt.enforceState(pepperEnv, 'upg*', 'heat') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 197 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 198 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 199 | |
| 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 Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 203 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 209 | stage('Real upgrade') { |
| 210 | // # actual upgrade |
| 211 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 212 | _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 213 | domain = _pillar['return'][0].values()[0].values()[0] |
| 214 | print(_pillar) |
| 215 | print(domain) |
| 216 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 217 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 218 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 219 | print(_pillar) |
| 220 | print(kvm01) |
| 221 | |
| 222 | def errorOccured = false |
| 223 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 224 | def proxy_general_target = "" |
| 225 | def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 226 | def node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 227 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 228 | for (t in proxy_target_hosts) { |
| 229 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 230 | proxy_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 231 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 232 | 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 Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 246 | node_count++ |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 247 | } |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 248 | def control_general_target = "" |
| 249 | def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 250 | node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 251 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 252 | for (t in control_target_hosts) { |
| 253 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 254 | control_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 255 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 256 | 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 Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 270 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 271 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 272 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 273 | salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c '/usr/local/bin/innobackupex-runner.sh'") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 274 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 275 | // salt 'kvm*' state.sls salt.control |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 276 | salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 277 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 278 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 288 | |
| 289 | // salt '*' saltutil.refresh_pillar |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 290 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 291 | // salt '*' saltutil.sync_all |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 292 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 293 | |
| 294 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 295 | salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 296 | } catch (Exception e) { |
| 297 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 298 | } |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 299 | salt.enforceState(pepperEnv, "${proxy_general_target}* or ${control_general_target}*", ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 300 | |
| 301 | // salt 'ctl*' state.sls keepalived |
| 302 | // salt 'ctl*' state.sls haproxy |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 303 | salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 304 | // salt 'ctl*' service.restart rsyslog |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 305 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 306 | // salt "ctl*" state.sls memcached |
| 307 | // salt "ctl*" state.sls keystone.server |
| 308 | try { |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 309 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 310 | salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server']) |
| 311 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 312 | } catch (Exception e) { |
| 313 | common.warningMsg('Restarting Apache2 and enforcing keystone.server state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 314 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true) |
| 315 | salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 316 | } |
| 317 | // salt 'ctl01*' state.sls keystone.client |
| 318 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 319 | salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client') |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 320 | } catch (Exception e) { |
| 321 | common.warningMsg('running keystone.client state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 322 | salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client') |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 323 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 324 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 325 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glance') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 326 | } catch (Exception e) { |
| 327 | common.warningMsg('running glance state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 328 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 329 | } // salt 'ctl*' state.sls glusterfs.client |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 330 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 331 | // salt 'ctl*' state.sls keystone.server |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 332 | salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 333 | // salt 'ctl*' state.sls nova |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 334 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 335 | salt.enforceState(pepperEnv, "${control_general_target}*", 'nova') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 336 | } catch (Exception e) { |
| 337 | common.warningMsg('running nova state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 338 | salt.enforceState(pepperEnv, "${control_general_target}*", 'nova') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 339 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 340 | // salt 'ctl*' state.sls cinder |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 341 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 342 | salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder') |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 343 | } catch (Exception e) { |
| 344 | common.warningMsg('running cinder state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 345 | salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 346 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 347 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 348 | salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 349 | } catch (Exception e) { |
| 350 | common.warningMsg('running neutron state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 351 | salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 352 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 353 | // salt 'ctl*' state.sls heat |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 354 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 355 | salt.enforceState(pepperEnv, "${control_general_target}*", 'heat') |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 356 | } catch (Exception e) { |
| 357 | common.warningMsg('running heat state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 358 | salt.enforceState(pepperEnv, "${control_general_target}*", 'heat') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 361 | } catch (Exception e) { |
| 362 | errorOccured = true |
| 363 | common.warningMsg('Some states that require syncdb failed. Restoring production databases') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 364 | |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 365 | // database restore section |
| 366 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 367 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 368 | } catch (Exception er) { |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 369 | common.warningMsg('Mysql service already stopped') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 370 | } |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 371 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 372 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 373 | } catch (Exception er) { |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 374 | common.warningMsg('Mysql service already stopped') |
| 375 | } |
| 376 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 377 | salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 378 | } catch (Exception er) { |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 379 | common.warningMsg('Files are not present') |
| 380 | } |
| 381 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 382 | salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir /root/mysql/mysql.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 383 | } catch (Exception er) { |
| 384 | common.warningMsg('Directory already exists') |
| 385 | } |
| 386 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 387 | salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /root/mysql/mysql.bak/*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 388 | } catch (Exception er) { |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 389 | common.warningMsg('Directory already empty') |
| 390 | } |
| 391 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 392 | salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 393 | } catch (Exception er) { |
| 394 | common.warningMsg('Files were already moved') |
| 395 | } |
| 396 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 397 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 398 | } catch (Exception er) { |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 399 | common.warningMsg('File is not present') |
| 400 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 401 | 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 Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 403 | 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) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 406 | 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 Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 409 | |
| 410 | // wait until mysql service on galera master is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 411 | salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running') |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 412 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 413 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
Jiri Broulik | 00d0109 | 2017-06-01 19:38:15 +0200 | [diff] [blame] | 414 | // |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 415 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 416 | common.errorMsg("Stage Real control upgrade failed") |
| 417 | } |
| 418 | if(!errorOccured){ |
| 419 | |
| 420 | ceph = null |
| 421 | |
| 422 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 423 | ceph = salt.cmdRun(pepperEnv, "${control_general_target}*", "salt-call grains.item roles | grep ceph.client") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 424 | |
| 425 | } catch (Exception er) { |
| 426 | common.infoMsg("Ceph is not used") |
| 427 | } |
| 428 | |
| 429 | if(ceph != null) { |
| 430 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 431 | salt.enforceState(pepperEnv, "${control_general_target}*", 'ceph.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 432 | } catch (Exception er) { |
| 433 | common.warningMsg("Ceph client state on controllers failed. Please fix it manually") |
| 434 | } |
| 435 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 436 | |
| 437 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 438 | 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 Broulik | f20c767 | 2017-06-19 21:20:52 +0200 | [diff] [blame] | 441 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 442 | |
| 443 | // salt 'prx*' state.sls linux,openssh,salt.minion,ntp,rsyslog |
| 444 | // salt 'ctl*' state.sls keepalived |
| 445 | // salt 'prx*' state.sls keepalived |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 446 | salt.enforceState(pepperEnv, "${proxy_general_target}*", 'keepalived') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 447 | // salt 'prx*' state.sls horizon |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 448 | salt.enforceState(pepperEnv, "${proxy_general_target}*", 'horizon') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 449 | // salt 'prx*' state.sls nginx |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 450 | salt.enforceState(pepperEnv, "${proxy_general_target}*", 'nginx') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 451 | // salt "prx*" state.sls memcached |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 452 | salt.enforceState(pepperEnv, "${proxy_general_target}*", 'memcached') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 453 | |
| 454 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 455 | salt.enforceHighstate(pepperEnv, "${control_general_target}*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 456 | } 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 Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 461 | salt.enforceHighstate(pepperEnv, "${proxy_general_target}*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 462 | } 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 Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 466 | 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 Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 467 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 468 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 469 | |
| 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 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 484 | _pillar = salt.getGrain(pepperEnv, 'I@salt:master', 'domain') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 485 | domain = _pillar['return'][0].values()[0].values()[0] |
| 486 | print(_pillar) |
| 487 | print(domain) |
| 488 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 489 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 490 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 491 | print(_pillar) |
| 492 | print(kvm01) |
| 493 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 494 | def proxy_general_target = "" |
| 495 | def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 496 | def node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 497 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 498 | for (t in proxy_target_hosts) { |
| 499 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 500 | proxy_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 501 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 502 | 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 Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 511 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 512 | } |
| 513 | def control_general_target = "" |
| 514 | def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 515 | node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 516 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 517 | for (t in control_target_hosts) { |
| 518 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 519 | control_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 520 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 521 | 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 Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 530 | node_count++ |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | // database restore section |
| 534 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 535 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 536 | } catch (Exception e) { |
| 537 | common.warningMsg('Mysql service already stopped') |
| 538 | } |
| 539 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 540 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 541 | } catch (Exception e) { |
| 542 | common.warningMsg('Mysql service already stopped') |
| 543 | } |
| 544 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 545 | salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 546 | } catch (Exception e) { |
| 547 | common.warningMsg('Files are not present') |
| 548 | } |
| 549 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 550 | salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 551 | } catch (Exception e) { |
| 552 | common.warningMsg('Directory already empty') |
| 553 | } |
| 554 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 555 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 556 | } catch (Exception e) { |
| 557 | common.warningMsg('File is not present') |
| 558 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 559 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 561 | 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) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 564 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 567 | |
| 568 | // wait until mysql service on galera master is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 569 | salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 570 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 571 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 572 | // |
| 573 | |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 574 | node_count = 1 |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 575 | for (t in control_target_hosts) { |
| 576 | def target = t.split("\\.")[0] |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 577 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:ctl0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 578 | def nodeProvider = _pillar['return'][0].values()[0] |
| 579 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true) |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 580 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 581 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 582 | node_count = 1 |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 583 | for (t in proxy_target_hosts) { |
| 584 | def target = t.split("\\.")[0] |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 585 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", "salt:control:cluster:internal:node:prx0${node_count}:provider") |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 586 | def nodeProvider = _pillar['return'][0].values()[0] |
| 587 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true) |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame^] | 588 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 589 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 590 | |
| 591 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 592 | salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 593 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 594 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 602 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 603 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 605 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 606 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 607 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 608 | } |
| 609 | } |