blob: 93db00953dc29c130532092fb51d6fde36bd9878 [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
Anton Samoylov9837c212018-12-20 00:15:11 +040016common = new com.mirantis.mk.Common()
17salt = new com.mirantis.mk.Salt()
18python = new com.mirantis.mk.Python()
Marek Celouda54924d2017-12-28 16:28:42 +010019
20def pepperEnv = "pepperEnv"
Anton Samoylovfb4fec52018-12-24 21:37:06 +040021def supportedOcTargetVersions = ['4.0', '4.1']
Marek Celouda54924d2017-12-28 16:28:42 +010022def targetLiveSubset
23def targetLiveAll
24def minions
25def args
26def probe = 1
27def command = 'cmd.shell'
28
29def 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 +040030def thirdPartyControlPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,redis-server,ifmap-server,supervisor'
Marek Celouda54924d2017-12-28 16:28:42 +010031def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,python-contrail,contrail-database'
Anton Samoylov23be5cd2018-10-18 14:55:31 +040032def thirdPartyAnalyticsPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,python-cassandra,cassandra-cpp-driver,redis-server,supervisor'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040033def 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 +040034def neutronServerPkgs = 'neutron-plugin-contrail,contrail-heat,python-contrail'
35def dashboardPanelPkg = 'openstack-dashboard-contrail-panels'
Anton Samoylov0dd88f42018-10-18 16:37:04 +040036def 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 +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
Marek Celouda54924d2017-12-28 16:28:42 +010043
Anton Samoylovfb4fec52018-12-24 21:37:06 +040044def checkContrailServices(pepperEnv, oc_version, target) {
45
46 def checkCmd
47
48 if (oc_version.startsWith('4')) {
49
50 checkCmd = "doctrail all contrail-status | 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/"
51
52 if (oc_version == '4.1') {
53 def targetMinions = salt.getMinions(pepperEnv, target)
54 def collectorMinionsInTarget = targetMinions.intersect(salt.getMinions(pepperEnv, 'I@opencontrail:collector'))
55
56 if (collectorMinionsInTarget.size() != 0) {
57 def cassandraConfigYaml = readYaml text: salt.getFileContent(pepperEnv, 'I@opencontrail:control:role:primary', '/etc/cassandra/cassandra.yaml')
58
59 def currentCassandraNativeTransportPort = cassandraConfigYaml['native_transport_port'] ?: "9042"
60 def currentCassandraRpcPort = cassandraConfigYaml['rpc_port'] ?: "9160"
61
62 def cassandraNativeTransportPort = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:port_configdb")
63 def cassandraCassandraRpcPort = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:rpc_port_configdb")
64
65 if (currentCassandraNativeTransportPort != cassandraNativeTransportPort) {
66 checkCmd += ' | grep -v \'contrail-collector.*(Database:Cassandra connection down)\''
67 }
68
69 if (currentCassandraRpcPort != cassandraCassandraRpcPort) {
70 checkCmd += ' | grep -v \'contrail-alarm-gen.*(Database:Cassandra\\[\\] connection down)\''
71 }
72 }
73 }
74
75 } else {
76 checkCmd = "contrail-status | grep -v == | grep -v FOR | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/"
Marek Celouda54924d2017-12-28 16:28:42 +010077 }
Anton Samoylovfb4fec52018-12-24 21:37:06 +040078
79 salt.commandStatus(pepperEnv, target, checkCmd, null, false, true, null, true, 500)
Marek Celouda54924d2017-12-28 16:28:42 +010080}
Anton Samoylov9837c212018-12-20 00:15:11 +040081
82def getValueForPillarKey(pepperEnv, target, pillarKey) {
83 def out = salt.getReturnValues(salt.getPillar(pepperEnv, target, pillarKey))
84 if (out == '') {
85 throw new Exception("Cannot get value for ${pillarKey} key on ${target} target")
86 }
Anton Samoylovfb4fec52018-12-24 21:37:06 +040087 return out.toString()
Anton Samoylov9837c212018-12-20 00:15:11 +040088}
89
Jakub Josefa63f9862018-01-11 17:58:38 +010090timeout(time: 12, unit: 'HOURS') {
91 node() {
Marek Celouda54924d2017-12-28 16:28:42 +010092
Jakub Josefa63f9862018-01-11 17:58:38 +010093 stage('Setup virtualenv for Pepper') {
94 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
95 }
Marek Celouda54924d2017-12-28 16:28:42 +010096
Jakub Josefa63f9862018-01-11 17:58:38 +010097 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +010098
Anton Samoylov97ce9b82018-10-19 00:43:54 +040099 stage('Opencontrail controllers health check') {
100 try {
101 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true)
102 } catch (Exception er) {
103 common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.")
104 throw er
105 }
106 }
107
Jakub Josefa63f9862018-01-11 17:58:38 +0100108 stage('Opencontrail controllers upgrade') {
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400109
110 // Sync data on minions
111 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
112 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.sync_all', [], null, true)
113
114 // Verify specified target OpenContrail version before upgrade
115 def targetOcVersion = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version")
116 if (!supportedOcTargetVersions.contains(targetOcVersion)) {
117 throw new Exception("Specified OpenContrail version ${targetOcVersion} is not supported by upgrade pipeline. Supported versions: ${supportedOcTargetVersions}")
118 }
119
Jakub Josefa63f9862018-01-11 17:58:38 +0100120 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100121 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
122 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true)
Anton Samoylov049be7f2018-10-31 20:59:36 +0400123 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Marek Celouda54924d2017-12-28 16:28:42 +0100124
Jakub Josefa63f9862018-01-11 17:58:38 +0100125 } catch (Exception er) {
Anton Samoylov049be7f2018-10-31 20:59:36 +0400126 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 +0100127 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100128 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100129
Jakub Josefa63f9862018-01-11 17:58:38 +0100130 try {
Anton Samoylov9837c212018-12-20 00:15:11 +0400131 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail:service:controller:image")
132 analyticsImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analytics:image")
133 analyticsdbImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analyticsdb:image")
134
Jakub Josefa63f9862018-01-11 17:58:38 +0100135 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400136 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400137 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
139 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
140 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
141
142 } catch (Exception er) {
143 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
144 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100145 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100146
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
148 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
149
150 try {
151 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
152 } catch (Exception er) {
153 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
154 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100155 }
156
Jakub Josefa63f9862018-01-11 17:58:38 +0100157 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
158 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100159
Jakub Josefa63f9862018-01-11 17:58:38 +0100160 try {
161 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
162 } catch (Exception er) {
163 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
164 throw er
165 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400166
Jakub Josefa63f9862018-01-11 17:58:38 +0100167 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
168
169 try {
170 for (service in analyticsServices) {
171 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
172 }
173 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0]
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400174 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.makedirs', ['/var/lib/analyticsdb'])
175 // Keep analyticsdb only for 4.0 version
176 if (result == false && targetOcVersion == '4.0') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100177 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
178 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
179 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100180 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400181 if (targetOcVersion == '4.1') {
182 sleep(15)
183 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["doctrail analyticsdb systemctl restart confluent-kafka"], null, true)
184 }
185 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:collector')
Jakub Josefa63f9862018-01-11 17:58:38 +0100186 } catch (Exception er) {
187 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
188 throw er
189 }
190 try {
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400191 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100192
193 for (service in configServices) {
194 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
195 }
196
197 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
198 if (result == false) {
199 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
200 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
201 }
202
203 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400204 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100205 }
206
Anton Samoylova93106c2018-10-25 10:39:34 +0400207 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400208 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:control:role:secondary')
Jakub Josefa63f9862018-01-11 17:58:38 +0100209
210 sleep(120)
211
212 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400213 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100214 }
215
Anton Samoylova93106c2018-10-25 10:39:34 +0400216 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400217 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:control:role:primary')
Jakub Josefa63f9862018-01-11 17:58:38 +0100218
Anton Samoylov049be7f2018-10-31 20:59:36 +0400219 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
220 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100221 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400222 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100223 } catch (Exception er) {
224 common.errorMsg("Opencontrail Controller failed to be upgraded.")
225 throw er
226 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400227 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100228
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400229 stage('Opencontrail controllers backup and cleanup') {
230 try {
231 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
232 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
233 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
234 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
235
236 for (service in (controlServices + thirdPartyServicesToDisable)) {
237 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
238 }
239 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
240 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
241 }
242
243 def tmpCfgBackupDir = '/tmp/cfg_backup'
244 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
245
246 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
247
248 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
249 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
250 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
251 }
252
253 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
254 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
255
256 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
257 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
258 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
259 }
260 } catch (Exception er) {
261 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
262 throw er
263 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100264 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100265 }
266
267
268 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
269
270 try {
271
272 stage('List targeted compute servers') {
273 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
274
275 if (minions.isEmpty()) {
276 throw new Exception("No minion was targeted")
277 }
278
279 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
280 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
281
282 targetLiveAll = minions.join(' or ')
283 common.infoMsg("Found nodes: ${targetLiveAll}")
284 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
285 }
286
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400287 stage('Compute nodes health check') {
288 try {
289 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
290 } catch (Exception er) {
291 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
292 throw er
293 }
294 }
295
Jakub Josefa63f9862018-01-11 17:58:38 +0100296 stage('Confirm upgrade on sample nodes') {
297 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
298 }
299
300 stage("Opencontrail compute upgrade on sample nodes") {
301
302 try {
303 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
304 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
305 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
306 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
307 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400308 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 +0100309 throw er
310 }
311
azvyagintsev93e05cc2018-12-26 13:53:02 +0200312 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100313 check = 'contrail-status'
314
315 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
316 salt.printSaltCommandResult(out)
317
318 try {
319 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
320 } catch (Exception er) {
321 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
322 }
323
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400324 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100325
326 //sleep(10)
327 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
328
329 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
330 salt.printSaltCommandResult(out)
331 }
332
333 stage('Confirm upgrade on all targeted nodes') {
334 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
335 }
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400336
Jakub Josefa63f9862018-01-11 17:58:38 +0100337 stage("Opencontrail compute upgrade on all targeted nodes") {
338
339 try {
340 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
341 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
342 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
343 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
344 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400345 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 +0100346 throw er
347 }
348
azvyagintsev93e05cc2018-12-26 13:53:02 +0200349 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100350 check = 'contrail-status'
351
352 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
353 salt.printSaltCommandResult(out)
354
355 try {
356 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
357 } catch (Exception er) {
358 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
359 }
360
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400361 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100362 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
363
364 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
365 salt.printSaltCommandResult(out)
366 }
367
368 } catch (Throwable e) {
369 // If there was an error or exception thrown, the build failed
370 currentBuild.result = "FAILURE"
371 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
372 throw e
373 }
374 }
375
376
377 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
378
379 stage('Ask for manual confirmation') {
380 input message: "Do you want to continue with the Opencontrail nodes rollback?"
381 }
382
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400383 stage('Opencontrail controllers rollback') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100384
Anton Samoylov049be7f2018-10-31 20:59:36 +0400385 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
386 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100387 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
388
389 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400390 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100391
Anton Samoylova93106c2018-10-25 10:39:34 +0400392 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 +0100393 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400394 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100395 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400396 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100397
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400398 def rollbackOcVersion = getValueForPillarKey(pepperEnv, 'I@opencontrail:control:role:primary', '_param:opencontrail_version')
399 checkContrailServices(pepperEnv, rollbackOcVersion, 'I@opencontrail:control:role:secondary or I@opencontrail:collector')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100400
401 sleep(120)
402
Anton Samoylova93106c2018-10-25 10:39:34 +0400403 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
404 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400405
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400406 checkContrailServices(pepperEnv, rollbackOcVersion, 'I@opencontrail:control:role:primary')
407
Anton Samoylov049be7f2018-10-31 20:59:36 +0400408 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
409 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
410 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
411 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
412 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
413 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
414
415 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400416 for (service in (controlServices + thirdPartyServicesToDisable)) {
417 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
418 }
419 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
420 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
421 }
Marek Celouda54924d2017-12-28 16:28:42 +0100422 }
Marek Celouda54924d2017-12-28 16:28:42 +0100423 }
424
Jakub Josefa63f9862018-01-11 17:58:38 +0100425 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100426
Jakub Josefa63f9862018-01-11 17:58:38 +0100427 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100428
Jakub Josefa63f9862018-01-11 17:58:38 +0100429 stage('List targeted compute servers') {
430 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100431
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 if (minions.isEmpty()) {
433 throw new Exception("No minion was targeted")
434 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100435
Jakub Josefa63f9862018-01-11 17:58:38 +0100436 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
437 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100438
Jakub Josefa63f9862018-01-11 17:58:38 +0100439 targetLiveAll = minions.join(' or ')
440 common.infoMsg("Found nodes: ${targetLiveAll}")
441 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100442 }
443
Jakub Josefa63f9862018-01-11 17:58:38 +0100444 stage('Confirm rollback on sample nodes') {
445 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 +0100446 }
447
Jakub Josefa63f9862018-01-11 17:58:38 +0100448 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100449
Jakub Josefa63f9862018-01-11 17:58:38 +0100450 try {
451 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
452 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
453 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
454 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400455 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 +0100456 throw er
457 }
Marek Celouda54924d2017-12-28 16:28:42 +0100458
azvyagintsev93e05cc2018-12-26 13:53:02 +0200459 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100460 check = 'contrail-status'
461
462 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
463 salt.printSaltCommandResult(out)
464
465 try {
466 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
467 } catch (Exception er) {
468 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
469 }
470
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400471 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100472 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
473
474 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
475 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100476 }
477
Jakub Josefa63f9862018-01-11 17:58:38 +0100478 stage('Confirm rollback on all targeted nodes') {
479 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 +0100480 }
481
Jakub Josefa63f9862018-01-11 17:58:38 +0100482 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100483
Jakub Josefa63f9862018-01-11 17:58:38 +0100484 try {
485 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
486 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
487 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
488 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400489 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 +0100490 throw er
491 }
Marek Celouda54924d2017-12-28 16:28:42 +0100492
azvyagintsev93e05cc2018-12-26 13:53:02 +0200493 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100494 check = 'contrail-status'
495
496 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
497 salt.printSaltCommandResult(out)
498
499 try {
500 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
501 } catch (Exception er) {
502 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
503 }
504
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400505 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100506 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
507
508 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
509 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100510 }
511
Jakub Josefa63f9862018-01-11 17:58:38 +0100512 } catch (Throwable e) {
513 // If there was an error or exception thrown, the build failed
514 currentBuild.result = "FAILURE"
515 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
516 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100517 }
Marek Celouda54924d2017-12-28 16:28:42 +0100518 }
519 }
520}