blob: fb1259f11ddfef8cc21ec3ba85eba3b44ca33ffd [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') {
Anton Samoylov4e366c42019-06-26 17:20:58 +040041 // stop neutron-server to prevent CRUD api calls to contrail-api service
42 try {
43 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true)
44 } catch (Exception er) {
45 common.warningMsg('neutron-server service already stopped')
46 }
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020047 // get opencontrail version
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040048 def contrailVersion = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version")
Anton Samoylov4e366c42019-06-26 17:20:58 +040049 def configDbIp = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:host")
50 def configDbPort = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:port_configdb")
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040051 common.infoMsg("OpenContrail version is ${contrailVersion}")
52 if (contrailVersion.startsWith('4')) {
53 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary",
54 "docker:client:compose:opencontrail:service:controller:container_name")
55 common.infoMsg("Applying db restore procedure for OpenContrail 4.X version")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020056 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040057 common.infoMsg("Stop contrail control plane containers")
58 salt.cmdRun(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'cd /etc/docker/compose/opencontrail/; docker-compose down')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020059 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040060 common.errorMsg('An error has been occurred during contrail containers shutdown: ' + err.getMessage())
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040061 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020062 }
63 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040064 common.infoMsg("Cleanup cassandra data")
65 salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'for f in $(ls /var/lib/configdb/); do rm -r /var/lib/configdb/$f; done')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020066 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040067 common.errorMsg('Cannot cleanup cassandra data on control nodes: ' + err.getMessage())
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040068 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020069 }
70 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040071 common.infoMsg("Start cassandra db on I@cassandra:backup:client node")
72 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020073 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040074 common.errorMsg('An error has been occurred during cassandra db startup on I@cassandra:backup:client node: ' + err.getMessage())
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040075 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020076 }
Anton Samoylov4e366c42019-06-26 17:20:58 +040077 // wait for cassandra to be online
78 common.retry(6, 20){
79 common.infoMsg("Trying to connect to casandra db on I@cassandra:backup:client node ...")
80 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "nc -v -z -w2 ${configDbIp} ${configDbPort}")
81 }
Anton Samoylovb3d6b552019-06-24 12:02:51 +040082 // remove restore-already-happened file if any is present
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020083 try {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040084 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020085 } catch (Exception err) {
86 common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage())
87 }
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020088 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra")
Anton Samoylov4e366c42019-06-26 17:20:58 +040089 try {
90 salt.cmdRun(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
91 } catch (Exception err) {
92 common.errorMsg('An error has been occurred during cassandra db startup on I@opencontrail:control and not I@cassandra:backup:client nodes: ' + err.getMessage())
93 throw err
94 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020095 // another mantra, wait till all services are up
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020096 sleep(60)
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020097 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040098 common.infoMsg("Start analytics containers node")
99 salt.cmdRun(pepperEnv, 'I@opencontrail:collector', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
100 } catch (Exception err) {
101 common.errorMsg('An error has been occurred during analytics containers startup: ' + err.getMessage())
102 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200103 }
Anton Samoylov4e366c42019-06-26 17:20:58 +0400104 } else {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200105 try {
106 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
107 } catch (Exception er) {
108 common.warningMsg('Supervisor-config service already stopped')
109 }
110 // Cassandra restore section
111 try {
112 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
113 } catch (Exception er) {
114 common.warningMsg('Supervisor-database service already stopped')
115 }
116 try {
117 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
118 } catch (Exception er) {
119 common.warningMsg('Directory already exists')
120 }
121
122 try {
123 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
124 } catch (Exception er) {
125 common.warningMsg('Files were already moved')
126 }
127 try {
128 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
129 } catch (Exception er) {
130 common.warningMsg('Directory already empty')
131 }
132
Anton Samoylovf3b0ca22019-06-21 19:53:26 +0400133 def backupDir = getValueForPillarKey(pepperEnv, "I@cassandra:backup:client", "cassandra:backup:backup_dir")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200134 common.infoMsg("Backup directory is ${backupDir}")
135 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true)
136
137 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
138
139 // wait until supervisor-database service is up
140 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
141 sleep(60)
142
143 // performs restore
144 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup")
145 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
146 sleep(5)
147 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
148
149 // wait until supervisor-database service is up
150 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
151 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
152 sleep(5)
153
154 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200155
156 // wait until contrail-status is up
157 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)
158
159 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
160 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100161 }
Anton Samoylov4e366c42019-06-26 17:20:58 +0400162
163 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +0200164 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200165
166 stage('Opencontrail controllers health check') {
Anton Samoylov4e366c42019-06-26 17:20:58 +0400167 common.retry(9, 20){
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200168 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
169 }
170 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200171 }
172}