blob: 01adb0c2a689650176220efac12f3d783231acee [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'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +040096 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +010097 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
98 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
99 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
100
101 } catch (Exception er) {
102 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
103 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100104 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100105
Jakub Josefa63f9862018-01-11 17:58:38 +0100106 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
107 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
108
109 try {
110 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
111 } catch (Exception er) {
112 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
113 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100114 }
115
Jakub Josefa63f9862018-01-11 17:58:38 +0100116 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
117 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100118
Jakub Josefa63f9862018-01-11 17:58:38 +0100119 try {
120 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
121 } catch (Exception er) {
122 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
123 throw er
124 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400125
Jakub Josefa63f9862018-01-11 17:58:38 +0100126 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
127
128 try {
129 for (service in analyticsServices) {
130 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
131 }
132 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
133 if (result == false) {
134 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
135 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
136 }
137 check = 'doctrail all contrail-status'
138 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylova93106c2018-10-25 10:39:34 +0400139 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100140 } catch (Exception er) {
141 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
142 throw er
143 }
144 try {
145 check = 'doctrail all contrail-status'
146
147 for (service in configServices) {
148 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
149 }
150
151 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
152 if (result == false) {
153 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
154 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
155 }
156
157 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400158 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100159 }
160
Anton Samoylova93106c2018-10-25 10:39:34 +0400161 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100162
Anton Samoylova93106c2018-10-25 10:39:34 +0400163 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100164
165 sleep(120)
166
167 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400168 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100169 }
170
Anton Samoylova93106c2018-10-25 10:39:34 +0400171 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100172
Anton Samoylov049be7f2018-10-31 20:59:36 +0400173 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
174 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100175 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400176 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100177 } catch (Exception er) {
178 common.errorMsg("Opencontrail Controller failed to be upgraded.")
179 throw er
180 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400181 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100182
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400183 stage('Opencontrail controllers backup and cleanup') {
184 try {
185 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
186 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
187 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
188 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
189
190 for (service in (controlServices + thirdPartyServicesToDisable)) {
191 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
192 }
193 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
194 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
195 }
196
197 def tmpCfgBackupDir = '/tmp/cfg_backup'
198 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
199
200 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
201
202 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
203 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
204 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
205 }
206
207 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
208 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
209
210 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
211 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
212 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
213 }
214 } catch (Exception er) {
215 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
216 throw er
217 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100218 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100219 }
220
221
222 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
223
224 try {
225
226 stage('List targeted compute servers') {
227 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
228
229 if (minions.isEmpty()) {
230 throw new Exception("No minion was targeted")
231 }
232
233 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
234 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
235
236 targetLiveAll = minions.join(' or ')
237 common.infoMsg("Found nodes: ${targetLiveAll}")
238 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
239 }
240
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400241 stage('Compute nodes health check') {
242 try {
243 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
244 } catch (Exception er) {
245 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
246 throw er
247 }
248 }
249
Jakub Josefa63f9862018-01-11 17:58:38 +0100250 stage('Confirm upgrade on sample nodes') {
251 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
252 }
253
254 stage("Opencontrail compute upgrade on sample nodes") {
255
256 try {
257 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
258 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
259 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
260 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
261 } catch (Exception er) {
262 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
263 throw er
264 }
265
266 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
267 check = 'contrail-status'
268
269 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
270 salt.printSaltCommandResult(out)
271
272 try {
273 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
274 } catch (Exception er) {
275 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
276 }
277
278 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
279
280 //sleep(10)
281 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
282
283 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
284 salt.printSaltCommandResult(out)
285 }
286
287 stage('Confirm upgrade on all targeted nodes') {
288 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
289 }
290 stage("Opencontrail compute upgrade on all targeted nodes") {
291
292 try {
293 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
294 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
295 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
296 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
297 } catch (Exception er) {
298 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
299 throw er
300 }
301
302 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
303 check = 'contrail-status'
304
305 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
306 salt.printSaltCommandResult(out)
307
308 try {
309 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
310 } catch (Exception er) {
311 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
312 }
313
314 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
315 //sleep(10)
316 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
317
318 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
319 salt.printSaltCommandResult(out)
320 }
321
322 } catch (Throwable e) {
323 // If there was an error or exception thrown, the build failed
324 currentBuild.result = "FAILURE"
325 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
326 throw e
327 }
328 }
329
330
331 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
332
333 stage('Ask for manual confirmation') {
334 input message: "Do you want to continue with the Opencontrail nodes rollback?"
335 }
336
337 stage('Opencontrail controllers rollback') {
338
Anton Samoylov049be7f2018-10-31 20:59:36 +0400339 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
340 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100341 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
342
343 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400344 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100345
Anton Samoylova93106c2018-10-25 10:39:34 +0400346 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 +0100347 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400348 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100349 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400350 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100351
352 check = 'contrail-status'
Anton Samoylova93106c2018-10-25 10:39:34 +0400353 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100354
355 sleep(120)
356
Anton Samoylova93106c2018-10-25 10:39:34 +0400357 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
358 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400359
360 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
361 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
362 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
363 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
364 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
365 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
366
367 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400368 for (service in (controlServices + thirdPartyServicesToDisable)) {
369 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
370 }
371 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
372 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
373 }
Marek Celouda54924d2017-12-28 16:28:42 +0100374 }
Marek Celouda54924d2017-12-28 16:28:42 +0100375 }
376
Jakub Josefa63f9862018-01-11 17:58:38 +0100377 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100378
Jakub Josefa63f9862018-01-11 17:58:38 +0100379 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100380
Jakub Josefa63f9862018-01-11 17:58:38 +0100381 stage('List targeted compute servers') {
382 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100383
Jakub Josefa63f9862018-01-11 17:58:38 +0100384 if (minions.isEmpty()) {
385 throw new Exception("No minion was targeted")
386 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100387
Jakub Josefa63f9862018-01-11 17:58:38 +0100388 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
389 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100390
Jakub Josefa63f9862018-01-11 17:58:38 +0100391 targetLiveAll = minions.join(' or ')
392 common.infoMsg("Found nodes: ${targetLiveAll}")
393 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100394 }
395
Jakub Josefa63f9862018-01-11 17:58:38 +0100396 stage('Confirm rollback on sample nodes') {
397 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 +0100398 }
399
Jakub Josefa63f9862018-01-11 17:58:38 +0100400 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100401
Jakub Josefa63f9862018-01-11 17:58:38 +0100402 try {
403 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
404 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
405 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
406 } catch (Exception er) {
407 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
408 throw er
409 }
Marek Celouda54924d2017-12-28 16:28:42 +0100410
Jakub Josefa63f9862018-01-11 17:58:38 +0100411 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
412 check = 'contrail-status'
413
414 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
415 salt.printSaltCommandResult(out)
416
417 try {
418 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
419 } catch (Exception er) {
420 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
421 }
422
423 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
424 //sleep(10)
425 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
426
427 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
428 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100429 }
430
Jakub Josefa63f9862018-01-11 17:58:38 +0100431 stage('Confirm rollback on all targeted nodes') {
432 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 +0100433 }
434
Jakub Josefa63f9862018-01-11 17:58:38 +0100435 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100436
Jakub Josefa63f9862018-01-11 17:58:38 +0100437 try {
438 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
439 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
440 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
441 } catch (Exception er) {
442 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
443 throw er
444 }
Marek Celouda54924d2017-12-28 16:28:42 +0100445
Jakub Josefa63f9862018-01-11 17:58:38 +0100446 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
447 check = 'contrail-status'
448
449 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
450 salt.printSaltCommandResult(out)
451
452 try {
453 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
454 } catch (Exception er) {
455 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
456 }
457
458 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
459 //sleep(10)
460 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
461
462 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
463 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100464 }
465
Jakub Josefa63f9862018-01-11 17:58:38 +0100466 } catch (Throwable e) {
467 // If there was an error or exception thrown, the build failed
468 currentBuild.result = "FAILURE"
469 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
470 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100471 }
Marek Celouda54924d2017-12-28 16:28:42 +0100472 }
473 }
474}