Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +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]. |
| 7 | * |
| 8 | **/ |
| 9 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 12 | def python = new com.mirantis.mk.Python() |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 13 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 14 | def pepperEnv = "pepperEnv" |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 15 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 16 | node() { |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 17 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 18 | stage('Setup virtualenv for Pepper') { |
| 19 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | stage('Start restore') { |
| 23 | // # actual upgrade |
| 24 | |
| 25 | stage('Ask for manual confirmation') { |
| 26 | input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Cassandra?" |
| 27 | } |
| 28 | // Cassandra restore section |
| 29 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 30 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 31 | } catch (Exception er) { |
| 32 | common.warningMsg('Supervisor-database service already stopped') |
| 33 | } |
| 34 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 35 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 36 | } catch (Exception er) { |
| 37 | common.warningMsg('Directory already exists') |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 40 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 41 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 42 | } catch (Exception er) { |
| 43 | common.warningMsg('Files were already moved') |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 44 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 45 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 46 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 47 | } catch (Exception er) { |
| 48 | common.warningMsg('Directory already empty') |
| 49 | } |
| 50 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 51 | _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 52 | backup_dir = _pillar['return'][0].values()[0] |
| 53 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' } |
| 54 | print(backup_dir) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 55 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 56 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 57 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 58 | |
| 59 | // wait until supervisor-database service is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 60 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
Jiri Broulik | 3bf1d5c | 2017-08-11 12:31:37 +0200 | [diff] [blame] | 61 | sleep(5) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 62 | // performs restore |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 63 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c 'salt-call state.sls cassandra'") |
| 64 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 65 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 66 | |
| 67 | // wait until supervisor-database service is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 68 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 69 | salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 70 | sleep(5) |
| 71 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 72 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 73 | |
| 74 | // wait until contrail-status is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 75 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
Jiri Broulik | 3bf1d5c | 2017-08-11 12:31:37 +0200 | [diff] [blame] | 76 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 77 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status") |
| 78 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 79 | } |
| 80 | } |