blob: af96600a034e335faa6487a79e2c48bc0b0cf394 [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'
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020036def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;'
37
chnyda625f4b42017-10-11 14:10:31 +020038def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) {
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020039
chnyda625f4b42017-10-11 14:10:31 +020040 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null)
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020041 salt.printSaltCommandResult(out)
Jiri Broulik375b0b32017-12-11 11:36:58 +010042 // if Error occured - throw exception
43 if (out.toString().contains('E: ')) {
44 throw new Exception("Command execution failed")
45 }
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020046 // wait until $check is in correct state
47 if ( check == "nodetool status" ) {
chnyda625f4b42017-10-11 14:10:31 +020048 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020049 } else if ( check == "contrail-status" ) {
Petr Jediný0fd757e2017-12-01 11:35:17 +010050 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 +020051 }
52
chnyda625f4b42017-10-11 14:10:31 +020053 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020054 //salt.printSaltCommandResult(out)
55 //input message: "Please check the output of \'${check}\' and continue if it is correct."
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020056}
Jakub Josefa63f9862018-01-11 17:58:38 +010057timeout(time: 12, unit: 'HOURS') {
58 node() {
Jiri Broulik641e4102017-07-13 12:26:18 +020059
Jakub Josefa63f9862018-01-11 17:58:38 +010060 stage('Setup virtualenv for Pepper') {
61 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040062 }
63
Jakub Josefa63f9862018-01-11 17:58:38 +010064 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040065
Jakub Josefa63f9862018-01-11 17:58:38 +010066 stage('Opencontrail controllers upgrade') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040067
Jakub Josefa63f9862018-01-11 17:58:38 +010068 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 +040069
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040070 oc_component_repo = oc_component_repo['return'][0].values()[0]
71
72 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010073 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
74 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
75 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040076 } catch (Exception er) {
77 errorOccured = true
Jakub Josefa63f9862018-01-11 17:58:38 +010078 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 +040079 return
80 }
81
Jakub Josefa63f9862018-01-11 17:58:38 +010082 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
83 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040084
85 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010086 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040087 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +010088 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040089 }
90
Jakub Josefa63f9862018-01-11 17:58:38 +010091 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
92 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040093
Jakub Josefa63f9862018-01-11 17:58:38 +010094 try {
95 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
96 } catch (Exception er) {
97 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
98 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040099
Jakub Josefa63f9862018-01-11 17:58:38 +0100100 args = 'apt install contrail-database -y;'
101 check = 'nodetool status'
102
103 // ntw01
104 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
105 // ntw02
106 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
107 // ntw03
108 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
109
110 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
111 check = 'contrail-status'
112
113 // ntw01
114 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
115 // ntw02
116 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
117 // ntw03
118 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
119
120 try {
121 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
122 } catch (Exception er) {
123 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
124 }
125
126 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400127 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100128
129 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
130 }
131 }
132
133 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
134
135 stage('Ask for manual confirmation') {
136 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400137 }
138
Jakub Josefa63f9862018-01-11 17:58:38 +0100139 stage('Opencontrail analytics upgrade') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400140
Jakub Josefa63f9862018-01-11 17:58:38 +0100141 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)
142
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400143 oc_component_repo = oc_component_repo['return'][0].values()[0]
144
145 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100146 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
147 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
148 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400149 } catch (Exception er) {
150 errorOccured = true
Jakub Josefa63f9862018-01-11 17:58:38 +0100151 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 +0400152 return
153 }
154
Jakub Josefa63f9862018-01-11 17:58:38 +0100155 args = 'apt install contrail-database -y;'
156 check = 'nodetool status'
157
158 // nal01
159 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
160 // nal02
161 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
162 // nal03
163 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
164
165 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400166 check = 'contrail-status'
167
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 // nal01
169 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
170 // nal02
171 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
172 // nal03
173 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400174
175 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400177 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100178 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400179 }
180
Jakub Josefa63f9862018-01-11 17:58:38 +0100181 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400182 salt.printSaltCommandResult(out)
183 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100184 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400185
Jakub Josefa63f9862018-01-11 17:58:38 +0100186 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
187
188 try {
189
190 stage('List targeted compute servers') {
191 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
192
193 if (minions.isEmpty()) {
194 throw new Exception("No minion was targeted")
195 }
196
197 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
198 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
199
200 targetLiveAll = minions.join(' or ')
201 common.infoMsg("Found nodes: ${targetLiveAll}")
202 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
203 }
204
205 stage('Confirm upgrade on sample nodes') {
206 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
207 }
208
209 stage("Opencontrail compute upgrade on sample nodes") {
210
211 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)
212 oc_component_repo = oc_component_repo['return'][0].values()[0]
213
214 try {
215 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
216 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
217 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
218 } catch (Exception er) {
219 errorOccured = true
220 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
221 return
222 }
223
224 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
225 check = 'contrail-status'
226
227 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
228 salt.printSaltCommandResult(out)
229
230 try {
231 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
232 } catch (Exception er) {
233 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
234 }
235
236 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
237
238 //sleep(10)
239 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
240
241 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
242 salt.printSaltCommandResult(out)
243 }
244
245 stage('Confirm upgrade on all targeted nodes') {
246 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
247 }
248 stage("Opencontrail compute upgrade on all targeted nodes") {
249
250 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)
251 oc_component_repo = oc_component_repo['return'][0].values()[0]
252
253 try {
254 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
255 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
256 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
257 } catch (Exception er) {
258 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
259 return
260 }
261
262 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
263 check = 'contrail-status'
264
265 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
266 salt.printSaltCommandResult(out)
267
268 try {
269 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
270 } catch (Exception er) {
271 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
272 }
273
274 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
275 //sleep(10)
276 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
277
278 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
279 salt.printSaltCommandResult(out)
280 }
281
282 } catch (Throwable e) {
283 // If there was an error or exception thrown, the build failed
284 currentBuild.result = "FAILURE"
285 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
286 throw e
287 }
288 }
289
290
291 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
292
293 stage('Ask for manual confirmation') {
294 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400295 }
296
Jakub Josefa63f9862018-01-11 17:58:38 +0100297 stage('Opencontrail controllers rollback') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400298
Jakub Josefa63f9862018-01-11 17:58:38 +0100299 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 +0400300 oc_component_repo = oc_component_repo['return'][0].values()[0]
301
302 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100303 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
304 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
305 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400306 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100307 errorOccured = true
308 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 +0400309 return
310 }
311
Jakub Josefa63f9862018-01-11 17:58:38 +0100312 args = 'apt install contrail-database -y --force-yes;'
313 check = 'nodetool status'
314
315 // ntw01
316 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
317 // ntw02
318 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
319 // ntw03
320 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
321
322 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400323 check = 'contrail-status'
324
Jakub Josefa63f9862018-01-11 17:58:38 +0100325 // ntw01
326 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
327 // ntw02
328 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
329 // ntw03
330 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400331
332 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100333 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400334 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100335 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400336 }
337
Jakub Josefa63f9862018-01-11 17:58:38 +0100338 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400339 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100340
341 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
342 }
343 }
344
345 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
346
347 stage('Ask for manual confirmation') {
348 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400349 }
350
Jakub Josefa63f9862018-01-11 17:58:38 +0100351 stage('Opencontrail analytics rollback') {
352
353 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)
354 oc_component_repo = oc_component_repo['return'][0].values()[0]
355
356 try {
357 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
358 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
359 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
360 } catch (Exception er) {
361 errorOccured = true
362 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
363 return
364 }
365
366 args = 'apt install contrail-database -y --force-yes;'
367 check = 'nodetool status'
368
369 // nal01
370 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
371 // nal02
372 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
373 // nal03
374 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
375
376 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
377 check = 'contrail-status'
378
379 // nal01
380 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
381 // nal02
382 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
383 // nal03
384 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
385
386 try {
387 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
388 } catch (Exception er) {
389 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
390 }
391
392 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
393 salt.printSaltCommandResult(out)
394 }
395 }
396
397 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
398
399 try {
400
401 stage('List targeted compute servers') {
402 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
403
404 if (minions.isEmpty()) {
405 throw new Exception("No minion was targeted")
406 }
407
408 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
409 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
410
411 targetLiveAll = minions.join(' or ')
412 common.infoMsg("Found nodes: ${targetLiveAll}")
413 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
414 }
415
416 stage('Confirm rollback on sample nodes') {
417 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
418 }
419
420 stage("Opencontrail compute rollback on sample nodes") {
421
422 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)
423 oc_component_repo = oc_component_repo['return'][0].values()[0]
424
425 try {
426 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
427 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
428 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
429 } catch (Exception er) {
430 errorOccured = true
431 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
432 return
433 }
434
435 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
436 check = 'contrail-status'
437
438 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
439 salt.printSaltCommandResult(out)
440
441 try {
442 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
443 } catch (Exception er) {
444 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
445 }
446
447 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
448 //sleep(10)
449 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
450
451 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
452 salt.printSaltCommandResult(out)
453 }
454
455 stage('Confirm rollback on all targeted nodes') {
456 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
457 }
458
459 stage("Opencontrail compute upgrade on all targeted nodes") {
460
461 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)
462 oc_component_repo = oc_component_repo['return'][0].values()[0]
463
464 try {
465 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
466 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
467 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
468 } catch (Exception er) {
469 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
470 return
471 }
472
473 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
474 check = 'contrail-status'
475
476 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
477 salt.printSaltCommandResult(out)
478
479 try {
480 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
481 } catch (Exception er) {
482 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
483 }
484
485 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
486
487 //sleep(10)
488 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
489
490 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
491 salt.printSaltCommandResult(out)
492 }
493
494 } catch (Throwable e) {
495 // If there was an error or exception thrown, the build failed
496 currentBuild.result = "FAILURE"
497 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
498 throw e
499 }
Jiri Broulik641e4102017-07-13 12:26:18 +0200500 }
501 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100502}