blob: 0c339ed9a4b0ab3f970558fff616a64fcd67df94 [file] [log] [blame]
Marek Celouda54924d2017-12-28 16:28:42 +01001/**
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 * STAGE_CONTROLLERS_UPGRADE Run upgrade on Opencontrail controllers and analytics (bool)
8 * STAGE_COMPUTES_UPGRADE Run upgrade on Opencontrail compute nodes (bool)
9 * COMPUTE_TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
10 * COMPUTE_TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update.
11 * STAGE_CONTROLLERS_ROLLBACK Run rollback on Opencontrail controllers (bool)
12 * STAGE_COMPUTES_ROLLBACK Run rollback on Opencontrail compute nodes (bool)
13 *
14**/
15
Anton Samoylov9837c212018-12-20 00:15:11 +040016common = new com.mirantis.mk.Common()
17salt = new com.mirantis.mk.Salt()
18python = new com.mirantis.mk.Python()
Marek Celouda54924d2017-12-28 16:28:42 +010019
20def pepperEnv = "pepperEnv"
21def targetLiveSubset
22def targetLiveAll
23def minions
24def args
25def probe = 1
26def command = 'cmd.shell'
27
28def controlPkgs = 'contrail-config,contrail-config-openstack,contrail-control,contrail-dns,contrail-lib,contrail-nodemgr,contrail-utils,contrail-web-controller,contrail-web-core,neutron-plugin-contrail,python-contrail,contrail-database'
Anton Samoylov23be5cd2018-10-18 14:55:31 +040029def thirdPartyControlPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,redis-server,ifmap-server,supervisor'
Marek Celouda54924d2017-12-28 16:28:42 +010030def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,python-contrail,contrail-database'
Anton Samoylov23be5cd2018-10-18 14:55:31 +040031def thirdPartyAnalyticsPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,python-cassandra,cassandra-cpp-driver,redis-server,supervisor'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040032def cmpPkgs = 'contrail-lib contrail-nodemgr contrail-utils contrail-vrouter-agent contrail-vrouter-utils python-contrail python-contrail-vrouter-api python-opencontrail-vrouter-netns contrail-vrouter-dkms'
Anton Samoylov049be7f2018-10-31 20:59:36 +040033def neutronServerPkgs = 'neutron-plugin-contrail,contrail-heat,python-contrail'
34def dashboardPanelPkg = 'openstack-dashboard-contrail-panels'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040035def kernelModuleReloadCmd = 'service supervisor-vrouter stop; rmmod vrouter; sync && echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory; service contrail-vrouter-agent start; service contrail-vrouter-nodemgr start'
Anton Samoylovf6b498d2018-09-19 13:10:34 +040036def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper', 'redis-server']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010037def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper']
Anton Samoylovf6b498d2018-09-19 13:10:34 +040038def controlServices = ['ifmap-server', 'supervisor-control', 'redis-server']
39def thirdPartyServicesToDisable = ['kafka', 'zookeeper', 'cassandra']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010040def config4Services = ['zookeeper', 'contrail-webui-middleware', 'contrail-webui', 'contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr', 'contrail-database']
Marek Celouda54924d2017-12-28 16:28:42 +010041
Anton Samoylov9837c212018-12-20 00:15:11 +040042def runCommonCommands(pepperEnv, target, command, args, check) {
Marek Celouda54924d2017-12-28 16:28:42 +010043
44 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
45 salt.printSaltCommandResult(out)
46 // wait until $check is in correct state
47 if ( check == "nodetool status" ) {
48 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
49 } else if ( check == "doctrail all contrail-status" ) {
Marek Celoud8d6ddd82018-01-03 17:56:05 +010050 salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v FOR | grep -v \\* | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/", null, false, true, null, true, 500)
51 } else if ( check == "contrail-status" ) {
52 salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v FOR | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/", null, false, true, null, true, 500)
Marek Celouda54924d2017-12-28 16:28:42 +010053 }
Marek Celouda54924d2017-12-28 16:28:42 +010054}
Anton Samoylov9837c212018-12-20 00:15:11 +040055
56def getValueForPillarKey(pepperEnv, target, pillarKey) {
57 def out = salt.getReturnValues(salt.getPillar(pepperEnv, target, pillarKey))
58 if (out == '') {
59 throw new Exception("Cannot get value for ${pillarKey} key on ${target} target")
60 }
61 return out
62}
63
Jakub Josefa63f9862018-01-11 17:58:38 +010064timeout(time: 12, unit: 'HOURS') {
65 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010066
Jakub Josefa63f9862018-01-11 17:58:38 +010067 stage('Setup virtualenv for Pepper') {
68 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
69 }
Marek Celouda54924d2017-12-28 16:28:42 +010070
Jakub Josefa63f9862018-01-11 17:58:38 +010071 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010072
Anton Samoylov97ce9b82018-10-19 00:43:54 +040073 stage('Opencontrail controllers health check') {
74 try {
75 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
76 } catch (Exception er) {
77 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
78 throw er
79 }
80 }
81
Jakub Josefa63f9862018-01-11 17:58:38 +010082 stage('Opencontrail controllers upgrade') {
83 try {
Anton Samoylov049be7f2018-10-31 20:59:36 +040084 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
85 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.sync_all', [], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010086 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
87 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
Anton Samoylov049be7f2018-10-31 20:59:36 +040088 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010089
Jakub Josefa63f9862018-01-11 17:58:38 +010090 } catch (Exception er) {
Anton Samoylov049be7f2018-10-31 20:59:36 +040091 common.errorMsg("Opencontrail component on I@opencontrail:control, I@opencontrail:collector, I@neutron:server or I@horizon:server probably failed to be replaced.")
Jakub Josefa63f9862018-01-11 17:58:38 +010092 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010093 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010094
Jakub Josefa63f9862018-01-11 17:58:38 +010095 try {
Anton Samoylov9837c212018-12-20 00:15:11 +040096 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail:service:controller:image")
97 analyticsImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analytics:image")
98 analyticsdbImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analyticsdb:image")
99
Jakub Josefa63f9862018-01-11 17:58:38 +0100100 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
101 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400102 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
104 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
105 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
106
107 } catch (Exception er) {
108 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
109 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100110 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
113 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
114
115 try {
116 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
117 } catch (Exception er) {
118 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
119 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100120 }
121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
123 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100124
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 try {
126 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
127 } catch (Exception er) {
128 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
129 throw er
130 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400131
Jakub Josefa63f9862018-01-11 17:58:38 +0100132 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
133
134 try {
135 for (service in analyticsServices) {
136 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
137 }
138 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
139 if (result == false) {
140 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
141 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
142 }
143 check = 'doctrail all contrail-status'
144 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylov9837c212018-12-20 00:15:11 +0400145 runCommonCommands(pepperEnv, 'I@opencontrail:collector:role:primary', command, args, check)
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 } catch (Exception er) {
147 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
148 throw er
149 }
150 try {
151 check = 'doctrail all contrail-status'
152
153 for (service in configServices) {
154 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
155 }
156
157 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
158 if (result == false) {
159 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
160 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
161 }
162
163 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400164 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100165 }
166
Anton Samoylova93106c2018-10-25 10:39:34 +0400167 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100168
Anton Samoylov9837c212018-12-20 00:15:11 +0400169 runCommonCommands(pepperEnv, 'I@opencontrail:control:role:secondary', command, args, check)
Jakub Josefa63f9862018-01-11 17:58:38 +0100170
171 sleep(120)
172
173 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400174 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100175 }
176
Anton Samoylova93106c2018-10-25 10:39:34 +0400177 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100178
Anton Samoylov049be7f2018-10-31 20:59:36 +0400179 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
180 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100181 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400182 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100183 } catch (Exception er) {
184 common.errorMsg("Opencontrail Controller failed to be upgraded.")
185 throw er
186 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400187 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100188
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400189 stage('Opencontrail controllers backup and cleanup') {
190 try {
191 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
192 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
193 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
194 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
195
196 for (service in (controlServices + thirdPartyServicesToDisable)) {
197 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
198 }
199 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
200 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
201 }
202
203 def tmpCfgBackupDir = '/tmp/cfg_backup'
204 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
205
206 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
207
208 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
209 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
210 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
211 }
212
213 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
214 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
215
216 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
217 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
218 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
219 }
220 } catch (Exception er) {
221 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
222 throw er
223 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100224 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100225 }
226
227
228 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
229
230 try {
231
232 stage('List targeted compute servers') {
233 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
234
235 if (minions.isEmpty()) {
236 throw new Exception("No minion was targeted")
237 }
238
239 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
240 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
241
242 targetLiveAll = minions.join(' or ')
243 common.infoMsg("Found nodes: ${targetLiveAll}")
244 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
245 }
246
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400247 stage('Compute nodes health check') {
248 try {
249 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
250 } catch (Exception er) {
251 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
252 throw er
253 }
254 }
255
Jakub Josefa63f9862018-01-11 17:58:38 +0100256 stage('Confirm upgrade on sample nodes') {
257 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
258 }
259
260 stage("Opencontrail compute upgrade on sample nodes") {
261
262 try {
263 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
264 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
265 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
266 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
267 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400268 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100269 throw er
270 }
271
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400272 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100273 check = 'contrail-status'
274
275 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
276 salt.printSaltCommandResult(out)
277
278 try {
279 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
280 } catch (Exception er) {
281 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
282 }
283
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400284 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100285
286 //sleep(10)
287 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
288
289 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
290 salt.printSaltCommandResult(out)
291 }
292
293 stage('Confirm upgrade on all targeted nodes') {
294 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
295 }
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400296
Jakub Josefa63f9862018-01-11 17:58:38 +0100297 stage("Opencontrail compute upgrade on all targeted nodes") {
298
299 try {
300 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
301 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
302 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
303 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
304 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400305 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100306 throw er
307 }
308
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400309 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100310 check = 'contrail-status'
311
312 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
313 salt.printSaltCommandResult(out)
314
315 try {
316 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
317 } catch (Exception er) {
318 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
319 }
320
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400321 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100322 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
323
324 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
325 salt.printSaltCommandResult(out)
326 }
327
328 } catch (Throwable e) {
329 // If there was an error or exception thrown, the build failed
330 currentBuild.result = "FAILURE"
331 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
332 throw e
333 }
334 }
335
336
337 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
338
339 stage('Ask for manual confirmation') {
340 input message: "Do you want to continue with the Opencontrail nodes rollback?"
341 }
342
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400343 stage('Opencontrail controllers rollback') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100344
Anton Samoylov049be7f2018-10-31 20:59:36 +0400345 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
346 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100347 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
348
349 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400350 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100351
Anton Samoylova93106c2018-10-25 10:39:34 +0400352 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100353 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400354 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100355 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400356 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100357
358 check = 'contrail-status'
Anton Samoylov9837c212018-12-20 00:15:11 +0400359 runCommonCommands(pepperEnv, 'I@opencontrail:control:role:secondary', command, args, check)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100360
361 sleep(120)
362
Anton Samoylova93106c2018-10-25 10:39:34 +0400363 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
364 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400365
366 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
367 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
368 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
369 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
370 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
371 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
372
373 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400374 for (service in (controlServices + thirdPartyServicesToDisable)) {
375 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
376 }
377 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
378 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
379 }
Marek Celouda54924d2017-12-28 16:28:42 +0100380 }
Marek Celouda54924d2017-12-28 16:28:42 +0100381 }
382
Jakub Josefa63f9862018-01-11 17:58:38 +0100383 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100384
Jakub Josefa63f9862018-01-11 17:58:38 +0100385 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100386
Jakub Josefa63f9862018-01-11 17:58:38 +0100387 stage('List targeted compute servers') {
388 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100389
Jakub Josefa63f9862018-01-11 17:58:38 +0100390 if (minions.isEmpty()) {
391 throw new Exception("No minion was targeted")
392 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100393
Jakub Josefa63f9862018-01-11 17:58:38 +0100394 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
395 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100396
Jakub Josefa63f9862018-01-11 17:58:38 +0100397 targetLiveAll = minions.join(' or ')
398 common.infoMsg("Found nodes: ${targetLiveAll}")
399 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100400 }
401
Jakub Josefa63f9862018-01-11 17:58:38 +0100402 stage('Confirm rollback on sample nodes') {
403 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
Marek Celouda54924d2017-12-28 16:28:42 +0100404 }
405
Jakub Josefa63f9862018-01-11 17:58:38 +0100406 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100407
Jakub Josefa63f9862018-01-11 17:58:38 +0100408 try {
409 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
410 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
411 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
412 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400413 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100414 throw er
415 }
Marek Celouda54924d2017-12-28 16:28:42 +0100416
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400417 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100418 check = 'contrail-status'
419
420 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
421 salt.printSaltCommandResult(out)
422
423 try {
424 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
425 } catch (Exception er) {
426 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
427 }
428
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400429 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100430 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
431
432 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
433 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100434 }
435
Jakub Josefa63f9862018-01-11 17:58:38 +0100436 stage('Confirm rollback on all targeted nodes') {
437 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
Marek Celouda54924d2017-12-28 16:28:42 +0100438 }
439
Jakub Josefa63f9862018-01-11 17:58:38 +0100440 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100441
Jakub Josefa63f9862018-01-11 17:58:38 +0100442 try {
443 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
444 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
445 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
446 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400447 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100448 throw er
449 }
Marek Celouda54924d2017-12-28 16:28:42 +0100450
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400451 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100452 check = 'contrail-status'
453
454 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
455 salt.printSaltCommandResult(out)
456
457 try {
458 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
459 } catch (Exception er) {
460 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
461 }
462
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400463 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100464 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
465
466 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
467 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100468 }
469
Jakub Josefa63f9862018-01-11 17:58:38 +0100470 } catch (Throwable e) {
471 // If there was an error or exception thrown, the build failed
472 currentBuild.result = "FAILURE"
473 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
474 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100475 }
Marek Celouda54924d2017-12-28 16:28:42 +0100476 }
477 }
478}