blob: 6b4822a6b051568c728fa23e76b6239b9d81615f [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 Broulik1c513982017-07-04 22:19:51 +020045 sleep(5)
Jiri Broulikf2abf422017-07-03 17:04:19 +020046 try {
Jiri Broulik1c513982017-07-04 22:19:51 +020047 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
Jiri Broulikf2abf422017-07-03 17:04:19 +020048 } catch (Exception er) {
49 common.warningMsg('Directory already exists')
50 }
51
Jiri Broulikf2abf422017-07-03 17:04:19 +020052 try {
53 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
54 } catch (Exception er) {
55 common.warningMsg('Files were already moved')
56 }
Jiri Broulik1c513982017-07-04 22:19:51 +020057 try {
58 salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*")
59 } catch (Exception er) {
60 common.warningMsg('Directory already empty')
61 }
Jiri Broulikf2abf422017-07-03 17:04:19 +020062
63 _pillar = salt.getPillar(saltMaster, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
64 backup_dir = _pillar['return'][0].values()[0]
65 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' }
66 print(backup_dir)
Jiri Broulik1c513982017-07-04 22:19:51 +020067 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +020068
69 // performs restore
70 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
71
72 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true)
73 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true)
74 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true)
75
Jiri Broulik1c513982017-07-04 22:19:51 +020076 sleep(50)
Jiri Broulikf2abf422017-07-03 17:04:19 +020077 salt.cmdRun(saltMaster, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
Jiri Broulik1c513982017-07-04 22:19:51 +020078 try {
79 salt.cmdRun(saltMaster, 'I@opencontrail:control', "echo stat | nc localhost 2181")
80 } catch (Exception er) {
81 common.warningMsg('Check which node is zookeeper leader')
82 }
Jiri Broulikf2abf422017-07-03 17:04:19 +020083 salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
84 }
85 }
86}
87
88
89