blob: 7c761a03a2f948113591e4aa5001adbe9fd14672 [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
Denis Egorenko14fa6e12019-08-23 14:29:34 +040069 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', '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
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400106 runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common)
107 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100108
109 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
110 check = 'contrail-status'
111
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400112 runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common)
113 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100114
115 try {
116 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
117 } catch (Exception er) {
118 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
119 }
120
121 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400122 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100123
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400124 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
125 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
126
Jakub Josefa63f9862018-01-11 17:58:38 +0100127 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
128 }
129 }
130
131 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
132
133 stage('Ask for manual confirmation') {
134 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400135 }
136
Jakub Josefa63f9862018-01-11 17:58:38 +0100137 stage('Opencontrail analytics upgrade') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400138
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400139 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector:role:primary', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100140
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400141 oc_component_repo = oc_component_repo['return'][0].values()[0]
142
143 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100144 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
145 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
146 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400147 } catch (Exception er) {
148 errorOccured = true
Jakub Josefa63f9862018-01-11 17:58:38 +0100149 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 +0400150 return
151 }
152
Jakub Josefa63f9862018-01-11 17:58:38 +0100153 args = 'apt install contrail-database -y;'
154 check = 'nodetool status'
155
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400156 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
157 runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100158
159 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400160 check = 'contrail-status'
161
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400162 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
163 runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400164
165 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100166 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400167 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100168 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400169 }
170
Jakub Josefa63f9862018-01-11 17:58:38 +0100171 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400172 salt.printSaltCommandResult(out)
173 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100174 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400175
Jakub Josefa63f9862018-01-11 17:58:38 +0100176 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
177
178 try {
179
180 stage('List targeted compute servers') {
181 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
182
183 if (minions.isEmpty()) {
184 throw new Exception("No minion was targeted")
185 }
186
187 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
188 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
189
190 targetLiveAll = minions.join(' or ')
191 common.infoMsg("Found nodes: ${targetLiveAll}")
192 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
193 }
194
195 stage('Confirm upgrade on sample nodes') {
196 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
197 }
198
199 stage("Opencontrail compute upgrade on sample nodes") {
200
201 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)
202 oc_component_repo = oc_component_repo['return'][0].values()[0]
203
204 try {
205 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
206 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
207 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
208 } catch (Exception er) {
209 errorOccured = true
210 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
211 return
212 }
213
azvyagintsev93e05cc2018-12-26 13:53:02 +0200214 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100215 check = 'contrail-status'
216
217 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
218 salt.printSaltCommandResult(out)
219
220 try {
221 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
222 } catch (Exception er) {
223 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
224 }
225
226 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
227
228 //sleep(10)
229 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
230
231 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
232 salt.printSaltCommandResult(out)
233 }
234
235 stage('Confirm upgrade on all targeted nodes') {
236 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
237 }
238 stage("Opencontrail compute upgrade on all targeted nodes") {
239
240 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)
241 oc_component_repo = oc_component_repo['return'][0].values()[0]
242
243 try {
244 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
245 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
246 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
247 } catch (Exception er) {
248 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
249 return
250 }
251
azvyagintsev93e05cc2018-12-26 13:53:02 +0200252 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100253 check = 'contrail-status'
254
255 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
256 salt.printSaltCommandResult(out)
257
258 try {
259 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
260 } catch (Exception er) {
261 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
262 }
263
264 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
265 //sleep(10)
266 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
267
268 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
269 salt.printSaltCommandResult(out)
270 }
271
272 } catch (Throwable e) {
273 // If there was an error or exception thrown, the build failed
274 currentBuild.result = "FAILURE"
275 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
276 throw e
277 }
278 }
279
280
281 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
282
283 stage('Ask for manual confirmation') {
284 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400285 }
286
Jakub Josefa63f9862018-01-11 17:58:38 +0100287 stage('Opencontrail controllers rollback') {
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400288
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400289 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', '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 +0400290 oc_component_repo = oc_component_repo['return'][0].values()[0]
291
292 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100293 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400294 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'saltutil.refresh_pillar', [], null, true)
295 salt.enforceState(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400296 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100297 errorOccured = true
298 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 +0400299 return
300 }
301
Jakub Josefa63f9862018-01-11 17:58:38 +0100302 args = 'apt install contrail-database -y --force-yes;'
303 check = 'nodetool status'
304
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400305 runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common)
306 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100307
308 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400309 check = 'contrail-status'
310
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400311 runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common)
312 runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400313
314 try {
Jakub Josefa63f9862018-01-11 17:58:38 +0100315 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400316 } catch (Exception er) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100317 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400318 }
319
Jakub Josefa63f9862018-01-11 17:58:38 +0100320 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400321 salt.printSaltCommandResult(out)
Jakub Josefa63f9862018-01-11 17:58:38 +0100322
Anton Samoylov0d642aa2018-11-08 15:22:27 +0400323 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'])
324 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs])
325 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs])
326 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'])
327
Jakub Josefa63f9862018-01-11 17:58:38 +0100328 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
329 }
330 }
331
332 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
333
334 stage('Ask for manual confirmation') {
335 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400336 }
337
Jakub Josefa63f9862018-01-11 17:58:38 +0100338 stage('Opencontrail analytics rollback') {
339
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400340 oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector:role:primary', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +0100341 oc_component_repo = oc_component_repo['return'][0].values()[0]
342
343 try {
344 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
345 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
346 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
347 } catch (Exception er) {
348 errorOccured = true
349 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
350 return
351 }
352
353 args = 'apt install contrail-database -y --force-yes;'
354 check = 'nodetool status'
355
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400356 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
357 runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100358
359 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
360 check = 'contrail-status'
361
Denis Egorenko14fa6e12019-08-23 14:29:34 +0400362 runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common)
363 runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common)
Jakub Josefa63f9862018-01-11 17:58:38 +0100364
365 try {
366 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
367 } catch (Exception er) {
368 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
369 }
370
371 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
372 salt.printSaltCommandResult(out)
373 }
374 }
375
376 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
377
378 try {
379
380 stage('List targeted compute servers') {
381 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
382
383 if (minions.isEmpty()) {
384 throw new Exception("No minion was targeted")
385 }
386
387 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
388 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
389
390 targetLiveAll = minions.join(' or ')
391 common.infoMsg("Found nodes: ${targetLiveAll}")
392 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
393 }
394
395 stage('Confirm rollback on sample nodes') {
396 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
397 }
398
399 stage("Opencontrail compute rollback on sample nodes") {
400
401 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)
402 oc_component_repo = oc_component_repo['return'][0].values()[0]
403
404 try {
405 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
406 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
407 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
408 } catch (Exception er) {
409 errorOccured = true
410 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
411 return
412 }
413
azvyagintsev93e05cc2018-12-26 13:53:02 +0200414 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100415 check = 'contrail-status'
416
417 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
418 salt.printSaltCommandResult(out)
419
420 try {
421 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
422 } catch (Exception er) {
423 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
424 }
425
426 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
427 //sleep(10)
428 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
429
430 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
431 salt.printSaltCommandResult(out)
432 }
433
434 stage('Confirm rollback on all targeted nodes') {
435 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
436 }
437
438 stage("Opencontrail compute upgrade on all targeted nodes") {
439
440 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)
441 oc_component_repo = oc_component_repo['return'][0].values()[0]
442
443 try {
444 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
445 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
446 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
447 } catch (Exception er) {
448 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
449 return
450 }
451
azvyagintsev93e05cc2018-12-26 13:53:02 +0200452 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;"
Jakub Josefa63f9862018-01-11 17:58:38 +0100453 check = 'contrail-status'
454
455 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
456 salt.printSaltCommandResult(out)
457
458 try {
459 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
460 } catch (Exception er) {
461 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
462 }
463
464 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
465
466 //sleep(10)
467 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
468
469 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
470 salt.printSaltCommandResult(out)
471 }
472
473 } catch (Throwable e) {
474 // If there was an error or exception thrown, the build failed
475 currentBuild.result = "FAILURE"
476 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
477 throw e
478 }
Jiri Broulik641e4102017-07-13 12:26:18 +0200479 }
480 }
azvyagintsev93e05cc2018-12-26 13:53:02 +0200481}