blob: 63cb5b47b270019cac8c58398bc1a9370cd89184 [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'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040032def 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'
Anton Samoylov049be7f2018-10-31 20:59:36 +040033def neutronServerPkgs = 'neutron-plugin-contrail,contrail-heat,python-contrail'
34def dashboardPanelPkg = 'openstack-dashboard-contrail-panels'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040035def kernelModuleReloadCmd = '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 +040036def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper', 'redis-server']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010037def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper']
Anton Samoylovf6b498d2018-09-19 13:10:34 +040038def controlServices = ['ifmap-server', 'supervisor-control', 'redis-server']
39def thirdPartyServicesToDisable = ['kafka', 'zookeeper', 'cassandra']
Marek Celoud8d6ddd82018-01-03 17:56:05 +010040def 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 +010041
Anton Samoylov0dd88f42018-10-18 16:37:04 +040042def runCommonCommands(target, command, args, check, salt, pepperEnv) {
Marek Celouda54924d2017-12-28 16:28:42 +010043
44 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
45 salt.printSaltCommandResult(out)
46 // wait until $check is in correct state
47 if ( check == "nodetool status" ) {
48 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
49 } else if ( check == "doctrail all contrail-status" ) {
Marek Celoud8d6ddd82018-01-03 17:56:05 +010050 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)
51 } else if ( check == "contrail-status" ) {
52 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 +010053 }
Marek Celouda54924d2017-12-28 16:28:42 +010054}
Jakub Josefa63f9862018-01-11 17:58:38 +010055timeout(time: 12, unit: 'HOURS') {
56 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010057
Jakub Josefa63f9862018-01-11 17:58:38 +010058 stage('Setup virtualenv for Pepper') {
59 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
60 }
Marek Celouda54924d2017-12-28 16:28:42 +010061
Jakub Josefa63f9862018-01-11 17:58:38 +010062 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010063
Anton Samoylov97ce9b82018-10-19 00:43:54 +040064 stage('Opencontrail controllers health check') {
65 try {
66 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
67 } catch (Exception er) {
68 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
69 throw er
70 }
71 }
72
Jakub Josefa63f9862018-01-11 17:58:38 +010073 stage('Opencontrail controllers upgrade') {
74 try {
Anton Samoylov049be7f2018-10-31 20:59:36 +040075 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
76 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 +010077 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
78 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
Anton Samoylov049be7f2018-10-31 20:59:36 +040079 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +010080
Jakub Josefa63f9862018-01-11 17:58:38 +010081 } catch (Exception er) {
Anton Samoylov049be7f2018-10-31 20:59:36 +040082 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 +010083 throw er
Marek Celouda54924d2017-12-28 16:28:42 +010084 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +010085
Jakub Josefa63f9862018-01-11 17:58:38 +010086 try {
Anton Samoylova93106c2018-10-25 10:39:34 +040087 controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail_api:service:controller:image")
88 analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analytics:image")
89 analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analyticsdb:image")
Jakub Josefa63f9862018-01-11 17:58:38 +010090 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
91 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +040092 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +010093 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
94 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
95 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
96
97 } catch (Exception er) {
98 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
99 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100100 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100101
Jakub Josefa63f9862018-01-11 17:58:38 +0100102 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
103 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
104
105 try {
106 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
107 } catch (Exception er) {
108 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
109 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100110 }
111
Jakub Josefa63f9862018-01-11 17:58:38 +0100112 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
113 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100114
Jakub Josefa63f9862018-01-11 17:58:38 +0100115 try {
116 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
117 } catch (Exception er) {
118 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
119 throw er
120 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400121
Jakub Josefa63f9862018-01-11 17:58:38 +0100122 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
123
124 try {
125 for (service in analyticsServices) {
126 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
127 }
128 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
129 if (result == false) {
130 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
131 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
132 }
133 check = 'doctrail all contrail-status'
134 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400135 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv)
Jakub Josefa63f9862018-01-11 17:58:38 +0100136 } catch (Exception er) {
137 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
138 throw er
139 }
140 try {
141 check = 'doctrail all contrail-status'
142
143 for (service in configServices) {
144 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
145 }
146
147 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
148 if (result == false) {
149 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
150 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
151 }
152
153 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400154 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100155 }
156
Anton Samoylova93106c2018-10-25 10:39:34 +0400157 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100158
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400159 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv)
Jakub Josefa63f9862018-01-11 17:58:38 +0100160
161 sleep(120)
162
163 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400164 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100165 }
166
Anton Samoylova93106c2018-10-25 10:39:34 +0400167 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Jakub Josefa63f9862018-01-11 17:58:38 +0100168
Anton Samoylov049be7f2018-10-31 20:59:36 +0400169 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
170 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100171 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400172 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100173 } catch (Exception er) {
174 common.errorMsg("Opencontrail Controller failed to be upgraded.")
175 throw er
176 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400177 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100178
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400179 stage('Opencontrail controllers backup and cleanup') {
180 try {
181 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
182 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
183 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
184 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
185
186 for (service in (controlServices + thirdPartyServicesToDisable)) {
187 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
188 }
189 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
190 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
191 }
192
193 def tmpCfgBackupDir = '/tmp/cfg_backup'
194 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
195
196 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
197
198 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
199 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
200 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
201 }
202
203 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
204 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
205
206 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
207 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
208 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
209 }
210 } catch (Exception er) {
211 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
212 throw er
213 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100214 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100215 }
216
217
218 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
219
220 try {
221
222 stage('List targeted compute servers') {
223 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
224
225 if (minions.isEmpty()) {
226 throw new Exception("No minion was targeted")
227 }
228
229 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
230 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
231
232 targetLiveAll = minions.join(' or ')
233 common.infoMsg("Found nodes: ${targetLiveAll}")
234 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
235 }
236
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400237 stage('Compute nodes health check') {
238 try {
239 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
240 } catch (Exception er) {
241 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
242 throw er
243 }
244 }
245
Jakub Josefa63f9862018-01-11 17:58:38 +0100246 stage('Confirm upgrade on sample nodes') {
247 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
248 }
249
250 stage("Opencontrail compute upgrade on sample nodes") {
251
252 try {
253 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
254 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
255 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
256 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
257 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400258 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100259 throw er
260 }
261
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400262 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100263 check = 'contrail-status'
264
265 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
266 salt.printSaltCommandResult(out)
267
268 try {
269 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
270 } catch (Exception er) {
271 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
272 }
273
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400274 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100275
276 //sleep(10)
277 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
278
279 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
280 salt.printSaltCommandResult(out)
281 }
282
283 stage('Confirm upgrade on all targeted nodes') {
284 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
285 }
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400286
Jakub Josefa63f9862018-01-11 17:58:38 +0100287 stage("Opencontrail compute upgrade on all targeted nodes") {
288
289 try {
290 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
291 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
292 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
293 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
294 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400295 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100296 throw er
297 }
298
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400299 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100300 check = 'contrail-status'
301
302 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
303 salt.printSaltCommandResult(out)
304
305 try {
306 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
307 } catch (Exception er) {
308 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
309 }
310
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400311 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100312 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
313
314 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
315 salt.printSaltCommandResult(out)
316 }
317
318 } catch (Throwable e) {
319 // If there was an error or exception thrown, the build failed
320 currentBuild.result = "FAILURE"
321 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
322 throw e
323 }
324 }
325
326
327 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
328
329 stage('Ask for manual confirmation') {
330 input message: "Do you want to continue with the Opencontrail nodes rollback?"
331 }
332
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400333 stage('Opencontrail controllers rollback') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100334
Anton Samoylov049be7f2018-10-31 20:59:36 +0400335 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
336 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100337 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
338
339 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400340 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100341
Anton Samoylova93106c2018-10-25 10:39:34 +0400342 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 +0100343 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400344 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100345 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400346 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100347
348 check = 'contrail-status'
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400349 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100350
351 sleep(120)
352
Anton Samoylova93106c2018-10-25 10:39:34 +0400353 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
354 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400355
356 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
357 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
358 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
359 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
360 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
361 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
362
363 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400364 for (service in (controlServices + thirdPartyServicesToDisable)) {
365 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
366 }
367 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
368 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
369 }
Marek Celouda54924d2017-12-28 16:28:42 +0100370 }
Marek Celouda54924d2017-12-28 16:28:42 +0100371 }
372
Jakub Josefa63f9862018-01-11 17:58:38 +0100373 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100374
Jakub Josefa63f9862018-01-11 17:58:38 +0100375 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100376
Jakub Josefa63f9862018-01-11 17:58:38 +0100377 stage('List targeted compute servers') {
378 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100379
Jakub Josefa63f9862018-01-11 17:58:38 +0100380 if (minions.isEmpty()) {
381 throw new Exception("No minion was targeted")
382 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100383
Jakub Josefa63f9862018-01-11 17:58:38 +0100384 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
385 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100386
Jakub Josefa63f9862018-01-11 17:58:38 +0100387 targetLiveAll = minions.join(' or ')
388 common.infoMsg("Found nodes: ${targetLiveAll}")
389 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100390 }
391
Jakub Josefa63f9862018-01-11 17:58:38 +0100392 stage('Confirm rollback on sample nodes') {
393 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 +0100394 }
395
Jakub Josefa63f9862018-01-11 17:58:38 +0100396 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100397
Jakub Josefa63f9862018-01-11 17:58:38 +0100398 try {
399 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
400 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
401 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
402 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400403 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100404 throw er
405 }
Marek Celouda54924d2017-12-28 16:28:42 +0100406
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400407 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100408 check = 'contrail-status'
409
410 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
411 salt.printSaltCommandResult(out)
412
413 try {
414 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
415 } catch (Exception er) {
416 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
417 }
418
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400419 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100420 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
421
422 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
423 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100424 }
425
Jakub Josefa63f9862018-01-11 17:58:38 +0100426 stage('Confirm rollback on all targeted nodes') {
427 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 +0100428 }
429
Jakub Josefa63f9862018-01-11 17:58:38 +0100430 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100431
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 try {
433 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
434 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
435 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
436 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400437 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check availability of contrail packages before continuing.")
Jakub Josefa63f9862018-01-11 17:58:38 +0100438 throw er
439 }
Marek Celouda54924d2017-12-28 16:28:42 +0100440
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400441 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100442 check = 'contrail-status'
443
444 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
445 salt.printSaltCommandResult(out)
446
447 try {
448 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
449 } catch (Exception er) {
450 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
451 }
452
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400453 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100454 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
455
456 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
457 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100458 }
459
Jakub Josefa63f9862018-01-11 17:58:38 +0100460 } catch (Throwable e) {
461 // If there was an error or exception thrown, the build failed
462 currentBuild.result = "FAILURE"
463 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
464 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100465 }
Marek Celouda54924d2017-12-28 16:28:42 +0100466 }
467 }
468}