blob: 8afc5a5106c1854609affd11c7be2b39e786d115 [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"
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040015
16def oc3SupervisorServices = ["supervisor-config", "supervisor-control"]
17def oc4ConfigServices = ["contrail-api", "contrail-schema", "contrail-svc-monitor", "contrail-device-manager", "contrail-config-nodemgr"]
18def oc4ControlServices = ["contrail-control", "contrail-named", "contrail-dns", "contrail-control-nodemgr"]
19def zkService = "zookeeper"
20def contrailStatusCheckCmd = "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup"
21def zkDbPath = "/var/lib/zookeeper/version-2"
22
Jakub Josefa63f9862018-01-11 17:58:38 +010023timeout(time: 12, unit: 'HOURS') {
24 node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020025
Jakub Josefa63f9862018-01-11 17:58:38 +010026 stage('Setup virtualenv for Pepper') {
27 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikf2abf422017-07-03 17:04:19 +020028 }
29
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020030 stage('Restore') {
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040031
32 def ocVersionPillarKey = salt.getReturnValues(salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version"))
33
34 if (ocVersionPillarKey == '') {
35 throw new Exception("Cannot get value for _param:opencontrail_version key on I@opencontrail:control:role:primary target")
Jakub Josefa63f9862018-01-11 17:58:38 +010036 }
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040037
38 def ocVersion = ocVersionPillarKey.toString()
39
40 if (ocVersion >= "4.0") {
41
42 contrailStatusCheckCmd = "doctrail controller ${contrailStatusCheckCmd}"
43 zkDbPath = "/var/lib/config_zookeeper_data/version-2"
44
45 for (service in (oc4ConfigServices + oc4ControlServices + [zkService])) {
46 try {
47 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.run', ["doctrail controller systemctl stop ${service}"])
48 } catch (Exception er) {
49 common.warningMsg("${service} cannot be stopped inside controller container")
50 }
51 }
52 // wait until zookeeper service is down
53 salt.commandStatus(pepperEnv, 'I@opencontrail:control', "doctrail controller service ${zkService} status", 'Active: inactive')
54 } else {
55 for (service in (oc3SupervisorServices + [zkService])) {
56 try {
57 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ["${service}"])
58 } catch (Exception er) {
59 common.warningMsg("${service} service cannot be stopped. It may be already stopped before.")
60 }
61 }
62 // wait until zookeeper service is down
63 salt.commandStatus(pepperEnv, 'I@opencontrail:control', "service ${zkService} status", "stop")
Jakub Josefa63f9862018-01-11 17:58:38 +010064 }
Jakub Josefa63f9862018-01-11 17:58:38 +010065
66 try {
67 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
68 } catch (Exception er) {
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040069 common.warningMsg('/root/zookeeper/zookeeper.bak directory already exists')
Jakub Josefa63f9862018-01-11 17:58:38 +010070 }
71
72 try {
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040073 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv ${zkDbPath}/* /root/zookeeper/zookeeper.bak")
Jakub Josefa63f9862018-01-11 17:58:38 +010074 } catch (Exception er) {
75 common.warningMsg('Files were already moved')
76 }
77 try {
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040078 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf ${zkDbPath}/*")
Jakub Josefa63f9862018-01-11 17:58:38 +010079 } catch (Exception er) {
80 common.warningMsg('Directory already empty')
81 }
82
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040083 backupDirPillarKey = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
84 backupDir = backupDirPillarKey['return'][0].values()[0]
85 if (backupDir == null || backupDir.isEmpty()) { backupDir='/var/backups/zookeeper' }
86 print(backupDir)
87 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backupDir}/dbrestored"])
Jakub Josefa63f9862018-01-11 17:58:38 +010088
89 // performs restore
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020090 salt.enforceState(pepperEnv, 'I@opencontrail:control', "zookeeper.backup")
Jakub Josefa63f9862018-01-11 17:58:38 +010091
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +040092 if (ocVersion >= "4.0") {
93 for (service in ([zkService] + oc4ConfigServices + oc4ControlServices)) {
94 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.run', ["doctrail controller systemctl start ${service}"])
95 }
96 } else {
97 for (service in ([zkService] + oc3SupervisorServices)) {
98 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ["${service}"])
99 }
100 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100101
102 // wait until contrail-status is up
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +0400103 salt.commandStatus(pepperEnv, 'I@opencontrail:control', contrailStatusCheckCmd, null, false)
Jakub Josefa63f9862018-01-11 17:58:38 +0100104
Anton Samoylov9c3f1ac2019-02-19 23:12:51 +0400105 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls ${zkDbPath}")
Jakub Josefa63f9862018-01-11 17:58:38 +0100106 try {
107 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181")
108 } catch (Exception er) {
109 common.warningMsg('Check which node is zookeeper leader')
110 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200111 }
112 }
113}