blob: 3e5da6cea7185a62740b858a56c4db907d5a4e85 [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()
12
13
14def saltMaster
15
16timestamps {
17 node() {
18
19 stage('Connect to Salt API') {
20 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
21 }
22
23 stage('Start restore') {
24 // # actual upgrade
25
26 stage('Ask for manual confirmation') {
27 input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Zookeeper?"
28 }
29 // Zookeeper restore section
30 try {
31 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
32 } catch (Exception er) {
33 common.warningMsg('Supervisor-config service already stopped')
34 }
35 try {
36 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true)
37 } catch (Exception er) {
38 common.warningMsg('Supervisor-control service already stopped')
39 }
40 try {
41 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true)
42 } catch (Exception er) {
43 common.warningMsg('Zookeeper service already stopped')
44 }
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020045 //sleep(5)
46 // wait until zookeeper service is down
47 salt.commandStatus(saltMaster, 'I@opencontrail:control', 'service zookeeper status', 'stop')
48
Jiri Broulikf2abf422017-07-03 17:04:19 +020049 try {
Jiri Broulik1c513982017-07-04 22:19:51 +020050 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
Jiri Broulikf2abf422017-07-03 17:04:19 +020051 } catch (Exception er) {
52 common.warningMsg('Directory already exists')
53 }
54
Jiri Broulikf2abf422017-07-03 17:04:19 +020055 try {
56 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
57 } catch (Exception er) {
58 common.warningMsg('Files were already moved')
59 }
Jiri Broulik1c513982017-07-04 22:19:51 +020060 try {
61 salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*")
62 } catch (Exception er) {
63 common.warningMsg('Directory already empty')
64 }
Jiri Broulikf2abf422017-07-03 17:04:19 +020065
66 _pillar = salt.getPillar(saltMaster, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
67 backup_dir = _pillar['return'][0].values()[0]
68 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' }
69 print(backup_dir)
Jiri Broulik1c513982017-07-04 22:19:51 +020070 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +020071
72 // performs restore
73 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
74
75 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true)
76 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true)
77 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true)
78
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020079 // wait until contrail-status is up
80 salt.commandStatus(saltMaster, 'I@opencontrail:control', "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
81
Jiri Broulikf2abf422017-07-03 17:04:19 +020082 salt.cmdRun(saltMaster, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
Jiri Broulik1c513982017-07-04 22:19:51 +020083 try {
84 salt.cmdRun(saltMaster, 'I@opencontrail:control', "echo stat | nc localhost 2181")
85 } catch (Exception er) {
86 common.warningMsg('Check which node is zookeeper leader')
87 }
Jiri Broulikf2abf422017-07-03 17:04:19 +020088 salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
89 }
90 }
91}
92
93
94