blob: bdcf2cd9be097a98ca432a70b1a93a5f8f68ee6c [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
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040010common = new com.mirantis.mk.Common()
11salt = new com.mirantis.mk.Salt()
12python = new com.mirantis.mk.Python()
Jiri Broulikf2abf422017-07-03 17:04:19 +020013
chnyda625f4b42017-10-11 14:10:31 +020014def pepperEnv = "pepperEnv"
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040015
16def getValueForPillarKey(pepperEnv, target, pillarKey) {
17 def out = salt.getReturnValues(salt.getPillar(pepperEnv, target, pillarKey))
18 if (out == '') {
19 throw new Exception("Cannot get value for ${pillarKey} key on ${target} target")
20 }
21 return out.toString()
22}
23
Jakub Josefa63f9862018-01-11 17:58:38 +010024timeout(time: 12, unit: 'HOURS') {
25 node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020026
Jakub Josefa63f9862018-01-11 17:58:38 +010027 stage('Setup virtualenv for Pepper') {
28 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikf2abf422017-07-03 17:04:19 +020029 }
30
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020031 stage('Opencontrail controllers health check') {
32 try {
33 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
34 } catch (Exception er) {
35 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
36 throw er
37 }
38 }
39
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020040 stage('Restore') {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020041 // get opencontrail version
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040042 def contrailVersion = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version")
43 common.infoMsg("OpenContrail version is ${contrailVersion}")
44 if (contrailVersion.startsWith('4')) {
45 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary",
46 "docker:client:compose:opencontrail:service:controller:container_name")
47 common.infoMsg("Applying db restore procedure for OpenContrail 4.X version")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020048 try {
49 salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'doctrail controller systemctl stop contrail-database' )
50 } catch (Exception err) {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040051 common.errorMsg('An error has been occurred during cassandra db shutdown: ' + err.getMessage())
52 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020053 }
54 try {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040055 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "docker exec ${controllerImage} bash -c 'for f in \$(ls /var/lib/cassandra/); do rm -r /var/lib/cassandra/\$f; done'")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020056 } catch (Exception err) {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040057 common.errorMsg('Cannot cleanup cassandra data: ' + err.getMessage())
58 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020059 }
60 try {
61 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'doctrail controller systemctl start contrail-database' )
62 } catch (Exception err) {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040063 common.errorMsg('An error has been occurred during cassandra db startup: ' + err.getMessage())
64 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020065 }
Anton Samoylovb3d6b552019-06-24 12:02:51 +040066 // remove restore-already-happened file if any is present
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020067 try {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040068 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020069 } catch (Exception err) {
70 common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage())
71 }
Anton Samoylovb3d6b552019-06-24 12:02:51 +040072 // perform restore steps
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020073 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra")
74 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, [], true, 5)
75 sleep(5)
76 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, [], true, 5)
77 // the lovely wait-60-seconds mantra before restarting supervisor-database service
78 sleep(60)
79 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "doctrail controller systemctl restart contrail-database")
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020080 // another mantra, wait till all services are up
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020081 sleep(60)
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020082 } else {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020083 try {
84 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true)
85 } catch (Exception er) {
86 common.warningMsg('neutron-server service already stopped')
87 }
88 try {
89 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
90 } catch (Exception er) {
91 common.warningMsg('Supervisor-config service already stopped')
92 }
93 // Cassandra restore section
94 try {
95 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
96 } catch (Exception er) {
97 common.warningMsg('Supervisor-database service already stopped')
98 }
99 try {
100 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
101 } catch (Exception er) {
102 common.warningMsg('Directory already exists')
103 }
104
105 try {
106 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
107 } catch (Exception er) {
108 common.warningMsg('Files were already moved')
109 }
110 try {
111 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
112 } catch (Exception er) {
113 common.warningMsg('Directory already empty')
114 }
115
Anton Samoylovf3b0ca22019-06-21 19:53:26 +0400116 def backupDir = getValueForPillarKey(pepperEnv, "I@cassandra:backup:client", "cassandra:backup:backup_dir")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200117 common.infoMsg("Backup directory is ${backupDir}")
118 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true)
119
120 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
121
122 // wait until supervisor-database service is up
123 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
124 sleep(60)
125
126 // performs restore
127 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup")
128 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
129 sleep(5)
130 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
131
132 // wait until supervisor-database service is up
133 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
134 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
135 sleep(5)
136
137 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
138 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true)
139
140 // wait until contrail-status is up
141 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)
142
143 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
144 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100145 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200146 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200147
148 stage('Opencontrail controllers health check') {
149 common.retry(3, 20){
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200150 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
151 }
152 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200153 }
154}