blob: 52a0d23d2062c70413ff023007754313a0210d5a [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 Samoylovf6b498d2018-09-19 13:10:34 +040029def thirdPartyControlPkgsToRemove = '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 Samoylovf6b498d2018-09-19 13:10:34 +040031def thirdPartyAnalyticsPkgsToRemove = '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
Jakub Josefa63f9862018-01-11 17:58:38 +010066 stage('Opencontrail controllers upgrade') {
67 try {
68 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
69 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.sync_all', [], null, true)
70 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
71 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
72 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010073
Jakub Josefa63f9862018-01-11 17:58:38 +010074 } catch (Exception er) {
75 common.errorMsg("Opencontrail component on I@opencontrail:control or I@opencontrail:collector or I@neutron:server probably failed to be replaced.")
76 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010077 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010078
Jakub Josefa63f9862018-01-11 17:58:38 +010079 try {
80 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control and *01*", "docker:client:compose:opencontrail_api:service:controller:image")
81 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analytics:image")
82 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
83 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
84 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
85 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
86 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
87 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
88
89 } catch (Exception er) {
90 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
91 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010092 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010093
Jakub Josefa63f9862018-01-11 17:58:38 +010094 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
95 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
96
97 try {
98 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
99 } catch (Exception er) {
100 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
101 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100102 }
103
Jakub Josefa63f9862018-01-11 17:58:38 +0100104 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
105 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100106
Jakub Josefa63f9862018-01-11 17:58:38 +0100107 try {
108 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
109 } catch (Exception er) {
110 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
111 throw er
112 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400113
Jakub Josefa63f9862018-01-11 17:58:38 +0100114 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
115
116 try {
117 for (service in analyticsServices) {
118 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
119 }
120 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
121 if (result == false) {
122 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
123 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
124 }
125 check = 'doctrail all contrail-status'
126 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
127 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
128 } catch (Exception er) {
129 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
130 throw er
131 }
132 try {
133 check = 'doctrail all contrail-status'
134
135 for (service in configServices) {
136 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
137 }
138
139 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
140 if (result == false) {
141 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
142 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
143 }
144
145 for (service in controlServices) {
146 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'service.stop', [service])
147 }
148
149 salt.enforceState(pepperEnv, 'I@opencontrail:control and *0[23]*', 'docker.client')
150
151 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
152
153 sleep(120)
154
155 for (service in controlServices) {
156 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'service.stop', [service])
157 }
158
159 salt.enforceState(pepperEnv, 'I@opencontrail:control and *01*', 'docker.client')
160
161 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', ['neutron-plugin-contrail,contrail-heat,python-contrail'])
162 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
163 } catch (Exception er) {
164 common.errorMsg("Opencontrail Controller failed to be upgraded.")
165 throw er
166 }
167
168 }
169 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
170 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
171 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
172 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400173 for (service in (controlServices + thirdPartyServicesToDisable)) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
175 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400176 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100177 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400178 }
179 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
180 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
Jakub Josefa63f9862018-01-11 17:58:38 +0100181 }
182
183
184 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
185
186 try {
187
188 stage('List targeted compute servers') {
189 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
190
191 if (minions.isEmpty()) {
192 throw new Exception("No minion was targeted")
193 }
194
195 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
196 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
197
198 targetLiveAll = minions.join(' or ')
199 common.infoMsg("Found nodes: ${targetLiveAll}")
200 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
201 }
202
203 stage('Confirm upgrade on sample nodes') {
204 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
205 }
206
207 stage("Opencontrail compute upgrade on sample nodes") {
208
209 try {
210 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
211 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
212 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
213 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
214 } catch (Exception er) {
215 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
216 throw er
217 }
218
219 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
220 check = 'contrail-status'
221
222 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
223 salt.printSaltCommandResult(out)
224
225 try {
226 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
227 } catch (Exception er) {
228 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
229 }
230
231 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
232
233 //sleep(10)
234 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
235
236 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
237 salt.printSaltCommandResult(out)
238 }
239
240 stage('Confirm upgrade on all targeted nodes') {
241 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
242 }
243 stage("Opencontrail compute upgrade on all targeted nodes") {
244
245 try {
246 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
247 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
248 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
249 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
250 } catch (Exception er) {
251 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
252 throw er
253 }
254
255 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
256 check = 'contrail-status'
257
258 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
259 salt.printSaltCommandResult(out)
260
261 try {
262 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
263 } catch (Exception er) {
264 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
265 }
266
267 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
268 //sleep(10)
269 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
270
271 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
272 salt.printSaltCommandResult(out)
273 }
274
275 } catch (Throwable e) {
276 // If there was an error or exception thrown, the build failed
277 currentBuild.result = "FAILURE"
278 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
279 throw e
280 }
281 }
282
283
284 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
285
286 stage('Ask for manual confirmation') {
287 input message: "Do you want to continue with the Opencontrail nodes rollback?"
288 }
289
290 stage('Opencontrail controllers rollback') {
291
292 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true)
293 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo')
294 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
295
296 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
297
298 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
299 for (service in config4Services) {
300 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
301 }
302 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
303
304 check = 'contrail-status'
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100305 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
306
307 sleep(120)
308
Jakub Josefa63f9862018-01-11 17:58:38 +0100309 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
310 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400311 for (service in (controlServices + thirdPartyServicesToDisable)) {
312 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
313 }
314 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
315 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
316 }
Marek Celouda54924d2017-12-28 16:28:42 +0100317 }
Marek Celouda54924d2017-12-28 16:28:42 +0100318 }
319
Jakub Josefa63f9862018-01-11 17:58:38 +0100320 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100321
Jakub Josefa63f9862018-01-11 17:58:38 +0100322 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100323
Jakub Josefa63f9862018-01-11 17:58:38 +0100324 stage('List targeted compute servers') {
325 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100326
Jakub Josefa63f9862018-01-11 17:58:38 +0100327 if (minions.isEmpty()) {
328 throw new Exception("No minion was targeted")
329 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100330
Jakub Josefa63f9862018-01-11 17:58:38 +0100331 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
332 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100333
Jakub Josefa63f9862018-01-11 17:58:38 +0100334 targetLiveAll = minions.join(' or ')
335 common.infoMsg("Found nodes: ${targetLiveAll}")
336 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100337 }
338
Jakub Josefa63f9862018-01-11 17:58:38 +0100339 stage('Confirm rollback on sample nodes') {
340 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 +0100341 }
342
Jakub Josefa63f9862018-01-11 17:58:38 +0100343 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100344
Jakub Josefa63f9862018-01-11 17:58:38 +0100345 try {
346 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
347 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
348 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
349 } catch (Exception er) {
350 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
351 throw er
352 }
Marek Celouda54924d2017-12-28 16:28:42 +0100353
Jakub Josefa63f9862018-01-11 17:58:38 +0100354 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
355 check = 'contrail-status'
356
357 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
358 salt.printSaltCommandResult(out)
359
360 try {
361 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
362 } catch (Exception er) {
363 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
364 }
365
366 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
367 //sleep(10)
368 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
369
370 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
371 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100372 }
373
Jakub Josefa63f9862018-01-11 17:58:38 +0100374 stage('Confirm rollback on all targeted nodes') {
375 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 +0100376 }
377
Jakub Josefa63f9862018-01-11 17:58:38 +0100378 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100379
Jakub Josefa63f9862018-01-11 17:58:38 +0100380 try {
381 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
382 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
383 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
384 } catch (Exception er) {
385 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
386 throw er
387 }
Marek Celouda54924d2017-12-28 16:28:42 +0100388
Jakub Josefa63f9862018-01-11 17:58:38 +0100389 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
390 check = 'contrail-status'
391
392 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
393 salt.printSaltCommandResult(out)
394
395 try {
396 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
397 } catch (Exception er) {
398 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
399 }
400
401 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
402 //sleep(10)
403 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
404
405 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
406 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100407 }
408
Jakub Josefa63f9862018-01-11 17:58:38 +0100409 } catch (Throwable e) {
410 // If there was an error or exception thrown, the build failed
411 currentBuild.result = "FAILURE"
412 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
413 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100414 }
Marek Celouda54924d2017-12-28 16:28:42 +0100415 }
416 }
417}