blob: 76243e525d215fbd41d0c5e45276734cd879f9ba [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'
29def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,python-contrail,contrail-database'
30//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']
31def 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'
32def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;'
33def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010034def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper']
35def controlServices = ['ifmap-server', 'supervisor-control']
36def 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 +010037
38def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) {
39
40 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
41 salt.printSaltCommandResult(out)
42 // wait until $check is in correct state
43 if ( check == "nodetool status" ) {
44 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
45 } else if ( check == "doctrail all contrail-status" ) {
Marek Celoud8d6ddd82018-01-03 17:56:05 +010046 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)
47 } else if ( check == "contrail-status" ) {
48 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 +010049 }
Marek Celouda54924d2017-12-28 16:28:42 +010050 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
51 //salt.printSaltCommandResult(out)
52 //input message: "Please check the output of \'${check}\' and continue if it is correct."
53}
Jakub Josefa63f9862018-01-11 17:58:38 +010054timeout(time: 12, unit: 'HOURS') {
55 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010056
Jakub Josefa63f9862018-01-11 17:58:38 +010057 stage('Setup virtualenv for Pepper') {
58 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
59 }
Marek Celouda54924d2017-12-28 16:28:42 +010060
Jakub Josefa63f9862018-01-11 17:58:38 +010061 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010062
Jakub Josefa63f9862018-01-11 17:58:38 +010063 stage('Opencontrail controllers upgrade') {
64 try {
65 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
66 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.sync_all', [], null, true)
67 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
68 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
69 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010070
Jakub Josefa63f9862018-01-11 17:58:38 +010071 } catch (Exception er) {
72 common.errorMsg("Opencontrail component on I@opencontrail:control or I@opencontrail:collector or I@neutron:server probably failed to be replaced.")
73 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010074 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010075
Jakub Josefa63f9862018-01-11 17:58:38 +010076 try {
77 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control and *01*", "docker:client:compose:opencontrail_api:service:controller:image")
78 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analytics:image")
79 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
80 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
81 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
82 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
83 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
84 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
85
86 } catch (Exception er) {
87 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
88 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010089 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010090
Jakub Josefa63f9862018-01-11 17:58:38 +010091 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
92 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
93
94 try {
95 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
96 } catch (Exception er) {
97 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
98 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +010099 }
100
Jakub Josefa63f9862018-01-11 17:58:38 +0100101 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
102 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100103
Jakub Josefa63f9862018-01-11 17:58:38 +0100104 try {
105 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
106 } catch (Exception er) {
107 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
108 throw er
109 }
110
111 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
112
113 try {
114 for (service in analyticsServices) {
115 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
116 }
117 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
118 if (result == false) {
119 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
120 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
121 }
122 check = 'doctrail all contrail-status'
123 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
124 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
125 } catch (Exception er) {
126 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
127 throw er
128 }
129 try {
130 check = 'doctrail all contrail-status'
131
132 for (service in configServices) {
133 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
134 }
135
136 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
137 if (result == false) {
138 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
139 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
140 }
141
142 for (service in controlServices) {
143 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'service.stop', [service])
144 }
145
146 salt.enforceState(pepperEnv, 'I@opencontrail:control and *0[23]*', 'docker.client')
147
148 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
149
150 sleep(120)
151
152 for (service in controlServices) {
153 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'service.stop', [service])
154 }
155
156 salt.enforceState(pepperEnv, 'I@opencontrail:control and *01*', 'docker.client')
157
158 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', ['neutron-plugin-contrail,contrail-heat,python-contrail'])
159 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
160 } catch (Exception er) {
161 common.errorMsg("Opencontrail Controller failed to be upgraded.")
162 throw er
163 }
164
165 }
166 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
167 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
168 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
169 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
170 //salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs])
171 //salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs])
172 for (service in controlServices) {
173 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
174 }
175 for (service in analyticsServices) {
176 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
177 }
178 }
179
180
181 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
182
183 try {
184
185 stage('List targeted compute servers') {
186 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
187
188 if (minions.isEmpty()) {
189 throw new Exception("No minion was targeted")
190 }
191
192 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
193 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
194
195 targetLiveAll = minions.join(' or ')
196 common.infoMsg("Found nodes: ${targetLiveAll}")
197 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
198 }
199
200 stage('Confirm upgrade on sample nodes') {
201 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
202 }
203
204 stage("Opencontrail compute upgrade on sample nodes") {
205
206 try {
207 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
208 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
209 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
210 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
211 } catch (Exception er) {
212 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
213 throw er
214 }
215
216 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
217 check = 'contrail-status'
218
219 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
220 salt.printSaltCommandResult(out)
221
222 try {
223 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
224 } catch (Exception er) {
225 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
226 }
227
228 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
229
230 //sleep(10)
231 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
232
233 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
234 salt.printSaltCommandResult(out)
235 }
236
237 stage('Confirm upgrade on all targeted nodes') {
238 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
239 }
240 stage("Opencontrail compute upgrade on all targeted nodes") {
241
242 try {
243 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
244 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
245 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
246 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
247 } catch (Exception er) {
248 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
249 throw er
250 }
251
252 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
253 check = 'contrail-status'
254
255 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
256 salt.printSaltCommandResult(out)
257
258 try {
259 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
260 } catch (Exception er) {
261 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
262 }
263
264 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
265 //sleep(10)
266 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
267
268 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
269 salt.printSaltCommandResult(out)
270 }
271
272 } catch (Throwable e) {
273 // If there was an error or exception thrown, the build failed
274 currentBuild.result = "FAILURE"
275 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
276 throw e
277 }
278 }
279
280
281 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
282
283 stage('Ask for manual confirmation') {
284 input message: "Do you want to continue with the Opencontrail nodes rollback?"
285 }
286
287 stage('Opencontrail controllers rollback') {
288
289 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true)
290 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo')
291 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
292
293 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
294
295 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
296 for (service in config4Services) {
297 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
298 }
299 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
300
301 check = 'contrail-status'
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100302 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
303
304 sleep(120)
305
Jakub Josefa63f9862018-01-11 17:58:38 +0100306 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
307 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Marek Celouda54924d2017-12-28 16:28:42 +0100308 }
Marek Celouda54924d2017-12-28 16:28:42 +0100309 }
310
Jakub Josefa63f9862018-01-11 17:58:38 +0100311 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100312
Jakub Josefa63f9862018-01-11 17:58:38 +0100313 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100314
Jakub Josefa63f9862018-01-11 17:58:38 +0100315 stage('List targeted compute servers') {
316 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100317
Jakub Josefa63f9862018-01-11 17:58:38 +0100318 if (minions.isEmpty()) {
319 throw new Exception("No minion was targeted")
320 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100321
Jakub Josefa63f9862018-01-11 17:58:38 +0100322 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
323 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100324
Jakub Josefa63f9862018-01-11 17:58:38 +0100325 targetLiveAll = minions.join(' or ')
326 common.infoMsg("Found nodes: ${targetLiveAll}")
327 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100328 }
329
Jakub Josefa63f9862018-01-11 17:58:38 +0100330 stage('Confirm rollback on sample nodes') {
331 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 +0100332 }
333
Jakub Josefa63f9862018-01-11 17:58:38 +0100334 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100335
Jakub Josefa63f9862018-01-11 17:58:38 +0100336 try {
337 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
338 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
339 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
340 } catch (Exception er) {
341 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
342 throw er
343 }
Marek Celouda54924d2017-12-28 16:28:42 +0100344
Jakub Josefa63f9862018-01-11 17:58:38 +0100345 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
346 check = 'contrail-status'
347
348 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
349 salt.printSaltCommandResult(out)
350
351 try {
352 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
353 } catch (Exception er) {
354 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
355 }
356
357 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
358 //sleep(10)
359 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
360
361 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
362 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100363 }
364
Jakub Josefa63f9862018-01-11 17:58:38 +0100365 stage('Confirm rollback on all targeted nodes') {
366 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 +0100367 }
368
Jakub Josefa63f9862018-01-11 17:58:38 +0100369 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100370
Jakub Josefa63f9862018-01-11 17:58:38 +0100371 try {
372 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
373 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
374 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
375 } catch (Exception er) {
376 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
377 throw er
378 }
Marek Celouda54924d2017-12-28 16:28:42 +0100379
Jakub Josefa63f9862018-01-11 17:58:38 +0100380 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
381 check = 'contrail-status'
382
383 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
384 salt.printSaltCommandResult(out)
385
386 try {
387 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
388 } catch (Exception er) {
389 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
390 }
391
392 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
393 //sleep(10)
394 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
395
396 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
397 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100398 }
399
Jakub Josefa63f9862018-01-11 17:58:38 +0100400 } catch (Throwable e) {
401 // If there was an error or exception thrown, the build failed
402 currentBuild.result = "FAILURE"
403 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
404 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100405 }
Marek Celouda54924d2017-12-28 16:28:42 +0100406 }
407 }
408}