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" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 15 | timeout(time: 12, unit: 'HOURS') { |
| 16 | node() { |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 17 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 18 | stage('Setup virtualenv for Pepper') { |
| 19 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame^] | 22 | stage('Restore') { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 23 | try { |
| 24 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true) |
| 25 | } catch (Exception er) { |
| 26 | common.warningMsg('Supervisor-config service already stopped') |
| 27 | } |
| 28 | try { |
| 29 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true) |
| 30 | } catch (Exception er) { |
| 31 | common.warningMsg('Supervisor-control service already stopped') |
| 32 | } |
| 33 | try { |
| 34 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true) |
| 35 | } catch (Exception er) { |
| 36 | common.warningMsg('Zookeeper service already stopped') |
| 37 | } |
| 38 | //sleep(5) |
| 39 | // wait until zookeeper service is down |
| 40 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', 'service zookeeper status', 'stop') |
| 41 | |
| 42 | try { |
| 43 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak") |
| 44 | } catch (Exception er) { |
| 45 | common.warningMsg('Directory already exists') |
| 46 | } |
| 47 | |
| 48 | try { |
| 49 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak") |
| 50 | } catch (Exception er) { |
| 51 | common.warningMsg('Files were already moved') |
| 52 | } |
| 53 | try { |
| 54 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*") |
| 55 | } catch (Exception er) { |
| 56 | common.warningMsg('Directory already empty') |
| 57 | } |
| 58 | |
| 59 | _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir') |
| 60 | backup_dir = _pillar['return'][0].values()[0] |
| 61 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' } |
| 62 | print(backup_dir) |
| 63 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 64 | |
| 65 | // performs restore |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame^] | 66 | salt.enforceState(pepperEnv, 'I@opencontrail:control', "zookeeper.backup") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 67 | |
| 68 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true) |
| 69 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true) |
| 70 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true) |
| 71 | |
| 72 | // wait until contrail-status is up |
| 73 | 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) |
| 74 | |
| 75 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2") |
| 76 | try { |
| 77 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181") |
| 78 | } catch (Exception er) { |
| 79 | common.warningMsg('Check which node is zookeeper leader') |
| 80 | } |
| 81 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |