blob: f2531441b36ebd5b3b88824260be65c14b6fdccf [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
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 {
Anton Samoylova93106c2018-10-25 10:39:34 +040080 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail_api:service:controller:image")
81 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analytics:image")
82 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
Jakub Josefa63f9862018-01-11 17:58:38 +010083 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')
Anton Samoylova93106c2018-10-25 10:39:34 +0400127 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100128 } 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) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400146 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 }
148
Anton Samoylova93106c2018-10-25 10:39:34 +0400149 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100150
Anton Samoylova93106c2018-10-25 10:39:34 +0400151 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100152
153 sleep(120)
154
155 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400156 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100157 }
158
Anton Samoylova93106c2018-10-25 10:39:34 +0400159 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100160
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 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400167 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100168
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400169 stage('Opencontrail controllers backup and cleanup') {
170 try {
171 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
172 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
173 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
174 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
175
176 for (service in (controlServices + thirdPartyServicesToDisable)) {
177 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
178 }
179 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
180 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
181 }
182
183 def tmpCfgBackupDir = '/tmp/cfg_backup'
184 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
185
186 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
187
188 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
189 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
190 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
191 }
192
193 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
194 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
195
196 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
197 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
198 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
199 }
200 } catch (Exception er) {
201 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
202 throw er
203 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100204 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100205 }
206
207
208 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
209
210 try {
211
212 stage('List targeted compute servers') {
213 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
214
215 if (minions.isEmpty()) {
216 throw new Exception("No minion was targeted")
217 }
218
219 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
220 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
221
222 targetLiveAll = minions.join(' or ')
223 common.infoMsg("Found nodes: ${targetLiveAll}")
224 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
225 }
226
227 stage('Confirm upgrade on sample nodes') {
228 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
229 }
230
231 stage("Opencontrail compute upgrade on sample nodes") {
232
233 try {
234 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
235 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
236 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
237 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
238 } catch (Exception er) {
239 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
240 throw er
241 }
242
243 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
244 check = 'contrail-status'
245
246 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
247 salt.printSaltCommandResult(out)
248
249 try {
250 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
251 } catch (Exception er) {
252 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
253 }
254
255 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
256
257 //sleep(10)
258 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
259
260 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
261 salt.printSaltCommandResult(out)
262 }
263
264 stage('Confirm upgrade on all targeted nodes') {
265 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
266 }
267 stage("Opencontrail compute upgrade on all targeted nodes") {
268
269 try {
270 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
271 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
272 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
273 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
274 } catch (Exception er) {
275 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
276 throw er
277 }
278
279 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
280 check = 'contrail-status'
281
282 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
283 salt.printSaltCommandResult(out)
284
285 try {
286 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
287 } catch (Exception er) {
288 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
289 }
290
291 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
292 //sleep(10)
293 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
294
295 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
296 salt.printSaltCommandResult(out)
297 }
298
299 } catch (Throwable e) {
300 // If there was an error or exception thrown, the build failed
301 currentBuild.result = "FAILURE"
302 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
303 throw e
304 }
305 }
306
307
308 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
309
310 stage('Ask for manual confirmation') {
311 input message: "Do you want to continue with the Opencontrail nodes rollback?"
312 }
313
314 stage('Opencontrail controllers rollback') {
315
316 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true)
317 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo')
318 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
319
320 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
321
Anton Samoylova93106c2018-10-25 10:39:34 +0400322 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 +0100323 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400324 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100325 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400326 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100327
328 check = 'contrail-status'
Anton Samoylova93106c2018-10-25 10:39:34 +0400329 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100330
331 sleep(120)
332
Anton Samoylova93106c2018-10-25 10:39:34 +0400333 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
334 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400335 for (service in (controlServices + thirdPartyServicesToDisable)) {
336 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
337 }
338 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
339 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
340 }
Marek Celouda54924d2017-12-28 16:28:42 +0100341 }
Marek Celouda54924d2017-12-28 16:28:42 +0100342 }
343
Jakub Josefa63f9862018-01-11 17:58:38 +0100344 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100345
Jakub Josefa63f9862018-01-11 17:58:38 +0100346 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100347
Jakub Josefa63f9862018-01-11 17:58:38 +0100348 stage('List targeted compute servers') {
349 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100350
Jakub Josefa63f9862018-01-11 17:58:38 +0100351 if (minions.isEmpty()) {
352 throw new Exception("No minion was targeted")
353 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100354
Jakub Josefa63f9862018-01-11 17:58:38 +0100355 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
356 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100357
Jakub Josefa63f9862018-01-11 17:58:38 +0100358 targetLiveAll = minions.join(' or ')
359 common.infoMsg("Found nodes: ${targetLiveAll}")
360 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100361 }
362
Jakub Josefa63f9862018-01-11 17:58:38 +0100363 stage('Confirm rollback on sample nodes') {
364 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 +0100365 }
366
Jakub Josefa63f9862018-01-11 17:58:38 +0100367 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100368
Jakub Josefa63f9862018-01-11 17:58:38 +0100369 try {
370 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
371 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
372 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
373 } catch (Exception er) {
374 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
375 throw er
376 }
Marek Celouda54924d2017-12-28 16:28:42 +0100377
Jakub Josefa63f9862018-01-11 17:58:38 +0100378 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
379 check = 'contrail-status'
380
381 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
382 salt.printSaltCommandResult(out)
383
384 try {
385 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
386 } catch (Exception er) {
387 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
388 }
389
390 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
391 //sleep(10)
392 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
393
394 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
395 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100396 }
397
Jakub Josefa63f9862018-01-11 17:58:38 +0100398 stage('Confirm rollback on all targeted nodes') {
399 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 +0100400 }
401
Jakub Josefa63f9862018-01-11 17:58:38 +0100402 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100403
Jakub Josefa63f9862018-01-11 17:58:38 +0100404 try {
405 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
406 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
407 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
408 } catch (Exception er) {
409 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
410 throw er
411 }
Marek Celouda54924d2017-12-28 16:28:42 +0100412
Jakub Josefa63f9862018-01-11 17:58:38 +0100413 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
414 check = 'contrail-status'
415
416 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
417 salt.printSaltCommandResult(out)
418
419 try {
420 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
421 } catch (Exception er) {
422 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
423 }
424
425 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
426 //sleep(10)
427 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
428
429 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
430 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100431 }
432
Jakub Josefa63f9862018-01-11 17:58:38 +0100433 } catch (Throwable e) {
434 // If there was an error or exception thrown, the build failed
435 currentBuild.result = "FAILURE"
436 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
437 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100438 }
Marek Celouda54924d2017-12-28 16:28:42 +0100439 }
440 }
441}