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') { |
Dmitrii Kabanov | f31c896 | 2017-10-12 21:00:30 -0700 | [diff] [blame] | 19 | python.setupPepperVirtualenv(pepperEnv, 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 Zookeeper?" |
| 27 | } |
| 28 | // Zookeeper 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-config'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 31 | } catch (Exception er) { |
| 32 | common.warningMsg('Supervisor-config service already stopped') |
| 33 | } |
| 34 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 35 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 36 | } catch (Exception er) { |
| 37 | common.warningMsg('Supervisor-control service already stopped') |
| 38 | } |
| 39 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 40 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 41 | } catch (Exception er) { |
| 42 | common.warningMsg('Zookeeper service already stopped') |
| 43 | } |
| 44 | //sleep(5) |
| 45 | // wait until zookeeper service is down |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 46 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', 'service zookeeper status', 'stop') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 47 | |
| 48 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 49 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 50 | } catch (Exception er) { |
| 51 | common.warningMsg('Directory already exists') |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 52 | } |
| 53 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 54 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 55 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 56 | } catch (Exception er) { |
| 57 | common.warningMsg('Files were already moved') |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 58 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 59 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 60 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 61 | } catch (Exception er) { |
| 62 | common.warningMsg('Directory already empty') |
| 63 | } |
| 64 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 65 | _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 66 | backup_dir = _pillar['return'][0].values()[0] |
| 67 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' } |
| 68 | print(backup_dir) |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 69 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 70 | |
| 71 | // performs restore |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 72 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 73 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 74 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true) |
| 75 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true) |
| 76 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 77 | |
| 78 | // wait until contrail-status is up |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 79 | 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) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 80 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 81 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 82 | try { |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 83 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181") |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 84 | } catch (Exception er) { |
| 85 | common.warningMsg('Check which node is zookeeper leader') |
| 86 | } |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 87 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 88 | } |
| 89 | } |