blob: 02c2bc1e96ff7fd84aba9187c941583aaed9a4db [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()
20
21def saltMaster
Jiri Broulik641e4102017-07-13 12:26:18 +020022def targetLiveSubset
23def targetLiveAll
24def minions
25def result
26def args
Jiri Broulik641e4102017-07-13 12:26:18 +020027def commandKwargs
28def probe = 1
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020029def errorOccured = false
30def command = 'cmd.shell'
31
32def 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'
33def ANALYTIC_PKGS = 'contrail-analytics contrail-lib contrail-nodemgr contrail-utils python-contrail'
34def 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'
35def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;'
36
37
38def void runCommonCommands(target, command, args, check, salt, saltMaster, common) {
39
40 out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
41 salt.printSaltCommandResult(out)
42 sleep(60)
43 out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
44 salt.printSaltCommandResult(out)
45 input message: "Please check the output of \'${check}\' and continue if it is correct."
46}
Jiri Broulik641e4102017-07-13 12:26:18 +020047
48timestamps {
49 node() {
50
51 stage('Connect to Salt API') {
52 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
53 }
54
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020055 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +020056
57 stage('Opencontrail controllers upgrade') {
58
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020059 oc_component_repo = salt.runSaltProcessStep(saltMaster, '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)
Jiri Broulik641e4102017-07-13 12:26:18 +020060
Jiri Broulik641e4102017-07-13 12:26:18 +020061 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +020062
63 try {
Jiri Broulik641e4102017-07-13 12:26:18 +020064 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
65 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
66 salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo')
67 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020068 errorOccured = true
69 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Jiri Broulik641e4102017-07-13 12:26:18 +020070 return
71 }
72
73 try {
74 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
75 } catch (Exception er) {
76 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
77 return
78 }
79
80 try {
81 salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
82 } catch (Exception er) {
83 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
84 return
85 }
86
Jiri Broulik641e4102017-07-13 12:26:18 +020087 args = 'apt install contrail-database -y;'
88 check = 'nodetool status'
89
90 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020091 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +020092 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020093 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +020094 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020095 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +020096
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020097 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
Jiri Broulik641e4102017-07-13 12:26:18 +020098 check = 'contrail-status'
99
100 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200101 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200102 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200103 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200104 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200105 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200106
Jiri Broulik641e4102017-07-13 12:26:18 +0200107 try {
108 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail')
109 } catch (Exception er) {
110 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
111 }
112
113 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
114 salt.printSaltCommandResult(out)
115
116 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
117 }
118 }
119
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200120 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +0200121
122 stage('Ask for manual confirmation') {
123 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
124 }
125
126 stage('Opencontrail analytics upgrade') {
127
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200128 oc_component_repo = salt.runSaltProcessStep(saltMaster, '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)
Jiri Broulik641e4102017-07-13 12:26:18 +0200129
Jiri Broulik641e4102017-07-13 12:26:18 +0200130 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200131
132 try {
Jiri Broulik641e4102017-07-13 12:26:18 +0200133 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
134 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
135 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo')
136 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200137 errorOccured = true
138 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200139 return
140 }
141
Jiri Broulik641e4102017-07-13 12:26:18 +0200142 args = 'apt install contrail-database -y;'
143 check = 'nodetool status'
144
Jiri Broulik641e4102017-07-13 12:26:18 +0200145 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200146 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200147 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200148 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200149 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200150 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200151
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200152 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
Jiri Broulik641e4102017-07-13 12:26:18 +0200153 check = 'contrail-status'
154
155 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200156 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200157 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200158 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200159 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200160 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200161
Jiri Broulik641e4102017-07-13 12:26:18 +0200162 try {
163 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail')
164 } catch (Exception er) {
165 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
166 }
167
168 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
169 salt.printSaltCommandResult(out)
170 }
Jiri Broulik641e4102017-07-13 12:26:18 +0200171 }
172
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200173 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +0200174
175 try {
176
177 stage('List targeted compute servers') {
178 minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS)
179
180 if (minions.isEmpty()) {
181 throw new Exception("No minion was targeted")
182 }
183
184 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
185 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
186
187 targetLiveAll = minions.join(' or ')
188 common.infoMsg("Found nodes: ${targetLiveAll}")
189 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
190 }
191
192 stage('Confirm upgrade on sample nodes') {
193 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
194 }
195
196 stage("Opencontrail compute upgrade on sample nodes") {
197
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200198 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Jiri Broulik641e4102017-07-13 12:26:18 +0200199 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200200
201 try {
202 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
203 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
204 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
205 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200206 errorOccured = true
207 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200208 return
209 }
210
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200211 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
Jiri Broulik641e4102017-07-13 12:26:18 +0200212 check = 'contrail-status'
213
Jiri Broulik641e4102017-07-13 12:26:18 +0200214 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
215 salt.printSaltCommandResult(out)
Jiri Broulik641e4102017-07-13 12:26:18 +0200216
Jiri Broulik641e4102017-07-13 12:26:18 +0200217 try {
218 salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail')
219 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200220 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200221 }
222
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200223 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
224 sleep(10)
Jiri Broulik641e4102017-07-13 12:26:18 +0200225
226 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
227 salt.printSaltCommandResult(out)
228 }
229
230 stage('Confirm upgrade on all targeted nodes') {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200231 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
Jiri Broulik641e4102017-07-13 12:26:18 +0200232 }
233 stage("Opencontrail compute upgrade on all targeted nodes") {
234
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200235 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Jiri Broulik641e4102017-07-13 12:26:18 +0200236 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200237
238 try {
239 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
240 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
241 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo')
242 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200243 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200244 return
245 }
246
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200247 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
Jiri Broulik641e4102017-07-13 12:26:18 +0200248 check = 'contrail-status'
249
Jiri Broulik641e4102017-07-13 12:26:18 +0200250 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
251 salt.printSaltCommandResult(out)
Jiri Broulik641e4102017-07-13 12:26:18 +0200252
Jiri Broulik641e4102017-07-13 12:26:18 +0200253 try {
254 salt.enforceState(saltMaster, targetLiveAll, 'opencontrail')
255 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200256 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200257 }
258
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200259 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
260 sleep(10)
261
262 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
263 salt.printSaltCommandResult(out)
264 }
265
266 } catch (Throwable e) {
267 // If there was an error or exception thrown, the build failed
268 currentBuild.result = "FAILURE"
269 throw e
270 }
271 }
272
273
274 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
275
276 stage('Ask for manual confirmation') {
277 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
278 }
279
280 stage('Opencontrail controllers rollback') {
281
282 oc_component_repo = salt.runSaltProcessStep(saltMaster, '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)
283 oc_component_repo = oc_component_repo['return'][0].values()[0]
284
285 try {
286 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
287 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
288 salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo')
289 } catch (Exception er) {
290 errorOccured = true
291 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
292 return
293 }
294
295 args = 'apt install contrail-database -y --force-yes;'
296 check = 'nodetool status'
297
298 // ntw01
299 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
300 // ntw02
301 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
302 // ntw03
303 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
304
305 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
306 check = 'contrail-status'
307
308 // ntw01
309 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
310 // ntw02
311 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
312 // ntw03
313 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
314
315 try {
316 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail')
317 } catch (Exception er) {
318 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
319 }
320
321 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
322 salt.printSaltCommandResult(out)
323
324 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
325 }
326 }
327
328 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
329
330 stage('Ask for manual confirmation') {
331 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
332 }
333
334 stage('Opencontrail analytics rollback') {
335
336 oc_component_repo = salt.runSaltProcessStep(saltMaster, '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)
337 oc_component_repo = oc_component_repo['return'][0].values()[0]
338
339 try {
340 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
341 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
342 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo')
343 } catch (Exception er) {
344 errorOccured = true
345 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
346 return
347 }
348
349 args = 'apt install contrail-database -y --force-yes;'
350 check = 'nodetool status'
351
352 // ntw01
353 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
354 // ntw02
355 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
356 // ntw03
357 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
358
359 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
360 check = 'contrail-status'
361
362 // ntw01
363 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
364 // ntw02
365 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
366 // ntw03
367 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
368
369 try {
370 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail')
371 } catch (Exception er) {
372 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
373 }
374
375 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
376 salt.printSaltCommandResult(out)
377 }
378 }
379
380 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
381
382 try {
383
384 stage('List targeted compute servers') {
385 minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS)
386
387 if (minions.isEmpty()) {
388 throw new Exception("No minion was targeted")
389 }
390
391 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
392 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
393
394 targetLiveAll = minions.join(' or ')
395 common.infoMsg("Found nodes: ${targetLiveAll}")
396 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
397 }
398
399 stage('Confirm rollback on sample nodes') {
400 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
401 }
402
403 stage("Opencontrail compute rollback on sample nodes") {
404
405 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
406 oc_component_repo = oc_component_repo['return'][0].values()[0]
407
408 try {
409 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
410 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
411 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
412 } catch (Exception er) {
413 errorOccured = true
414 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
415 return
416 }
417
418 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
419 check = 'contrail-status'
420
421 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
422 salt.printSaltCommandResult(out)
423
424 try {
425 salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail')
426 } catch (Exception er) {
427 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
428 }
429
430 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
431 sleep(10)
432
433 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
434 salt.printSaltCommandResult(out)
435 }
436
437 stage('Confirm rollback on all targeted nodes') {
438 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
439 }
440
441 stage("Opencontrail compute upgrade on all targeted nodes") {
442
443 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
444 oc_component_repo = oc_component_repo['return'][0].values()[0]
445
446 try {
447 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
448 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
449 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo')
450 } catch (Exception er) {
451 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
452 return
453 }
454
455 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
456 check = 'contrail-status'
457
458 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
459 salt.printSaltCommandResult(out)
460
461 try {
462 salt.enforceState(saltMaster, targetLiveAll, 'opencontrail')
463 } catch (Exception er) {
464 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
465 }
466
467 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
468 sleep(10)
Jiri Broulik641e4102017-07-13 12:26:18 +0200469
470 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
471 salt.printSaltCommandResult(out)
472 }
473
474 } catch (Throwable e) {
475 // If there was an error or exception thrown, the build failed
476 currentBuild.result = "FAILURE"
477 throw e
478 }
479 }
480 }
481}