blob: 8f0543c4d6147edaa29899d0e590dc95ee192874 [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 Samoylov049be7f2018-10-31 20:59:36 +040034def neutronServerPkgs = 'neutron-plugin-contrail,contrail-heat,python-contrail'
35def dashboardPanelPkg = 'openstack-dashboard-contrail-panels'
Anton Samoylovaaf1ff22018-09-27 10:46:43 +040036def 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 +040037def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper', 'redis-server']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010038def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper']
Anton Samoylovf6b498d2018-09-19 13:10:34 +040039def controlServices = ['ifmap-server', 'supervisor-control', 'redis-server']
40def thirdPartyServicesToDisable = ['kafka', 'zookeeper', 'cassandra']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010041def 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 +010042
43def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) {
44
45 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
46 salt.printSaltCommandResult(out)
47 // wait until $check is in correct state
48 if ( check == "nodetool status" ) {
49 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
50 } else if ( check == "doctrail all contrail-status" ) {
Marek Celoud8d6ddd82018-01-03 17:56:05 +010051 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)
52 } else if ( check == "contrail-status" ) {
53 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 +010054 }
Marek Celouda54924d2017-12-28 16:28:42 +010055 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
56 //salt.printSaltCommandResult(out)
57 //input message: "Please check the output of \'${check}\' and continue if it is correct."
58}
Jakub Josefa63f9862018-01-11 17:58:38 +010059timeout(time: 12, unit: 'HOURS') {
60 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010061
Jakub Josefa63f9862018-01-11 17:58:38 +010062 stage('Setup virtualenv for Pepper') {
63 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
64 }
Marek Celouda54924d2017-12-28 16:28:42 +010065
Jakub Josefa63f9862018-01-11 17:58:38 +010066 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010067
Anton Samoylov97ce9b82018-10-19 00:43:54 +040068 stage('Opencontrail controllers health check') {
69 try {
70 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
71 } catch (Exception er) {
72 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
73 throw er
74 }
75 }
76
Jakub Josefa63f9862018-01-11 17:58:38 +010077 stage('Opencontrail controllers upgrade') {
78 try {
Anton Samoylov049be7f2018-10-31 20:59:36 +040079 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
80 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.sync_all', [], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010081 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
82 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
Anton Samoylov049be7f2018-10-31 20:59:36 +040083 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010084
Jakub Josefa63f9862018-01-11 17:58:38 +010085 } catch (Exception er) {
Anton Samoylov049be7f2018-10-31 20:59:36 +040086 common.errorMsg("Opencontrail component on I@opencontrail:control, I@opencontrail:collector, I@neutron:server or I@horizon:server probably failed to be replaced.")
Jakub Josefa63f9862018-01-11 17:58:38 +010087 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010088 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010089
Jakub Josefa63f9862018-01-11 17:58:38 +010090 try {
Anton Samoylova93106c2018-10-25 10:39:34 +040091 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail_api:service:controller:image")
92 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analytics:image")
93 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
Jakub Josefa63f9862018-01-11 17:58:38 +010094 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
95 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
96 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
97 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
98 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
99
100 } catch (Exception er) {
101 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
102 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100103 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100104
Jakub Josefa63f9862018-01-11 17:58:38 +0100105 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
106 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
107
108 try {
109 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
110 } catch (Exception er) {
111 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
112 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100113 }
114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
116 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100117
Jakub Josefa63f9862018-01-11 17:58:38 +0100118 try {
119 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
120 } catch (Exception er) {
121 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
122 throw er
123 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400124
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
126
127 try {
128 for (service in analyticsServices) {
129 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
130 }
131 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
132 if (result == false) {
133 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
134 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
135 }
136 check = 'doctrail all contrail-status'
137 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylova93106c2018-10-25 10:39:34 +0400138 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 } catch (Exception er) {
140 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
141 throw er
142 }
143 try {
144 check = 'doctrail all contrail-status'
145
146 for (service in configServices) {
147 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
148 }
149
150 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
151 if (result == false) {
152 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
153 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
154 }
155
156 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400157 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100158 }
159
Anton Samoylova93106c2018-10-25 10:39:34 +0400160 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100161
Anton Samoylova93106c2018-10-25 10:39:34 +0400162 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100163
164 sleep(120)
165
166 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400167 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 }
169
Anton Samoylova93106c2018-10-25 10:39:34 +0400170 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100171
Anton Samoylov049be7f2018-10-31 20:59:36 +0400172 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
173 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400175 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 } catch (Exception er) {
177 common.errorMsg("Opencontrail Controller failed to be upgraded.")
178 throw er
179 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400180 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100181
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400182 stage('Opencontrail controllers backup and cleanup') {
183 try {
184 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
185 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
186 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
187 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
188
189 for (service in (controlServices + thirdPartyServicesToDisable)) {
190 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
191 }
192 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
193 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
194 }
195
196 def tmpCfgBackupDir = '/tmp/cfg_backup'
197 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
198
199 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
200
201 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
202 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
203 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
204 }
205
206 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
207 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
208
209 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
210 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
211 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
212 }
213 } catch (Exception er) {
214 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
215 throw er
216 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100217 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100218 }
219
220
221 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
222
223 try {
224
225 stage('List targeted compute servers') {
226 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
227
228 if (minions.isEmpty()) {
229 throw new Exception("No minion was targeted")
230 }
231
232 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
233 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
234
235 targetLiveAll = minions.join(' or ')
236 common.infoMsg("Found nodes: ${targetLiveAll}")
237 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
238 }
239
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400240 stage('Compute nodes health check') {
241 try {
242 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
243 } catch (Exception er) {
244 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
245 throw er
246 }
247 }
248
Jakub Josefa63f9862018-01-11 17:58:38 +0100249 stage('Confirm upgrade on sample nodes') {
250 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
251 }
252
253 stage("Opencontrail compute upgrade on sample nodes") {
254
255 try {
256 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
257 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
258 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
259 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
260 } catch (Exception er) {
261 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
262 throw er
263 }
264
265 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
266 check = 'contrail-status'
267
268 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
269 salt.printSaltCommandResult(out)
270
271 try {
272 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
273 } catch (Exception er) {
274 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
275 }
276
277 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
278
279 //sleep(10)
280 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
281
282 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
283 salt.printSaltCommandResult(out)
284 }
285
286 stage('Confirm upgrade on all targeted nodes') {
287 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
288 }
289 stage("Opencontrail compute upgrade on all targeted nodes") {
290
291 try {
292 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
293 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
294 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
295 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
296 } catch (Exception er) {
297 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
298 throw er
299 }
300
301 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
302 check = 'contrail-status'
303
304 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
305 salt.printSaltCommandResult(out)
306
307 try {
308 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
309 } catch (Exception er) {
310 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
311 }
312
313 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
314 //sleep(10)
315 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
316
317 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
318 salt.printSaltCommandResult(out)
319 }
320
321 } catch (Throwable e) {
322 // If there was an error or exception thrown, the build failed
323 currentBuild.result = "FAILURE"
324 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
325 throw e
326 }
327 }
328
329
330 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
331
332 stage('Ask for manual confirmation') {
333 input message: "Do you want to continue with the Opencontrail nodes rollback?"
334 }
335
336 stage('Opencontrail controllers rollback') {
337
Anton Samoylov049be7f2018-10-31 20:59:36 +0400338 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
339 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100340 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
341
342 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
343
Anton Samoylova93106c2018-10-25 10:39:34 +0400344 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 +0100345 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400346 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100347 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400348 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100349
350 check = 'contrail-status'
Anton Samoylova93106c2018-10-25 10:39:34 +0400351 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100352
353 sleep(120)
354
Anton Samoylova93106c2018-10-25 10:39:34 +0400355 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
356 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400357
358 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
359 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
360 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
361 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
362 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
363 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
364
365 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400366 for (service in (controlServices + thirdPartyServicesToDisable)) {
367 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
368 }
369 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
370 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
371 }
Marek Celouda54924d2017-12-28 16:28:42 +0100372 }
Marek Celouda54924d2017-12-28 16:28:42 +0100373 }
374
Jakub Josefa63f9862018-01-11 17:58:38 +0100375 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100376
Jakub Josefa63f9862018-01-11 17:58:38 +0100377 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100378
Jakub Josefa63f9862018-01-11 17:58:38 +0100379 stage('List targeted compute servers') {
380 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100381
Jakub Josefa63f9862018-01-11 17:58:38 +0100382 if (minions.isEmpty()) {
383 throw new Exception("No minion was targeted")
384 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100385
Jakub Josefa63f9862018-01-11 17:58:38 +0100386 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
387 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100388
Jakub Josefa63f9862018-01-11 17:58:38 +0100389 targetLiveAll = minions.join(' or ')
390 common.infoMsg("Found nodes: ${targetLiveAll}")
391 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100392 }
393
Jakub Josefa63f9862018-01-11 17:58:38 +0100394 stage('Confirm rollback on sample nodes') {
395 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 +0100396 }
397
Jakub Josefa63f9862018-01-11 17:58:38 +0100398 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100399
Jakub Josefa63f9862018-01-11 17:58:38 +0100400 try {
401 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
402 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
403 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
404 } catch (Exception er) {
405 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
406 throw er
407 }
Marek Celouda54924d2017-12-28 16:28:42 +0100408
Jakub Josefa63f9862018-01-11 17:58:38 +0100409 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
410 check = 'contrail-status'
411
412 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
413 salt.printSaltCommandResult(out)
414
415 try {
416 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
417 } catch (Exception er) {
418 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
419 }
420
421 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
422 //sleep(10)
423 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
424
425 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
426 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100427 }
428
Jakub Josefa63f9862018-01-11 17:58:38 +0100429 stage('Confirm rollback on all targeted nodes') {
430 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 +0100431 }
432
Jakub Josefa63f9862018-01-11 17:58:38 +0100433 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100434
Jakub Josefa63f9862018-01-11 17:58:38 +0100435 try {
436 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
437 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
438 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
439 } catch (Exception er) {
440 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
441 throw er
442 }
Marek Celouda54924d2017-12-28 16:28:42 +0100443
Jakub Josefa63f9862018-01-11 17:58:38 +0100444 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
445 check = 'contrail-status'
446
447 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
448 salt.printSaltCommandResult(out)
449
450 try {
451 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
452 } catch (Exception er) {
453 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
454 }
455
456 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
457 //sleep(10)
458 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
459
460 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
461 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100462 }
463
Jakub Josefa63f9862018-01-11 17:58:38 +0100464 } catch (Throwable e) {
465 // If there was an error or exception thrown, the build failed
466 currentBuild.result = "FAILURE"
467 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
468 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100469 }
Marek Celouda54924d2017-12-28 16:28:42 +0100470 }
471 }
472}