blob: 1e099171fb3c01160ea599eeb15f4074f6092117 [file] [log] [blame]
Jiri Broulik641e4102017-07-13 12:26:18 +02001/**
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 (bool)
8 * STAGE_ANALYTICS_UPGRADE Run upgrade on Opencontrail analytics (bool)
9 * STAGE_COMPUTES_UPGRADE Run upgrade on Opencontrail compute nodes (bool)
10 * COMPUTE_TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
11 * COMPUTE_TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update.
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020012 * STAGE_CONTROLLERS_ROLLBACK Run rollback on Opencontrail controllers (bool)
13 * STAGE_ANALYTICS_ROLLBACK Run rollback on Opencontrail analytics (bool)
14 * STAGE_COMPUTES_ROLLBACK Run rollback on Opencontrail compute nodes (bool)
Jiri Broulik641e4102017-07-13 12:26:18 +020015 *
16**/
17
18def common = new com.mirantis.mk.Common()
19def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020020def python = new com.mirantis.mk.Python()
Jiri Broulik641e4102017-07-13 12:26:18 +020021
chnyda625f4b42017-10-11 14:10:31 +020022def pepperEnv = "pepperEnv"
Jiri Broulik641e4102017-07-13 12:26:18 +020023def targetLiveSubset
24def targetLiveAll
25def minions
26def result
27def args
Jiri Broulik641e4102017-07-13 12:26:18 +020028def commandKwargs
29def probe = 1
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020030def errorOccured = false
31def command = 'cmd.shell'
32
33def CONTROL_PKGS = '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'
34def ANALYTIC_PKGS = 'contrail-analytics contrail-lib contrail-nodemgr contrail-utils python-contrail'
Petr Jediný0ec68192017-12-07 14:26:41 +010035def CMP_PKGS = 'contrail-lib contrail-nodemgr contrail-utils contrail-vrouter-agent contrail-vrouter-utils python-contrail python-contrail-vrouter-api python-opencontrail-vrouter-netns contrail-vrouter-dkms contrail-nova-driver'
Anton Samoylovaaf1ff22018-09-27 10:46:43 +040036def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop; rmmod vrouter; sync && echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory; service supervisor-vrouter start'
Anton Samoylov0d642aa2018-11-08 15:22:27 +040037def neutronServerPkgs = 'neutron-plugin-contrail,contrail-heat,python-contrail'
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020038
chnyda625f4b42017-10-11 14:10:31 +020039def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020040
chnyda625f4b42017-10-11 14:10:31 +020041 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020042 salt.printSaltCommandResult(out)
Jiri Broulik375b0b32017-12-11 11:36:58 +010043 // if Error occured - throw exception
44 if (out.toString().contains('E: ')) {
45 throw new Exception("Command execution failed")
46 }
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020047 // wait until $check is in correct state
48 if ( check == "nodetool status" ) {
chnyda625f4b42017-10-11 14:10:31 +020049 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020050 } else if ( check == "contrail-status" ) {
Petr Jediný0fd757e2017-12-01 11:35:17 +010051 salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/", null, false)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020052 }
53
chnyda625f4b42017-10-11 14:10:31 +020054 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020055 //salt.printSaltCommandResult(out)
56 //input message: "Please check the output of \'${check}\' and continue if it is correct."
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020057}
Jakub Josefa63f9862018-01-11 17:58:38 +010058timeout(time: 12, unit: 'HOURS') {
59 node() {
Jiri Broulik641e4102017-07-13 12:26:18 +020060
Jakub Josefa63f9862018-01-11 17:58:38 +010061 stage('Setup virtualenv for Pepper') {
62 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040063 }
64
Jakub Josefa63f9862018-01-11 17:58:38 +010065 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066
Jakub Josefa63f9862018-01-11 17:58:38 +010067 stage('Opencontrail controllers upgrade') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040068
Jakub Josefa63f9862018-01-11 17:58:38 +010069 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040070
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040071 oc_component_repo = oc_component_repo['return'][0].values()[0]
72
73 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010074 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
Anton Samoylov0d642aa2018-11-08 15:22:27 +040075 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
76 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040077 } catch (Exception er) {
78 errorOccured = true
Jakub Josefa63f9862018-01-11 17:58:38 +010079 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040080 return
81 }
82
Jakub Josefa63f9862018-01-11 17:58:38 +010083 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
84 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040085
86 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010087 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040088 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +010089 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040090 }
91
Jakub Josefa63f9862018-01-11 17:58:38 +010092 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
93 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040094
Jakub Josefa63f9862018-01-11 17:58:38 +010095 try {
96 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
97 } catch (Exception er) {
98 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
99 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400100
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400101 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
102
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 args = 'apt install contrail-database -y;'
104 check = 'nodetool status'
105
106 // ntw01
107 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
108 // ntw02
109 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
110 // ntw03
111 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
112
113 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
114 check = 'contrail-status'
115
116 // ntw01
117 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
118 // ntw02
119 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
120 // ntw03
121 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
122
123 try {
124 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
125 } catch (Exception er) {
126 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
127 }
128
129 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400130 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100131
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400132 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
133 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
134
Jakub Josefa63f9862018-01-11 17:58:38 +0100135 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
136 }
137 }
138
139 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
140
141 stage('Ask for manual confirmation') {
142 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400143 }
144
Jakub Josefa63f9862018-01-11 17:58:38 +0100145 stage('Opencontrail analytics upgrade') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400146
Jakub Josefa63f9862018-01-11 17:58:38 +0100147 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
148
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400149 oc_component_repo = oc_component_repo['return'][0].values()[0]
150
151 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100152 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
153 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
154 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400155 } catch (Exception er) {
156 errorOccured = true
Jakub Josefa63f9862018-01-11 17:58:38 +0100157 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400158 return
159 }
160
Jakub Josefa63f9862018-01-11 17:58:38 +0100161 args = 'apt install contrail-database -y;'
162 check = 'nodetool status'
163
164 // nal01
165 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
166 // nal02
167 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
168 // nal03
169 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
170
171 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400172 check = 'contrail-status'
173
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 // nal01
175 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
176 // nal02
177 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
178 // nal03
179 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400180
181 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100182 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400183 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100184 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400185 }
186
Jakub Josefa63f9862018-01-11 17:58:38 +0100187 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400188 salt.printSaltCommandResult(out)
189 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100190 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400191
Jakub Josefa63f9862018-01-11 17:58:38 +0100192 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
193
194 try {
195
196 stage('List targeted compute servers') {
197 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
198
199 if (minions.isEmpty()) {
200 throw new Exception("No minion was targeted")
201 }
202
203 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
204 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
205
206 targetLiveAll = minions.join(' or ')
207 common.infoMsg("Found nodes: ${targetLiveAll}")
208 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
209 }
210
211 stage('Confirm upgrade on sample nodes') {
212 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
213 }
214
215 stage("Opencontrail compute upgrade on sample nodes") {
216
217 oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
218 oc_component_repo = oc_component_repo['return'][0].values()[0]
219
220 try {
221 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
222 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
223 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
224 } catch (Exception er) {
225 errorOccured = true
226 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
227 return
228 }
229
230 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
231 check = 'contrail-status'
232
233 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
234 salt.printSaltCommandResult(out)
235
236 try {
237 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
238 } catch (Exception er) {
239 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
240 }
241
242 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
243
244 //sleep(10)
245 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
246
247 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
248 salt.printSaltCommandResult(out)
249 }
250
251 stage('Confirm upgrade on all targeted nodes') {
252 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
253 }
254 stage("Opencontrail compute upgrade on all targeted nodes") {
255
256 oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
257 oc_component_repo = oc_component_repo['return'][0].values()[0]
258
259 try {
260 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
261 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
262 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
263 } catch (Exception er) {
264 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
265 return
266 }
267
268 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
269 check = 'contrail-status'
270
271 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
272 salt.printSaltCommandResult(out)
273
274 try {
275 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
276 } catch (Exception er) {
277 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
278 }
279
280 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
281 //sleep(10)
282 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
283
284 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
285 salt.printSaltCommandResult(out)
286 }
287
288 } catch (Throwable e) {
289 // If there was an error or exception thrown, the build failed
290 currentBuild.result = "FAILURE"
291 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
292 throw e
293 }
294 }
295
296
297 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
298
299 stage('Ask for manual confirmation') {
300 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400301 }
302
Jakub Josefa63f9862018-01-11 17:58:38 +0100303 stage('Opencontrail controllers rollback') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400304
Jakub Josefa63f9862018-01-11 17:58:38 +0100305 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400306 oc_component_repo = oc_component_repo['return'][0].values()[0]
307
308 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100309 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400310 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
311 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400312 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100313 errorOccured = true
314 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400315 return
316 }
317
Jakub Josefa63f9862018-01-11 17:58:38 +0100318 args = 'apt install contrail-database -y --force-yes;'
319 check = 'nodetool status'
320
321 // ntw01
322 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
323 // ntw02
324 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
325 // ntw03
326 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
327
328 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400329 check = 'contrail-status'
330
Jakub Josefa63f9862018-01-11 17:58:38 +0100331 // ntw01
332 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
333 // ntw02
334 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
335 // ntw03
336 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400337
338 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100339 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400340 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100341 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400342 }
343
Jakub Josefa63f9862018-01-11 17:58:38 +0100344 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400345 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100346
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400347 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
348 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
349 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
350 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
351
Jakub Josefa63f9862018-01-11 17:58:38 +0100352 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
353 }
354 }
355
356 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
357
358 stage('Ask for manual confirmation') {
359 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400360 }
361
Jakub Josefa63f9862018-01-11 17:58:38 +0100362 stage('Opencontrail analytics rollback') {
363
364 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
365 oc_component_repo = oc_component_repo['return'][0].values()[0]
366
367 try {
368 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
369 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
370 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
371 } catch (Exception er) {
372 errorOccured = true
373 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
374 return
375 }
376
377 args = 'apt install contrail-database -y --force-yes;'
378 check = 'nodetool status'
379
380 // nal01
381 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
382 // nal02
383 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
384 // nal03
385 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
386
387 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
388 check = 'contrail-status'
389
390 // nal01
391 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
392 // nal02
393 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
394 // nal03
395 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
396
397 try {
398 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
399 } catch (Exception er) {
400 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
401 }
402
403 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
404 salt.printSaltCommandResult(out)
405 }
406 }
407
408 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
409
410 try {
411
412 stage('List targeted compute servers') {
413 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
414
415 if (minions.isEmpty()) {
416 throw new Exception("No minion was targeted")
417 }
418
419 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
420 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
421
422 targetLiveAll = minions.join(' or ')
423 common.infoMsg("Found nodes: ${targetLiveAll}")
424 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
425 }
426
427 stage('Confirm rollback on sample nodes') {
428 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
429 }
430
431 stage("Opencontrail compute rollback on sample nodes") {
432
433 oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
434 oc_component_repo = oc_component_repo['return'][0].values()[0]
435
436 try {
437 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
438 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
439 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
440 } catch (Exception er) {
441 errorOccured = true
442 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
443 return
444 }
445
446 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
447 check = 'contrail-status'
448
449 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
450 salt.printSaltCommandResult(out)
451
452 try {
453 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
454 } catch (Exception er) {
455 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
456 }
457
458 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
459 //sleep(10)
460 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
461
462 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
463 salt.printSaltCommandResult(out)
464 }
465
466 stage('Confirm rollback on all targeted nodes') {
467 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
468 }
469
470 stage("Opencontrail compute upgrade on all targeted nodes") {
471
472 oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
473 oc_component_repo = oc_component_repo['return'][0].values()[0]
474
475 try {
476 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
477 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
478 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
479 } catch (Exception er) {
480 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
481 return
482 }
483
484 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
485 check = 'contrail-status'
486
487 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
488 salt.printSaltCommandResult(out)
489
490 try {
491 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
492 } catch (Exception er) {
493 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
494 }
495
496 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
497
498 //sleep(10)
499 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
500
501 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
502 salt.printSaltCommandResult(out)
503 }
504
505 } catch (Throwable e) {
506 // If there was an error or exception thrown, the build failed
507 currentBuild.result = "FAILURE"
508 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
509 throw e
510 }
Jiri Broulik641e4102017-07-13 12:26:18 +0200511 }
512 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100513}