blob: c2cb8cce780cc9f11ae1d3be30ec309ba6c3eebb [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
16def common = new com.mirantis.mk.Common()
17def salt = new com.mirantis.mk.Salt()
18def python = new com.mirantis.mk.Python()
19
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'
Marek Celouda54924d2017-12-28 16:28:42 +010032//def 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']
33def CMP_PKGS = '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 Samoylovaaf1ff22018-09-27 10:46:43 +040034def KERNEL_MODULE_RELOAD = '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 +040035def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper', 'redis-server']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010036def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper']
Anton Samoylovf6b498d2018-09-19 13:10:34 +040037def controlServices = ['ifmap-server', 'supervisor-control', 'redis-server']
38def thirdPartyServicesToDisable = ['kafka', 'zookeeper', 'cassandra']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010039def 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 +010040
41def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) {
42
43 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
44 salt.printSaltCommandResult(out)
45 // wait until $check is in correct state
46 if ( check == "nodetool status" ) {
47 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
48 } else if ( check == "doctrail all contrail-status" ) {
Marek Celoud8d6ddd82018-01-03 17:56:05 +010049 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)
50 } else if ( check == "contrail-status" ) {
51 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 +010052 }
Marek Celouda54924d2017-12-28 16:28:42 +010053 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
54 //salt.printSaltCommandResult(out)
55 //input message: "Please check the output of \'${check}\' and continue if it is correct."
56}
Jakub Josefa63f9862018-01-11 17:58:38 +010057timeout(time: 12, unit: 'HOURS') {
58 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010059
Jakub Josefa63f9862018-01-11 17:58:38 +010060 stage('Setup virtualenv for Pepper') {
61 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
62 }
Marek Celouda54924d2017-12-28 16:28:42 +010063
Jakub Josefa63f9862018-01-11 17:58:38 +010064 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010065
Anton Samoylov97ce9b82018-10-19 00:43:54 +040066 stage('Opencontrail controllers health check') {
67 try {
68 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
69 } catch (Exception er) {
70 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
71 throw er
72 }
73 }
74
Jakub Josefa63f9862018-01-11 17:58:38 +010075 stage('Opencontrail controllers upgrade') {
76 try {
77 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
78 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.sync_all', [], null, true)
79 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
80 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
81 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010082
Jakub Josefa63f9862018-01-11 17:58:38 +010083 } catch (Exception er) {
84 common.errorMsg("Opencontrail component on I@opencontrail:control or I@opencontrail:collector or I@neutron:server probably failed to be replaced.")
85 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010086 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010087
Jakub Josefa63f9862018-01-11 17:58:38 +010088 try {
Anton Samoylova93106c2018-10-25 10:39:34 +040089 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail_api:service:controller:image")
90 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analytics:image")
91 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
Jakub Josefa63f9862018-01-11 17:58:38 +010092 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
93 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
94 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
95 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
96 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
97
98 } catch (Exception er) {
99 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
100 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100101 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100102
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
104 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
105
106 try {
107 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
108 } catch (Exception er) {
109 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
110 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100111 }
112
Jakub Josefa63f9862018-01-11 17:58:38 +0100113 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
114 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100115
Jakub Josefa63f9862018-01-11 17:58:38 +0100116 try {
117 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
118 } catch (Exception er) {
119 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
120 throw er
121 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400122
Jakub Josefa63f9862018-01-11 17:58:38 +0100123 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
124
125 try {
126 for (service in analyticsServices) {
127 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
128 }
129 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
130 if (result == false) {
131 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
132 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
133 }
134 check = 'doctrail all contrail-status'
135 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylova93106c2018-10-25 10:39:34 +0400136 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 } catch (Exception er) {
138 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
139 throw er
140 }
141 try {
142 check = 'doctrail all contrail-status'
143
144 for (service in configServices) {
145 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
146 }
147
148 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
149 if (result == false) {
150 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
151 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
152 }
153
154 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400155 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100156 }
157
Anton Samoylova93106c2018-10-25 10:39:34 +0400158 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100159
Anton Samoylova93106c2018-10-25 10:39:34 +0400160 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100161
162 sleep(120)
163
164 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400165 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100166 }
167
Anton Samoylova93106c2018-10-25 10:39:34 +0400168 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100169
170 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', ['neutron-plugin-contrail,contrail-heat,python-contrail'])
171 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
172 } catch (Exception er) {
173 common.errorMsg("Opencontrail Controller failed to be upgraded.")
174 throw er
175 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400176 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100177
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400178 stage('Opencontrail controllers backup and cleanup') {
179 try {
180 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
181 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
182 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
183 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
184
185 for (service in (controlServices + thirdPartyServicesToDisable)) {
186 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
187 }
188 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
189 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
190 }
191
192 def tmpCfgBackupDir = '/tmp/cfg_backup'
193 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
194
195 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
196
197 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
198 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
199 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
200 }
201
202 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
203 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
204
205 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
206 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
207 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
208 }
209 } catch (Exception er) {
210 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
211 throw er
212 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100213 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100214 }
215
216
217 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
218
219 try {
220
221 stage('List targeted compute servers') {
222 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
223
224 if (minions.isEmpty()) {
225 throw new Exception("No minion was targeted")
226 }
227
228 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
229 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
230
231 targetLiveAll = minions.join(' or ')
232 common.infoMsg("Found nodes: ${targetLiveAll}")
233 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
234 }
235
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400236 stage('Compute nodes health check') {
237 try {
238 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
239 } catch (Exception er) {
240 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
241 throw er
242 }
243 }
244
Jakub Josefa63f9862018-01-11 17:58:38 +0100245 stage('Confirm upgrade on sample nodes') {
246 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
247 }
248
249 stage("Opencontrail compute upgrade on sample nodes") {
250
251 try {
252 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
253 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
254 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
255 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
256 } catch (Exception er) {
257 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
258 throw er
259 }
260
261 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
262 check = 'contrail-status'
263
264 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
265 salt.printSaltCommandResult(out)
266
267 try {
268 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
269 } catch (Exception er) {
270 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
271 }
272
273 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
274
275 //sleep(10)
276 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
277
278 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
279 salt.printSaltCommandResult(out)
280 }
281
282 stage('Confirm upgrade on all targeted nodes') {
283 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
284 }
285 stage("Opencontrail compute upgrade on all targeted nodes") {
286
287 try {
288 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
289 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
290 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
291 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
292 } catch (Exception er) {
293 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
294 throw er
295 }
296
297 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
298 check = 'contrail-status'
299
300 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
301 salt.printSaltCommandResult(out)
302
303 try {
304 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
305 } catch (Exception er) {
306 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
307 }
308
309 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
310 //sleep(10)
311 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
312
313 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
314 salt.printSaltCommandResult(out)
315 }
316
317 } catch (Throwable e) {
318 // If there was an error or exception thrown, the build failed
319 currentBuild.result = "FAILURE"
320 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
321 throw e
322 }
323 }
324
325
326 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
327
328 stage('Ask for manual confirmation') {
329 input message: "Do you want to continue with the Opencontrail nodes rollback?"
330 }
331
332 stage('Opencontrail controllers rollback') {
333
334 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true)
335 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo')
336 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
337
338 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
339
Anton Samoylova93106c2018-10-25 10:39:34 +0400340 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 +0100341 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400342 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100343 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400344 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100345
346 check = 'contrail-status'
Anton Samoylova93106c2018-10-25 10:39:34 +0400347 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100348
349 sleep(120)
350
Anton Samoylova93106c2018-10-25 10:39:34 +0400351 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
352 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400353 for (service in (controlServices + thirdPartyServicesToDisable)) {
354 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
355 }
356 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
357 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
358 }
Marek Celouda54924d2017-12-28 16:28:42 +0100359 }
Marek Celouda54924d2017-12-28 16:28:42 +0100360 }
361
Jakub Josefa63f9862018-01-11 17:58:38 +0100362 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100363
Jakub Josefa63f9862018-01-11 17:58:38 +0100364 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100365
Jakub Josefa63f9862018-01-11 17:58:38 +0100366 stage('List targeted compute servers') {
367 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100368
Jakub Josefa63f9862018-01-11 17:58:38 +0100369 if (minions.isEmpty()) {
370 throw new Exception("No minion was targeted")
371 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100372
Jakub Josefa63f9862018-01-11 17:58:38 +0100373 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
374 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100375
Jakub Josefa63f9862018-01-11 17:58:38 +0100376 targetLiveAll = minions.join(' or ')
377 common.infoMsg("Found nodes: ${targetLiveAll}")
378 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100379 }
380
Jakub Josefa63f9862018-01-11 17:58:38 +0100381 stage('Confirm rollback on sample nodes') {
382 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 +0100383 }
384
Jakub Josefa63f9862018-01-11 17:58:38 +0100385 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100386
Jakub Josefa63f9862018-01-11 17:58:38 +0100387 try {
388 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
389 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
390 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
391 } catch (Exception er) {
392 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
393 throw er
394 }
Marek Celouda54924d2017-12-28 16:28:42 +0100395
Jakub Josefa63f9862018-01-11 17:58:38 +0100396 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
397 check = 'contrail-status'
398
399 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
400 salt.printSaltCommandResult(out)
401
402 try {
403 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
404 } catch (Exception er) {
405 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
406 }
407
408 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
409 //sleep(10)
410 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
411
412 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
413 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100414 }
415
Jakub Josefa63f9862018-01-11 17:58:38 +0100416 stage('Confirm rollback on all targeted nodes') {
417 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 +0100418 }
419
Jakub Josefa63f9862018-01-11 17:58:38 +0100420 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100421
Jakub Josefa63f9862018-01-11 17:58:38 +0100422 try {
423 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
424 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
425 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
426 } catch (Exception er) {
427 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
428 throw er
429 }
Marek Celouda54924d2017-12-28 16:28:42 +0100430
Jakub Josefa63f9862018-01-11 17:58:38 +0100431 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
432 check = 'contrail-status'
433
434 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
435 salt.printSaltCommandResult(out)
436
437 try {
438 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
439 } catch (Exception er) {
440 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
441 }
442
443 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
444 //sleep(10)
445 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
446
447 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
448 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100449 }
450
Jakub Josefa63f9862018-01-11 17:58:38 +0100451 } catch (Throwable e) {
452 // If there was an error or exception thrown, the build failed
453 currentBuild.result = "FAILURE"
454 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
455 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100456 }
Marek Celouda54924d2017-12-28 16:28:42 +0100457 }
458 }
459}