blob: 76b64aee87b799ef3993e1660303ce134204dc56 [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) {
Anton Samoylov0d17e522019-08-07 17:30:25 +040035 common.errorMsg("Opencontrail controllers health check stage found issues with currently running services.")
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020036 }
37 }
38
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020039 stage('Restore') {
Anton Samoylov4e366c42019-06-26 17:20:58 +040040 // stop neutron-server to prevent CRUD api calls to contrail-api service
41 try {
42 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true)
43 } catch (Exception er) {
44 common.warningMsg('neutron-server service already stopped')
45 }
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020046 // get opencontrail version
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040047 def contrailVersion = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version")
Anton Samoylov4e366c42019-06-26 17:20:58 +040048 def configDbIp = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:host")
49 def configDbPort = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:port_configdb")
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040050 common.infoMsg("OpenContrail version is ${contrailVersion}")
51 if (contrailVersion.startsWith('4')) {
52 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary",
53 "docker:client:compose:opencontrail:service:controller:container_name")
54 common.infoMsg("Applying db restore procedure for OpenContrail 4.X version")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020055 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040056 common.infoMsg("Stop contrail control plane containers")
57 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 +020058 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040059 common.errorMsg('An error has been occurred during contrail containers shutdown: ' + err.getMessage())
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040060 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020061 }
62 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040063 common.infoMsg("Cleanup cassandra data")
64 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 +020065 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040066 common.errorMsg('Cannot cleanup cassandra data on control nodes: ' + err.getMessage())
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040067 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020068 }
69 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040070 common.infoMsg("Start cassandra db on I@cassandra:backup:client node")
71 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020072 } catch (Exception err) {
Anton Samoylov4e366c42019-06-26 17:20:58 +040073 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 +040074 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020075 }
Anton Samoylov4e366c42019-06-26 17:20:58 +040076 // wait for cassandra to be online
77 common.retry(6, 20){
78 common.infoMsg("Trying to connect to casandra db on I@cassandra:backup:client node ...")
79 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "nc -v -z -w2 ${configDbIp} ${configDbPort}")
80 }
Anton Samoylovb3d6b552019-06-24 12:02:51 +040081 // remove restore-already-happened file if any is present
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020082 try {
Anton Samoylovf3b0ca22019-06-21 19:53:26 +040083 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored')
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020084 } catch (Exception err) {
85 common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage())
86 }
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020087 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra")
Anton Samoylov4e366c42019-06-26 17:20:58 +040088 try {
89 salt.cmdRun(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
90 } catch (Exception err) {
91 common.errorMsg('An error has been occurred during cassandra db startup on I@opencontrail:control and not I@cassandra:backup:client nodes: ' + err.getMessage())
92 throw err
93 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020094 // another mantra, wait till all services are up
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020095 sleep(60)
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020096 try {
Anton Samoylov4e366c42019-06-26 17:20:58 +040097 common.infoMsg("Start analytics containers node")
98 salt.cmdRun(pepperEnv, 'I@opencontrail:collector', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d')
99 } catch (Exception err) {
100 common.errorMsg('An error has been occurred during analytics containers startup: ' + err.getMessage())
101 throw err
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200102 }
Anton Samoylov4e366c42019-06-26 17:20:58 +0400103 } else {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200104 try {
105 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
106 } catch (Exception er) {
107 common.warningMsg('Supervisor-config service already stopped')
108 }
109 // Cassandra restore section
110 try {
111 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
112 } catch (Exception er) {
113 common.warningMsg('Supervisor-database service already stopped')
114 }
115 try {
116 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
117 } catch (Exception er) {
118 common.warningMsg('Directory already exists')
119 }
120
121 try {
122 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
123 } catch (Exception er) {
124 common.warningMsg('Files were already moved')
125 }
126 try {
127 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
128 } catch (Exception er) {
129 common.warningMsg('Directory already empty')
130 }
131
Anton Samoylovf3b0ca22019-06-21 19:53:26 +0400132 def backupDir = getValueForPillarKey(pepperEnv, "I@cassandra:backup:client", "cassandra:backup:backup_dir")
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200133 common.infoMsg("Backup directory is ${backupDir}")
134 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true)
135
136 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
137
138 // wait until supervisor-database service is up
139 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
140 sleep(60)
141
142 // performs restore
143 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup")
144 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
145 sleep(5)
146 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
147
148 // wait until supervisor-database service is up
149 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
150 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
151 sleep(5)
152
153 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
Inessa Vasilevskayaea454392018-09-07 17:25:34 +0200154
155 // wait until contrail-status is up
156 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)
157
158 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
159 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100160 }
Anton Samoylov4e366c42019-06-26 17:20:58 +0400161
162 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +0200163 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200164
165 stage('Opencontrail controllers health check') {
Anton Samoylov4e366c42019-06-26 17:20:58 +0400166 common.retry(9, 20){
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200167 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
168 }
169 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200170 }
171}