blob: c80b53ba301cf5fe96354b712e8b98f4aeb244a1 [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
Anton Samoylov32d62de2019-02-15 18:04:20 +040029def 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,contrail-database'
Anton Samoylov23be5cd2018-10-18 14:55:31 +040030def thirdPartyControlPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,redis-server,ifmap-server,supervisor'
Anton Samoylov32d62de2019-02-15 18:04:20 +040031def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,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
Anton Samoylov19a64332018-12-26 18:01:03 +0400111 salt.runSaltProcessStep(pepperEnv, 'I@keystone:server:role:primary or I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
112 salt.runSaltProcessStep(pepperEnv, 'I@keystone:server:role:primary or I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.sync_all', [], null, true)
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400113
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
Anton Samoylov19a64332018-12-26 18:01:03 +0400130 // Make sure that dedicated opencontrail user is created
Valeriy Sakharov05d83532019-12-30 14:21:58 +0400131 salt.enforceState(pepperEnv, 'I@keystone:server:role:primary', 'keystone.client.resources.v3')
Anton Samoylov19a64332018-12-26 18:01:03 +0400132
Jakub Josefa63f9862018-01-11 17:58:38 +0100133 try {
Anton Samoylov9837c212018-12-20 00:15:11 +0400134 controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail:service:controller:image")
135 analyticsImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analytics:image")
136 analyticsdbImage = getValueForPillarKey(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail:service:analyticsdb:image")
137
Jakub Josefa63f9862018-01-11 17:58:38 +0100138 salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400139 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400140 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage])
142 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage])
143 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage])
144
145 } catch (Exception er) {
146 common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.")
147 throw er
Marek Celouda54924d2017-12-28 16:28:42 +0100148 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100149
Jakub Josefa63f9862018-01-11 17:58:38 +0100150 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
151 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
152
153 try {
154 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
155 } catch (Exception er) {
156 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
157 throw er
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100158 }
159
Jakub Josefa63f9862018-01-11 17:58:38 +0100160 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
161 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100162
Jakub Josefa63f9862018-01-11 17:58:38 +0100163 try {
164 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
165 } catch (Exception er) {
166 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
167 throw er
168 }
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400169
Jakub Josefa63f9862018-01-11 17:58:38 +0100170 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
171
172 try {
173 for (service in analyticsServices) {
174 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service])
175 }
176 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 +0400177 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.makedirs', ['/var/lib/analyticsdb'])
178 // Keep analyticsdb only for 4.0 version
179 if (result == false && targetOcVersion == '4.0') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100180 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb'])
181 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True'])
182 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100183 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400184 if (targetOcVersion == '4.1') {
185 sleep(15)
186 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["doctrail analyticsdb systemctl restart confluent-kafka"], null, true)
187 }
188 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:collector')
Jakub Josefa63f9862018-01-11 17:58:38 +0100189 } catch (Exception er) {
190 common.errorMsg("Opencontrail Analytics failed to be upgraded.")
191 throw er
192 }
193 try {
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400194 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100195
196 for (service in configServices) {
197 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service])
198 }
199
200 result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0]
201 if (result == false) {
202 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True'])
203 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True'])
204 }
205
206 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400207 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100208 }
209
Anton Samoylova93106c2018-10-25 10:39:34 +0400210 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400211 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:control:role:secondary')
Jakub Josefa63f9862018-01-11 17:58:38 +0100212
213 sleep(120)
214
215 for (service in controlServices) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400216 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service])
Jakub Josefa63f9862018-01-11 17:58:38 +0100217 }
218
Anton Samoylova93106c2018-10-25 10:39:34 +0400219 salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client')
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400220 checkContrailServices(pepperEnv, targetOcVersion, 'I@opencontrail:control:role:primary')
Jakub Josefa63f9862018-01-11 17:58:38 +0100221
Anton Samoylov049be7f2018-10-31 20:59:36 +0400222 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
223 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
Jakub Josefa63f9862018-01-11 17:58:38 +0100224 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400225 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Jakub Josefa63f9862018-01-11 17:58:38 +0100226 } catch (Exception er) {
227 common.errorMsg("Opencontrail Controller failed to be upgraded.")
228 throw er
229 }
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400230 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100231
Anton Samoylov23be5cd2018-10-18 14:55:31 +0400232 stage('Opencontrail controllers backup and cleanup') {
233 try {
234 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra'])
235 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker'])
236 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra'])
237 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper'])
238
239 for (service in (controlServices + thirdPartyServicesToDisable)) {
240 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service])
241 }
242 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
243 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service])
244 }
245
246 def tmpCfgBackupDir = '/tmp/cfg_backup'
247 def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/']
248
249 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir])
250
251 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
252 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath])
253 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True'])
254 }
255
256 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove])
257 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove])
258
259 for (cfgFilePath in thirdPartyCfgFilesToBackup) {
260 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath])
261 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True'])
262 }
263 } catch (Exception er) {
264 common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.")
265 throw er
266 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100267 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100268 }
269
270
271 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
272
273 try {
274
275 stage('List targeted compute servers') {
276 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
277
278 if (minions.isEmpty()) {
279 throw new Exception("No minion was targeted")
280 }
281
282 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
283 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
284
285 targetLiveAll = minions.join(' or ')
286 common.infoMsg("Found nodes: ${targetLiveAll}")
287 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
288 }
289
Anton Samoylov97ce9b82018-10-19 00:43:54 +0400290 stage('Compute nodes health check') {
291 try {
292 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true)
293 } catch (Exception er) {
294 common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.")
295 throw er
296 }
297 }
298
Jakub Josefa63f9862018-01-11 17:58:38 +0100299 stage('Confirm upgrade on sample nodes') {
300 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
301 }
302
303 stage("Opencontrail compute upgrade on sample nodes") {
304
305 try {
306 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
307 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true)
308 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
309 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
310 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400311 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 +0100312 throw er
313 }
314
azvyagintsev93e05cc2018-12-26 13:53:02 +0200315 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100316 check = 'contrail-status'
317
318 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
319 salt.printSaltCommandResult(out)
320
321 try {
322 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
323 } catch (Exception er) {
324 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
325 }
326
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400327 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100328
329 //sleep(10)
330 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
331
332 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
333 salt.printSaltCommandResult(out)
334 }
335
336 stage('Confirm upgrade on all targeted nodes') {
337 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
338 }
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400339
Jakub Josefa63f9862018-01-11 17:58:38 +0100340 stage("Opencontrail compute upgrade on all targeted nodes") {
341
342 try {
343 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
344 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true)
345 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
346 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
347 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400348 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 +0100349 throw er
350 }
351
azvyagintsev93e05cc2018-12-26 13:53:02 +0200352 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100353 check = 'contrail-status'
354
355 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
356 salt.printSaltCommandResult(out)
357
358 try {
359 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
360 } catch (Exception er) {
361 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
362 }
363
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400364 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100365 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
366
367 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
368 salt.printSaltCommandResult(out)
369 }
370
371 } catch (Throwable e) {
372 // If there was an error or exception thrown, the build failed
373 currentBuild.result = "FAILURE"
374 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
375 throw e
376 }
377 }
378
379
380 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) {
381
382 stage('Ask for manual confirmation') {
383 input message: "Do you want to continue with the Opencontrail nodes rollback?"
384 }
385
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400386 stage('Opencontrail controllers rollback') {
Jakub Josefa63f9862018-01-11 17:58:38 +0100387
Anton Samoylov049be7f2018-10-31 20:59:36 +0400388 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'saltutil.refresh_pillar', [], null, true)
389 salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server or I@horizon:server', 'linux.system.repo')
Jakub Josefa63f9862018-01-11 17:58:38 +0100390 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
391
392 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov77a6d4a2018-11-04 14:42:49 +0400393 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100394
Anton Samoylova93106c2018-10-25 10:39:34 +0400395 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 +0100396 for (service in config4Services) {
Anton Samoylova93106c2018-10-25 10:39:34 +0400397 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100398 }
Anton Samoylova93106c2018-10-25 10:39:34 +0400399 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Jakub Josefa63f9862018-01-11 17:58:38 +0100400
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400401 def rollbackOcVersion = getValueForPillarKey(pepperEnv, 'I@opencontrail:control:role:primary', '_param:opencontrail_version')
402 checkContrailServices(pepperEnv, rollbackOcVersion, 'I@opencontrail:control:role:secondary or I@opencontrail:collector')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100403
404 sleep(120)
405
Anton Samoylova93106c2018-10-25 10:39:34 +0400406 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true)
407 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Anton Samoylov049be7f2018-10-31 20:59:36 +0400408
Anton Samoylovfb4fec52018-12-24 21:37:06 +0400409 checkContrailServices(pepperEnv, rollbackOcVersion, 'I@opencontrail:control:role:primary')
410
Anton Samoylov049be7f2018-10-31 20:59:36 +0400411 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
412 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
413 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
414 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.remove', [dashboardPanelPkg])
415 salt.runSaltProcessStep(pepperEnv, 'I@horizon:server', 'pkg.install', [dashboardPanelPkg])
416 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
417
418 salt.enforceState(pepperEnv, 'I@horizon:server', 'horizon')
Anton Samoylovf6b498d2018-09-19 13:10:34 +0400419 for (service in (controlServices + thirdPartyServicesToDisable)) {
420 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service])
421 }
422 for (service in (analyticsServices + thirdPartyServicesToDisable)) {
423 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service])
424 }
Marek Celouda54924d2017-12-28 16:28:42 +0100425 }
Marek Celouda54924d2017-12-28 16:28:42 +0100426 }
427
Jakub Josefa63f9862018-01-11 17:58:38 +0100428 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) {
Marek Celouda54924d2017-12-28 16:28:42 +0100429
Jakub Josefa63f9862018-01-11 17:58:38 +0100430 try {
Marek Celouda54924d2017-12-28 16:28:42 +0100431
Jakub Josefa63f9862018-01-11 17:58:38 +0100432 stage('List targeted compute servers') {
433 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100434
Jakub Josefa63f9862018-01-11 17:58:38 +0100435 if (minions.isEmpty()) {
436 throw new Exception("No minion was targeted")
437 }
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100438
Jakub Josefa63f9862018-01-11 17:58:38 +0100439 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
440 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
Marek Celoud8d6ddd82018-01-03 17:56:05 +0100441
Jakub Josefa63f9862018-01-11 17:58:38 +0100442 targetLiveAll = minions.join(' or ')
443 common.infoMsg("Found nodes: ${targetLiveAll}")
444 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
Marek Celouda54924d2017-12-28 16:28:42 +0100445 }
446
Jakub Josefa63f9862018-01-11 17:58:38 +0100447 stage('Confirm rollback on sample nodes') {
448 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 +0100449 }
450
Jakub Josefa63f9862018-01-11 17:58:38 +0100451 stage("Opencontrail compute rollback on sample nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100452
Jakub Josefa63f9862018-01-11 17:58:38 +0100453 try {
454 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
455 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
456 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
457 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400458 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 +0100459 throw er
460 }
Marek Celouda54924d2017-12-28 16:28:42 +0100461
azvyagintsev93e05cc2018-12-26 13:53:02 +0200462 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100463 check = 'contrail-status'
464
465 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
466 salt.printSaltCommandResult(out)
467
468 try {
469 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
470 } catch (Exception er) {
471 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
472 }
473
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400474 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100475 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
476
477 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
478 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100479 }
480
Jakub Josefa63f9862018-01-11 17:58:38 +0100481 stage('Confirm rollback on all targeted nodes') {
482 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 +0100483 }
484
Jakub Josefa63f9862018-01-11 17:58:38 +0100485 stage("Opencontrail compute upgrade on all targeted nodes") {
Marek Celouda54924d2017-12-28 16:28:42 +0100486
Jakub Josefa63f9862018-01-11 17:58:38 +0100487 try {
488 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true)
489 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
490 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
491 } catch (Exception er) {
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400492 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 +0100493 throw er
494 }
Marek Celouda54924d2017-12-28 16:28:42 +0100495
azvyagintsev93e05cc2018-12-26 13:53:02 +0200496 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${cmpPkgs} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100497 check = 'contrail-status'
498
499 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
500 salt.printSaltCommandResult(out)
501
502 try {
503 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
504 } catch (Exception er) {
505 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
506 }
507
Anton Samoylov0dd88f42018-10-18 16:37:04 +0400508 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', [kernelModuleReloadCmd], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100509 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
510
511 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
512 salt.printSaltCommandResult(out)
Marek Celouda54924d2017-12-28 16:28:42 +0100513 }
514
Jakub Josefa63f9862018-01-11 17:58:38 +0100515 } catch (Throwable e) {
516 // If there was an error or exception thrown, the build failed
517 currentBuild.result = "FAILURE"
518 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
519 throw e
Marek Celouda54924d2017-12-28 16:28:42 +0100520 }
Marek Celouda54924d2017-12-28 16:28:42 +0100521 }
522 }
523}