blob: d4592663ededd857e29ea70100103f827470bfd5 [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"
Jakub Josefa63f9862018-01-11 17:58:38 +010015timeout(time: 12, unit: 'HOURS') {
16 node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020017
Jakub Josefa63f9862018-01-11 17:58:38 +010018 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikf2abf422017-07-03 17:04:19 +020020 }
21
Jakub Josefa63f9862018-01-11 17:58:38 +010022 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 {
30 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
31 } catch (Exception er) {
32 common.warningMsg('Supervisor-config service already stopped')
33 }
34 try {
35 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true)
36 } catch (Exception er) {
37 common.warningMsg('Supervisor-control service already stopped')
38 }
39 try {
40 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true)
41 } catch (Exception er) {
42 common.warningMsg('Zookeeper service already stopped')
43 }
44 //sleep(5)
45 // wait until zookeeper service is down
46 salt.commandStatus(pepperEnv, 'I@opencontrail:control', 'service zookeeper status', 'stop')
47
48 try {
49 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
50 } catch (Exception er) {
51 common.warningMsg('Directory already exists')
52 }
53
54 try {
55 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
56 } catch (Exception er) {
57 common.warningMsg('Files were already moved')
58 }
59 try {
60 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*")
61 } catch (Exception er) {
62 common.warningMsg('Directory already empty')
63 }
64
65 _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
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)
69 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
70
71 // performs restore
72 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
73
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)
77
78 // wait until contrail-status is up
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)
80
81 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
82 try {
83 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181")
84 } catch (Exception er) {
85 common.warningMsg('Check which node is zookeeper leader')
86 }
87 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulikf2abf422017-07-03 17:04:19 +020088 }
89 }
90}