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 | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 10 | * SKIP_VM_RELAUNCH Set to true if vms should not be recreated |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 11 | * |
| 12 | **/ |
| 13 | |
| 14 | def common = new com.mirantis.mk.Common() |
| 15 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 16 | def python = new com.mirantis.mk.Python() |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 17 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 18 | def pepperEnv = "pepperEnv" |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 19 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 20 | node() { |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 21 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 22 | stage('Setup virtualenv for Pepper') { |
Dmitrii Kabanov | f31c896 | 2017-10-12 21:00:30 -0700 | [diff] [blame] | 23 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 24 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 25 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 26 | if (STAGE_TEST_UPGRADE.toBoolean() == true) { |
| 27 | stage('Test upgrade') { |
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 | |
Jiri Broulik | 0798e51 | 2017-11-13 17:00:58 +0100 | [diff] [blame] | 47 | def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain') |
| 48 | domain = domain['return'][0].values()[0] |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 49 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 50 | // read backupninja variable |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 51 | _pillar = salt.getPillar(pepperEnv, 'I@backupninja:client', '_param:backupninja_backup_host') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 52 | def backupninja_backup_host = _pillar['return'][0].values()[0] |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 53 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 54 | if (SKIP_VM_RELAUNCH.toBoolean() == false) { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 55 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 56 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
| 57 | def kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 58 | print(_pillar) |
| 59 | print(kvm01) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 60 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 61 | _pillar = salt.getPillar(pepperEnv, "${kvm01}", 'salt:control:cluster:internal:node:upg01:provider') |
| 62 | def upgNodeProvider = _pillar['return'][0].values()[0] |
| 63 | print(_pillar) |
| 64 | print(upgNodeProvider) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 65 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 66 | salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.destroy', ["upg01.${domain}"], null, true) |
| 67 | salt.runSaltProcessStep(pepperEnv, "${upgNodeProvider}", 'virt.undefine', ["upg01.${domain}"], null, true) |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 68 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 69 | try { |
| 70 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d upg01.${domain} -y") |
| 71 | } catch (Exception e) { |
| 72 | 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") |
| 73 | } |
Jiri Broulik | 6fc9d3f | 2017-05-12 07:11:29 +0200 | [diff] [blame] | 74 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 75 | // salt 'kvm02*' state.sls salt.control |
| 76 | salt.enforceState(pepperEnv, "${upgNodeProvider}", 'salt.control') |
| 77 | // wait until upg node is registered in salt-key |
| 78 | salt.minionPresent(pepperEnv, 'I@salt:master', 'upg01') |
| 79 | // salt '*' saltutil.refresh_pillar |
| 80 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.refresh_pillar', [], null, true) |
| 81 | // salt '*' saltutil.sync_all |
| 82 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'saltutil.sync_all', [], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 83 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 84 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 85 | // salt "upg*" state.sls linux,openssh,salt.minion,ntp,rsyslog |
| 86 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 87 | salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 88 | } catch (Exception e) { |
| 89 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 90 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 91 | salt.enforceState(pepperEnv, 'upg*', ['linux', 'openssh', 'salt.minion', 'ntp', 'rsyslog']) |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 92 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 93 | // salt "upg*" state.sls rabbitmq |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 94 | salt.enforceState(pepperEnv, 'upg*', ['rabbitmq', 'memcached']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 95 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 96 | salt.enforceState(pepperEnv, 'I@backupninja:client', ['openssh.client', 'salt.minion']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 97 | } catch (Exception e) { |
| 98 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 99 | } |
| 100 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 101 | salt.enforceState(pepperEnv, 'I@backupninja:server', ['salt.minion']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 102 | } catch (Exception e) { |
| 103 | common.warningMsg('salt-minion was restarted. We should continue to run') |
| 104 | } |
| 105 | // salt '*' state.apply salt.minion.grains |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 106 | //salt.enforceState(pepperEnv, '*', 'salt.minion.grains') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 107 | // salt -C 'I@backupninja:server' state.sls backupninja |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 108 | salt.enforceState(pepperEnv, 'I@backupninja:server', 'backupninja') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 109 | // salt -C 'I@backupninja:client' state.sls backupninja |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 110 | salt.enforceState(pepperEnv, 'I@backupninja:client', 'backupninja') |
| 111 | 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] | 112 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 113 | salt.cmdRun(pepperEnv, 'I@backupninja:client', "arp -d ${backupninja_backup_host}") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 114 | } catch (Exception e) { |
| 115 | common.warningMsg('The ARP entry does not exist. We should continue to run.') |
| 116 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 117 | salt.runSaltProcessStep(pepperEnv, 'I@backupninja:client', 'ssh.set_known_host', ["root", "${backupninja_backup_host}"], null, true) |
| 118 | salt.cmdRun(pepperEnv, 'I@backupninja:client', 'backupninja -n --run /etc/backup.d/101.mysql') |
| 119 | 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] | 120 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 121 | salt.enforceState(pepperEnv, 'I@xtrabackup:server', 'xtrabackup') |
| 122 | salt.enforceState(pepperEnv, 'I@xtrabackup:client', 'openssh.client') |
| 123 | salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 124 | 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] | 125 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 126 | 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] | 127 | if(databases && databases != ""){ |
| 128 | def databasesList = databases['return'][0].values()[0].trim().tokenize("\n") |
| 129 | for( i = 0; i < databasesList.size(); i++){ |
| 130 | if(databasesList[i].toLowerCase().contains('upgrade')){ |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 131 | 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] | 132 | common.warningMsg("removing database ${databasesList[i]}") |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 133 | 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] | 134 | } |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 135 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 136 | salt.enforceState(pepperEnv, 'I@mysql:client', 'mysql.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 137 | }else{ |
| 138 | common.errorMsg("No _upgrade databases were returned") |
| 139 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 140 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 141 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 142 | salt.enforceState(pepperEnv, 'upg*', 'keystone.server') |
| 143 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 144 | } catch (Exception e) { |
| 145 | common.warningMsg('Restarting Apache2') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 146 | salt.runSaltProcessStep(pepperEnv, 'upg*', 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 147 | } |
| 148 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 149 | salt.enforceState(pepperEnv, 'upg*', 'keystone.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 150 | } catch (Exception e) { |
| 151 | common.warningMsg('running keystone.client state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 152 | salt.enforceState(pepperEnv, 'upg*', 'keystone.client') |
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*', 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 156 | } catch (Exception e) { |
| 157 | common.warningMsg('running glance state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 158 | salt.enforceState(pepperEnv, 'upg*', 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 159 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 160 | salt.enforceState(pepperEnv, 'upg*', 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 161 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 162 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 163 | } catch (Exception e) { |
| 164 | common.warningMsg('running nova state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 165 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 166 | } |
| 167 | // run nova state again as sometimes nova does not enforce itself for some reason |
| 168 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 169 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 170 | } catch (Exception e) { |
| 171 | common.warningMsg('running nova state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 172 | salt.enforceState(pepperEnv, 'upg*', 'nova') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 173 | } |
| 174 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 175 | salt.enforceState(pepperEnv, 'upg*', 'cinder') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 176 | } catch (Exception e) { |
| 177 | common.warningMsg('running cinder state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 178 | salt.enforceState(pepperEnv, 'upg*', 'cinder') |
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*', 'neutron') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 182 | } catch (Exception e) { |
| 183 | common.warningMsg('running neutron state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 184 | salt.enforceState(pepperEnv, 'upg*', 'neutron') |
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*', 'heat') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 188 | } catch (Exception e) { |
| 189 | common.warningMsg('running heat state again') |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 190 | salt.enforceState(pepperEnv, 'upg*', 'heat') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 191 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 192 | 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] | 193 | |
| 194 | if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 195 | stage('Ask for manual confirmation') { |
| 196 | input message: "Do you want to continue with upgrade?" |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 197 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (STAGE_REAL_UPGRADE.toBoolean() == true) { |
| 203 | stage('Real upgrade') { |
| 204 | // # actual upgrade |
| 205 | |
Jiri Broulik | 0798e51 | 2017-11-13 17:00:58 +0100 | [diff] [blame] | 206 | def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain') |
| 207 | domain = domain['return'][0].values()[0] |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 208 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 209 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 210 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 211 | print(_pillar) |
| 212 | print(kvm01) |
| 213 | |
| 214 | def errorOccured = false |
| 215 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 216 | def proxy_general_target = "" |
Marek Celoud | ead57b9 | 2017-11-13 16:41:12 +0100 | [diff] [blame] | 217 | def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server').sort() |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 218 | def node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 219 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 220 | for (t in proxy_target_hosts) { |
| 221 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 222 | proxy_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 223 | if (SKIP_VM_RELAUNCH.toBoolean() == true) { |
| 224 | break |
| 225 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 226 | _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] | 227 | def nodeProvider = _pillar['return'][0].values()[0] |
| 228 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true) |
| 229 | sleep(2) |
| 230 | try { |
| 231 | salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak") |
| 232 | } catch (Exception e) { |
| 233 | common.warningMsg('File already exists') |
| 234 | } |
| 235 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true) |
| 236 | try { |
| 237 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y") |
| 238 | } catch (Exception e) { |
| 239 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 240 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 241 | node_count++ |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 242 | } |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 243 | def control_general_target = "" |
Marek Celoud | 8c34fc5 | 2017-11-13 16:46:09 +0100 | [diff] [blame] | 244 | def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server and not upg*') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 245 | node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 246 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 247 | for (t in control_target_hosts) { |
| 248 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 249 | control_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 250 | if (SKIP_VM_RELAUNCH.toBoolean() == true) { |
| 251 | break |
| 252 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 253 | _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] | 254 | def nodeProvider = _pillar['return'][0].values()[0] |
| 255 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true) |
| 256 | sleep(2) |
| 257 | try { |
| 258 | salt.cmdRun(pepperEnv, "${nodeProvider}", "[ ! -f /root/${target}.${domain}.qcow2.bak ] && cp /var/lib/libvirt/images/${target}.${domain}/system.qcow2 ./${target}.${domain}.qcow2.bak") |
| 259 | } catch (Exception e) { |
| 260 | common.warningMsg('File already exists') |
| 261 | } |
| 262 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.undefine', ["${target}.${domain}"], null, true) |
| 263 | try { |
| 264 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y") |
| 265 | } catch (Exception e) { |
| 266 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 267 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 268 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 269 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 270 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 271 | if (SKIP_VM_RELAUNCH.toBoolean() == false) { |
| 272 | 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] | 273 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 274 | // salt 'kvm*' state.sls salt.control |
| 275 | salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 276 | |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 277 | for (t in control_target_hosts) { |
| 278 | def target = t.split("\\.")[0] |
| 279 | // wait until ctl and prx nodes are registered in salt-key |
| 280 | salt.minionPresent(pepperEnv, 'I@salt:master', "${target}") |
| 281 | } |
| 282 | for (t in proxy_target_hosts) { |
| 283 | def target = t.split("\\.")[0] |
| 284 | // wait until ctl and prx nodes are registered in salt-key |
| 285 | salt.minionPresent(pepperEnv, 'I@salt:master', "${target}") |
| 286 | } |
| 287 | |
| 288 | // salt '*' saltutil.refresh_pillar |
| 289 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.refresh_pillar', [], null, true) |
| 290 | // salt '*' saltutil.sync_all |
| 291 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 292 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 293 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 294 | 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] | 295 | } catch (Exception e) { |
| 296 | common.warningMsg('Received no response because salt-minion was restarted. We should continue to run') |
| 297 | } |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 298 | 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] | 299 | |
| 300 | // salt 'ctl*' state.sls keepalived |
| 301 | // salt 'ctl*' state.sls haproxy |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 302 | salt.enforceState(pepperEnv, "${control_general_target}*", ['keepalived', 'haproxy']) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 303 | // salt 'ctl*' service.restart rsyslog |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 304 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['rsyslog'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 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 { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 309 | salt.enforceState(pepperEnv, "${control_general_target}*", ['memcached', 'keystone.server']) |
| 310 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 311 | } catch (Exception e) { |
| 312 | common.warningMsg('Restarting Apache2 and enforcing keystone.server state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 313 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['apache2'], null, true) |
| 314 | salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 315 | } |
| 316 | // salt 'ctl01*' state.sls keystone.client |
| 317 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 318 | salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client') |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 319 | } catch (Exception e) { |
| 320 | common.warningMsg('running keystone.client state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 321 | salt.enforceState(pepperEnv, "I@keystone:client and ${control_general_target}*", 'keystone.client') |
Jiri Broulik | 69de13a | 2017-05-18 13:53:58 +0200 | [diff] [blame] | 322 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 323 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 324 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glance') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 325 | } catch (Exception e) { |
| 326 | common.warningMsg('running glance state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 327 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glance') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 328 | } // salt 'ctl*' state.sls glusterfs.client |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 329 | salt.enforceState(pepperEnv, "${control_general_target}*", 'glusterfs.client') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 330 | // salt 'ctl*' state.sls keystone.server |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 331 | salt.enforceState(pepperEnv, "${control_general_target}*", 'keystone.server') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 332 | // salt 'ctl*' state.sls nova |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 333 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 334 | salt.enforceState(pepperEnv, "${control_general_target}*", 'nova') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 335 | } catch (Exception e) { |
| 336 | common.warningMsg('running nova state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 337 | salt.enforceState(pepperEnv, "${control_general_target}*", 'nova') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 338 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 339 | // salt 'ctl*' state.sls cinder |
Jiri Broulik | 80d9675 | 2017-05-22 19:42:01 +0200 | [diff] [blame] | 340 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 341 | salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder') |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 342 | } catch (Exception e) { |
| 343 | common.warningMsg('running cinder state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 344 | salt.enforceState(pepperEnv, "${control_general_target}*", 'cinder') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 345 | } |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 346 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 347 | salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 348 | } catch (Exception e) { |
| 349 | common.warningMsg('running neutron state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 350 | salt.enforceState(pepperEnv, "${control_general_target}*", 'neutron') |
Jiri Broulik | 5f83c29 | 2017-05-18 12:09:07 +0200 | [diff] [blame] | 351 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 352 | // salt 'ctl*' state.sls heat |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 353 | try { |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 354 | salt.enforceState(pepperEnv, "${control_general_target}*", 'heat') |
Jiri Broulik | bda0a21 | 2017-05-18 12:54:51 +0200 | [diff] [blame] | 355 | } catch (Exception e) { |
| 356 | common.warningMsg('running heat state again') |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 357 | salt.enforceState(pepperEnv, "${control_general_target}*", 'heat') |
Jiri Broulik | 3792c96 | 2017-05-17 18:26:36 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 360 | } catch (Exception e) { |
| 361 | errorOccured = true |
Jiri Broulik | 0798e51 | 2017-11-13 17:00:58 +0100 | [diff] [blame] | 362 | input message: "Some states that require syncdb failed. Please check the reason and click proceed only if you want to restore database into it's pre-upgrade state. Otherwise, click abort." |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 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 | |
Jiri Broulik | 0798e51 | 2017-11-13 17:00:58 +0100 | [diff] [blame] | 484 | def domain = salt.getPillar(pepperEnv, 'I@salt:master', '_param:cluster_domain') |
| 485 | domain = domain['return'][0].values()[0] |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 486 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 487 | _pillar = salt.getGrain(pepperEnv, 'I@salt:control', 'id') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 488 | kvm01 = _pillar['return'][0].values()[0].values()[0] |
| 489 | print(_pillar) |
| 490 | print(kvm01) |
| 491 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 492 | def proxy_general_target = "" |
| 493 | def proxy_target_hosts = salt.getMinions(pepperEnv, 'I@horizon:server') |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 494 | def node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 495 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 496 | for (t in proxy_target_hosts) { |
| 497 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 498 | proxy_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 499 | if (SKIP_VM_RELAUNCH.toBoolean() == true) { |
| 500 | break |
| 501 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 502 | _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] | 503 | def nodeProvider = _pillar['return'][0].values()[0] |
| 504 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true) |
| 505 | sleep(2) |
| 506 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true) |
| 507 | try { |
| 508 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y") |
| 509 | } catch (Exception e) { |
| 510 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 511 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 512 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 513 | } |
| 514 | def control_general_target = "" |
Marek Celoud | ead57b9 | 2017-11-13 16:41:12 +0100 | [diff] [blame] | 515 | def control_target_hosts = salt.getMinions(pepperEnv, 'I@keystone:server').sort() |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 516 | node_count = 1 |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 517 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 518 | for (t in control_target_hosts) { |
| 519 | def target = t.split("\\.")[0] |
Jiri Broulik | 42dfbb1 | 2017-11-13 11:27:45 +0100 | [diff] [blame] | 520 | control_general_target = target.replaceAll('\\d+$', "") |
Jiri Broulik | 7cadf58 | 2017-11-13 17:35:31 +0100 | [diff] [blame^] | 521 | if (SKIP_VM_RELAUNCH.toBoolean() == true) { |
| 522 | break |
| 523 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 524 | _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] | 525 | def nodeProvider = _pillar['return'][0].values()[0] |
| 526 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.destroy', ["${target}.${domain}"], null, true) |
| 527 | sleep(2) |
| 528 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'file.copy', ["/root/${target}.${domain}.qcow2.bak", "/var/lib/libvirt/images/${target}.${domain}/system.qcow2"], null, true) |
| 529 | try { |
| 530 | salt.cmdRun(pepperEnv, 'I@salt:master', "salt-key -d ${target}.${domain} -y") |
| 531 | } catch (Exception e) { |
| 532 | common.warningMsg('does not match any accepted, unaccepted or rejected keys. They were probably already removed. We should continue to run') |
| 533 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 534 | node_count++ |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | // database restore section |
| 538 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 539 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 540 | } catch (Exception e) { |
| 541 | common.warningMsg('Mysql service already stopped') |
| 542 | } |
| 543 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 544 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 545 | } catch (Exception e) { |
| 546 | common.warningMsg('Mysql service already stopped') |
| 547 | } |
| 548 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 549 | salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 550 | } catch (Exception e) { |
| 551 | common.warningMsg('Files are not present') |
| 552 | } |
| 553 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 554 | salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 555 | } catch (Exception e) { |
| 556 | common.warningMsg('Directory already empty') |
| 557 | } |
| 558 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 559 | 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] | 560 | } catch (Exception e) { |
| 561 | common.warningMsg('File is not present') |
| 562 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 563 | salt.cmdRun(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf") |
| 564 | _pillar = salt.getPillar(pepperEnv, "I@galera:master", 'xtrabackup:client:backup_dir') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 565 | backup_dir = _pillar['return'][0].values()[0] |
| 566 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' } |
| 567 | print(backup_dir) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 568 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 569 | salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 570 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 571 | |
| 572 | // wait until mysql service on galera master is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 573 | salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 574 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 575 | salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 576 | // |
| 577 | |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 578 | node_count = 1 |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 579 | for (t in control_target_hosts) { |
| 580 | def target = t.split("\\.")[0] |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 581 | _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] | 582 | def nodeProvider = _pillar['return'][0].values()[0] |
| 583 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true) |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 584 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 585 | } |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 586 | node_count = 1 |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 587 | for (t in proxy_target_hosts) { |
| 588 | def target = t.split("\\.")[0] |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 589 | _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] | 590 | def nodeProvider = _pillar['return'][0].values()[0] |
| 591 | salt.runSaltProcessStep(pepperEnv, "${nodeProvider}", 'virt.start', ["${target}.${domain}"], null, true) |
Jiri Broulik | 21b4f4d | 2017-11-13 14:04:46 +0100 | [diff] [blame] | 592 | node_count++ |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 593 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 594 | |
| 595 | // salt 'cmp*' cmd.run 'service nova-compute restart' |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 596 | salt.runSaltProcessStep(pepperEnv, 'I@nova:compute', 'service.restart', ['nova-compute'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 597 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 598 | for (t in control_target_hosts) { |
| 599 | def target = t.split("\\.")[0] |
| 600 | salt.minionPresent(pepperEnv, 'I@salt:master', "${target}") |
| 601 | } |
| 602 | for (t in proxy_target_hosts) { |
| 603 | def target = t.split("\\.")[0] |
| 604 | salt.minionPresent(pepperEnv, 'I@salt:master', "${target}") |
| 605 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 606 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 607 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-conductor'], null, true) |
| 608 | salt.runSaltProcessStep(pepperEnv, "${control_general_target}*", 'service.restart', ['nova-scheduler'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 609 | |
Jiri Broulik | 3f5ed1a | 2017-11-10 17:35:52 +0100 | [diff] [blame] | 610 | 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] | 611 | } |
Jiri Broulik | bb447ac | 2017-05-04 15:36:22 +0200 | [diff] [blame] | 612 | } |
| 613 | } |