blob: a01affe70015d3d6512bbb3073f649eb082c8d4b [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
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020037def void runCommonCommands(target, command, args, check, salt, saltMaster, common) {
38
39 out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
40 salt.printSaltCommandResult(out)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020041 // wait until $check is in correct state
42 if ( check == "nodetool status" ) {
43 salt.commandStatus(saltMaster, target, check, 'Status=Up')
44 } else if ( check == "contrail-status" ) {
45 salt.commandStatus(saltMaster, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
46 }
47
48 //out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
49 //salt.printSaltCommandResult(out)
50 //input message: "Please check the output of \'${check}\' and continue if it is correct."
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020051}
Jiri Broulik641e4102017-07-13 12:26:18 +020052
53timestamps {
54 node() {
55
56 stage('Connect to Salt API') {
57 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
58 }
59
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020060 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +020061
62 stage('Opencontrail controllers upgrade') {
63
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020064 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 +020065
Jiri Broulik641e4102017-07-13 12:26:18 +020066 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +020067
68 try {
Jiri Broulik641e4102017-07-13 12:26:18 +020069 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
70 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
71 salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo')
72 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020073 errorOccured = true
74 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 +020075 return
76 }
77
78 try {
79 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
80 } catch (Exception er) {
81 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
82 return
83 }
84
85 try {
86 salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
87 } catch (Exception er) {
88 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
89 return
90 }
91
Jiri Broulik641e4102017-07-13 12:26:18 +020092 args = 'apt install contrail-database -y;'
93 check = 'nodetool status'
94
95 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020096 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +020097 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020098 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +020099 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200100 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200101
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200102 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
Jiri Broulik641e4102017-07-13 12:26:18 +0200103 check = 'contrail-status'
104
105 // ntw01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200106 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200107 // ntw02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200108 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200109 // ntw03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200110 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200111
Jiri Broulik641e4102017-07-13 12:26:18 +0200112 try {
113 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail')
114 } catch (Exception er) {
115 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
116 }
117
118 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
119 salt.printSaltCommandResult(out)
120
121 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
122 }
123 }
124
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200125 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +0200126
127 stage('Ask for manual confirmation') {
128 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
129 }
130
131 stage('Opencontrail analytics upgrade') {
132
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200133 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 +0200134
Jiri Broulik641e4102017-07-13 12:26:18 +0200135 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200136
137 try {
Jiri Broulik641e4102017-07-13 12:26:18 +0200138 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
139 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
140 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo')
141 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200142 errorOccured = true
143 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 +0200144 return
145 }
146
Jiri Broulik641e4102017-07-13 12:26:18 +0200147 args = 'apt install contrail-database -y;'
148 check = 'nodetool status'
149
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200150 // nal01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200151 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200152 // nal02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200153 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200154 // nal03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200155 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200156
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200157 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
Jiri Broulik641e4102017-07-13 12:26:18 +0200158 check = 'contrail-status'
159
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200160 // nal01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200161 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200162 // nal02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200163 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200164 // nal03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200165 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
Jiri Broulik641e4102017-07-13 12:26:18 +0200166
Jiri Broulik641e4102017-07-13 12:26:18 +0200167 try {
168 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail')
169 } catch (Exception er) {
170 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
171 }
172
173 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
174 salt.printSaltCommandResult(out)
175 }
Jiri Broulik641e4102017-07-13 12:26:18 +0200176 }
177
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200178 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +0200179
180 try {
181
182 stage('List targeted compute servers') {
183 minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS)
184
185 if (minions.isEmpty()) {
186 throw new Exception("No minion was targeted")
187 }
188
189 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
190 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
191
192 targetLiveAll = minions.join(' or ')
193 common.infoMsg("Found nodes: ${targetLiveAll}")
194 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
195 }
196
197 stage('Confirm upgrade on sample nodes') {
198 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
199 }
200
201 stage("Opencontrail compute upgrade on sample nodes") {
202
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200203 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 +0200204 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200205
206 try {
207 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
208 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
209 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
210 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200211 errorOccured = true
212 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 +0200213 return
214 }
215
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200216 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 +0200217 check = 'contrail-status'
218
Jiri Broulik641e4102017-07-13 12:26:18 +0200219 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
220 salt.printSaltCommandResult(out)
Jiri Broulik641e4102017-07-13 12:26:18 +0200221
Jiri Broulik641e4102017-07-13 12:26:18 +0200222 try {
223 salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail')
224 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200225 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200226 }
227
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200228 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200229
230 //sleep(10)
231 salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Jiri Broulik641e4102017-07-13 12:26:18 +0200232
233 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
234 salt.printSaltCommandResult(out)
235 }
236
237 stage('Confirm upgrade on all targeted nodes') {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200238 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 +0200239 }
240 stage("Opencontrail compute upgrade on all targeted nodes") {
241
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200242 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 +0200243 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +0200244
245 try {
246 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
247 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
248 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo')
249 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200250 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 +0200251 return
252 }
253
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200254 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 +0200255 check = 'contrail-status'
256
Jiri Broulik641e4102017-07-13 12:26:18 +0200257 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
258 salt.printSaltCommandResult(out)
Jiri Broulik641e4102017-07-13 12:26:18 +0200259
Jiri Broulik641e4102017-07-13 12:26:18 +0200260 try {
261 salt.enforceState(saltMaster, targetLiveAll, 'opencontrail')
262 } catch (Exception er) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200263 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
Jiri Broulik641e4102017-07-13 12:26:18 +0200264 }
265
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200266 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200267 //sleep(10)
268 salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200269
270 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
271 salt.printSaltCommandResult(out)
272 }
273
274 } catch (Throwable e) {
275 // If there was an error or exception thrown, the build failed
276 currentBuild.result = "FAILURE"
277 throw e
278 }
279 }
280
281
282 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
283
284 stage('Ask for manual confirmation') {
285 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
286 }
287
288 stage('Opencontrail controllers rollback') {
289
290 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)
291 oc_component_repo = oc_component_repo['return'][0].values()[0]
292
293 try {
294 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
295 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
296 salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo')
297 } catch (Exception er) {
298 errorOccured = true
299 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
300 return
301 }
302
303 args = 'apt install contrail-database -y --force-yes;'
304 check = 'nodetool status'
305
306 // ntw01
307 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
308 // ntw02
309 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
310 // ntw03
311 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
312
313 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
314 check = 'contrail-status'
315
316 // ntw01
317 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common)
318 // ntw02
319 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common)
320 // ntw03
321 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common)
322
323 try {
324 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail')
325 } catch (Exception er) {
326 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
327 }
328
329 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
330 salt.printSaltCommandResult(out)
331
332 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
333 }
334 }
335
336 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
337
338 stage('Ask for manual confirmation') {
339 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
340 }
341
342 stage('Opencontrail analytics rollback') {
343
344 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)
345 oc_component_repo = oc_component_repo['return'][0].values()[0]
346
347 try {
348 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
349 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
350 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo')
351 } catch (Exception er) {
352 errorOccured = true
353 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
354 return
355 }
356
357 args = 'apt install contrail-database -y --force-yes;'
358 check = 'nodetool status'
359
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200360 // nal01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200361 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200362 // nal02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200363 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200364 // nal03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200365 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
366
367 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
368 check = 'contrail-status'
369
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200370 // nal01
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200371 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200372 // nal02
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200373 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200374 // nal03
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200375 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common)
376
377 try {
378 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail')
379 } catch (Exception er) {
380 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
381 }
382
383 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
384 salt.printSaltCommandResult(out)
385 }
386 }
387
388 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
389
390 try {
391
392 stage('List targeted compute servers') {
393 minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS)
394
395 if (minions.isEmpty()) {
396 throw new Exception("No minion was targeted")
397 }
398
399 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
400 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
401
402 targetLiveAll = minions.join(' or ')
403 common.infoMsg("Found nodes: ${targetLiveAll}")
404 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
405 }
406
407 stage('Confirm rollback on sample nodes') {
408 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
409 }
410
411 stage("Opencontrail compute rollback on sample nodes") {
412
413 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)
414 oc_component_repo = oc_component_repo['return'][0].values()[0]
415
416 try {
417 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
418 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
419 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
420 } catch (Exception er) {
421 errorOccured = true
422 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
423 return
424 }
425
426 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
427 check = 'contrail-status'
428
429 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
430 salt.printSaltCommandResult(out)
431
432 try {
433 salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail')
434 } catch (Exception er) {
435 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
436 }
437
438 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200439 //sleep(10)
440 salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +0200441
442 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
443 salt.printSaltCommandResult(out)
444 }
445
446 stage('Confirm rollback on all targeted nodes') {
447 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
448 }
449
450 stage("Opencontrail compute upgrade on all targeted nodes") {
451
452 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)
453 oc_component_repo = oc_component_repo['return'][0].values()[0]
454
455 try {
456 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
457 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
458 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo')
459 } catch (Exception er) {
460 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
461 return
462 }
463
464 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
465 check = 'contrail-status'
466
467 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
468 salt.printSaltCommandResult(out)
469
470 try {
471 salt.enforceState(saltMaster, targetLiveAll, 'opencontrail')
472 } catch (Exception er) {
473 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
474 }
475
476 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +0200477
478 //sleep(10)
479 salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Jiri Broulik641e4102017-07-13 12:26:18 +0200480
481 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
482 salt.printSaltCommandResult(out)
483 }
484
485 } catch (Throwable e) {
486 // If there was an error or exception thrown, the build failed
487 currentBuild.result = "FAILURE"
488 throw e
489 }
490 }
491 }
492}