blob: 0f32576cb1974a4dc5e6c602ec7a28e8baeb5d60 [file] [log] [blame]
Jiri Broulikf2abf422017-07-03 17:04:19 +02001/**
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
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020012def python = new com.mirantis.mk.Python()
Jiri Broulikf2abf422017-07-03 17:04:19 +020013
chnyda625f4b42017-10-11 14:10:31 +020014def pepperEnv = "pepperEnv"
Jiri Broulikf2abf422017-07-03 17:04:19 +020015
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040016node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020017
chnyda625f4b42017-10-11 14:10:31 +020018 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070019 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040020 }
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 {
chnyda625f4b42017-10-11 14:10:31 +020030 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040031 } catch (Exception er) {
32 common.warningMsg('Supervisor-config service already stopped')
33 }
34 try {
chnyda625f4b42017-10-11 14:10:31 +020035 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040036 } catch (Exception er) {
37 common.warningMsg('Supervisor-control service already stopped')
38 }
39 try {
chnyda625f4b42017-10-11 14:10:31 +020040 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040041 } catch (Exception er) {
42 common.warningMsg('Zookeeper service already stopped')
43 }
44 //sleep(5)
45 // wait until zookeeper service is down
chnyda625f4b42017-10-11 14:10:31 +020046 salt.commandStatus(pepperEnv, 'I@opencontrail:control', 'service zookeeper status', 'stop')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040047
48 try {
chnyda625f4b42017-10-11 14:10:31 +020049 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040050 } catch (Exception er) {
51 common.warningMsg('Directory already exists')
Jiri Broulikf2abf422017-07-03 17:04:19 +020052 }
53
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040054 try {
chnyda625f4b42017-10-11 14:10:31 +020055 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040056 } catch (Exception er) {
57 common.warningMsg('Files were already moved')
Jiri Broulikf2abf422017-07-03 17:04:19 +020058 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040059 try {
chnyda625f4b42017-10-11 14:10:31 +020060 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040061 } catch (Exception er) {
62 common.warningMsg('Directory already empty')
63 }
64
chnyda625f4b42017-10-11 14:10:31 +020065 _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066 backup_dir = _pillar['return'][0].values()[0]
67 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' }
68 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +020069 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040070
71 // performs restore
chnyda625f4b42017-10-11 14:10:31 +020072 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040073
chnyda625f4b42017-10-11 14:10:31 +020074 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 Kamaldinov6feef402017-08-02 16:55:58 +040077
78 // wait until contrail-status is up
chnyda625f4b42017-10-11 14:10:31 +020079 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 Kamaldinov6feef402017-08-02 16:55:58 +040080
chnyda625f4b42017-10-11 14:10:31 +020081 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040082 try {
chnyda625f4b42017-10-11 14:10:31 +020083 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040084 } catch (Exception er) {
85 common.warningMsg('Check which node is zookeeper leader')
86 }
chnyda625f4b42017-10-11 14:10:31 +020087 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulikf2abf422017-07-03 17:04:19 +020088 }
89}