blob: 185f097eff7e1c846baa02399fcc1ae45dabe466 [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
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020022 stage('Restore') {
Jakub Josefa63f9862018-01-11 17:58:38 +010023 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 Broulik5d4dd2c2018-04-16 17:50:07 +020066 salt.enforceState(pepperEnv, 'I@opencontrail:control', "zookeeper.backup")
Jakub Josefa63f9862018-01-11 17:58:38 +010067
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 Broulikf2abf422017-07-03 17:04:19 +020082 }
83 }
84}