blob: de385ea9e9a809be4566ab1efa90c7c3b4852e03 [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'
35def 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'
36def 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 Broulik8dabbfd2017-07-25 10:49:45 +020042 // wait until $check is in correct state
43 if ( check == "nodetool status" ) {
chnyda625f4b42017-10-11 14:10:31 +020044 salt.commandStatus(pepperEnv, target, check, 'Status=Up')
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020045 } else if ( check == "contrail-status" ) {
chnyda625f4b42017-10-11 14:10:31 +020046 salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020047 }
48
chnyda625f4b42017-10-11 14:10:31 +020049 //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null)
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020050 //salt.printSaltCommandResult(out)
51 //input message: "Please check the output of \'${check}\' and continue if it is correct."
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020052}
Jiri Broulik641e4102017-07-13 12:26:18 +020053
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040054node() {
Jiri Broulik641e4102017-07-13 12:26:18 +020055
chnyda625f4b42017-10-11 14:10:31 +020056 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070057 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040058 }
Jiri Broulik641e4102017-07-13 12:26:18 +020059
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040060 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +020061
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040062 stage('Opencontrail controllers upgrade') {
Jiri Broulik641e4102017-07-13 12:26:18 +020063
chnyda625f4b42017-10-11 14:10:31 +020064 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)
Jiri Broulik641e4102017-07-13 12:26:18 +020065
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +020067
68 try {
chnyda625f4b42017-10-11 14:10:31 +020069 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
70 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
71 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040072 } catch (Exception er) {
73 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.")
75 return
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020076 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020077
Jiri Broulikcda54f82017-11-30 17:24:50 +010078 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
79 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
80
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020081 try {
chnyda625f4b42017-10-11 14:10:31 +020082 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040083 } catch (Exception er) {
84 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
85 return
Jiri Broulik641e4102017-07-13 12:26:18 +020086 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040087
Jiri Broulikcda54f82017-11-30 17:24:50 +010088 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
89 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
90
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040091 try {
chnyda625f4b42017-10-11 14:10:31 +020092 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040093 } catch (Exception er) {
94 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
95 return
96 }
97
98 args = 'apt install contrail-database -y;'
99 check = 'nodetool status'
100
101 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200102 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400103 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200104 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400105 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200106 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400107
108 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
109 check = 'contrail-status'
110
111 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200112 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400113 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200114 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400115 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200116 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400117
118 try {
chnyda625f4b42017-10-11 14:10:31 +0200119 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400120 } catch (Exception er) {
121 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
122 }
123
chnyda625f4b42017-10-11 14:10:31 +0200124 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400125 salt.printSaltCommandResult(out)
126
127 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?"
135 }
136
137 stage('Opencontrail analytics upgrade') {
138
chnyda625f4b42017-10-11 14:10:31 +0200139 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400140
141 oc_component_repo = oc_component_repo['return'][0].values()[0]
142
143 try {
chnyda625f4b42017-10-11 14:10:31 +0200144 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
149 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
150 return
151 }
152
153 args = 'apt install contrail-database -y;'
154 check = 'nodetool status'
155
156 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200157 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400158 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200159 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400160 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200161 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400162
163 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
164 check = 'contrail-status'
165
166 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200167 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400168 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200169 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400170 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200171 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400172
173 try {
chnyda625f4b42017-10-11 14:10:31 +0200174 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400175 } catch (Exception er) {
176 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
177 }
178
chnyda625f4b42017-10-11 14:10:31 +0200179 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400180 salt.printSaltCommandResult(out)
181 }
182 }
183
184 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
185
186 try {
187
188 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200189 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400190
191 if (minions.isEmpty()) {
192 throw new Exception("No minion was targeted")
193 }
194
195 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
196 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
197
198 targetLiveAll = minions.join(' or ')
199 common.infoMsg("Found nodes: ${targetLiveAll}")
200 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
201 }
202
203 stage('Confirm upgrade on sample nodes') {
204 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
205 }
206
207 stage("Opencontrail compute upgrade on sample nodes") {
208
chnyda625f4b42017-10-11 14:10:31 +0200209 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400210 oc_component_repo = oc_component_repo['return'][0].values()[0]
211
212 try {
chnyda625f4b42017-10-11 14:10:31 +0200213 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
214 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
215 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400216 } catch (Exception er) {
217 errorOccured = true
218 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
219 return
220 }
221
222 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
223 check = 'contrail-status'
224
chnyda625f4b42017-10-11 14:10:31 +0200225 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400226 salt.printSaltCommandResult(out)
227
228 try {
chnyda625f4b42017-10-11 14:10:31 +0200229 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400230 } catch (Exception er) {
231 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
232 }
233
chnyda625f4b42017-10-11 14:10:31 +0200234 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400235
236 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200237 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400238
chnyda625f4b42017-10-11 14:10:31 +0200239 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400240 salt.printSaltCommandResult(out)
241 }
242
243 stage('Confirm upgrade on all targeted nodes') {
244 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
245 }
246 stage("Opencontrail compute upgrade on all targeted nodes") {
247
chnyda625f4b42017-10-11 14:10:31 +0200248 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400249 oc_component_repo = oc_component_repo['return'][0].values()[0]
250
251 try {
chnyda625f4b42017-10-11 14:10:31 +0200252 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
253 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
254 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400255 } catch (Exception er) {
256 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
257 return
258 }
259
260 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
261 check = 'contrail-status'
262
chnyda625f4b42017-10-11 14:10:31 +0200263 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400264 salt.printSaltCommandResult(out)
265
266 try {
chnyda625f4b42017-10-11 14:10:31 +0200267 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400268 } catch (Exception er) {
269 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
270 }
271
chnyda625f4b42017-10-11 14:10:31 +0200272 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400273 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200274 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400275
chnyda625f4b42017-10-11 14:10:31 +0200276 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400277 salt.printSaltCommandResult(out)
278 }
279
280 } catch (Throwable e) {
281 // If there was an error or exception thrown, the build failed
282 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200283 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400284 throw e
285 }
286 }
287
288
289 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
290
291 stage('Ask for manual confirmation') {
292 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
293 }
294
295 stage('Opencontrail controllers rollback') {
296
chnyda625f4b42017-10-11 14:10:31 +0200297 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 +0400298 oc_component_repo = oc_component_repo['return'][0].values()[0]
299
300 try {
chnyda625f4b42017-10-11 14:10:31 +0200301 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
302 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
303 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400304 } catch (Exception er) {
305 errorOccured = true
306 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
307 return
308 }
309
310 args = 'apt install contrail-database -y --force-yes;'
311 check = 'nodetool status'
312
313 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200314 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400315 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200316 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400317 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200318 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400319
320 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
321 check = 'contrail-status'
322
323 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200324 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400325 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200326 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400327 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200328 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400329
330 try {
chnyda625f4b42017-10-11 14:10:31 +0200331 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400332 } catch (Exception er) {
333 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
334 }
335
chnyda625f4b42017-10-11 14:10:31 +0200336 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400337 salt.printSaltCommandResult(out)
338
339 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
340 }
341 }
342
343 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
344
345 stage('Ask for manual confirmation') {
346 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
347 }
348
349 stage('Opencontrail analytics rollback') {
350
chnyda625f4b42017-10-11 14:10:31 +0200351 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400352 oc_component_repo = oc_component_repo['return'][0].values()[0]
353
354 try {
chnyda625f4b42017-10-11 14:10:31 +0200355 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
356 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
357 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400358 } catch (Exception er) {
359 errorOccured = true
360 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
361 return
362 }
363
364 args = 'apt install contrail-database -y --force-yes;'
365 check = 'nodetool status'
366
367 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200368 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400369 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200370 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400371 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200372 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400373
374 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
375 check = 'contrail-status'
376
377 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200378 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400379 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200380 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400381 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200382 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400383
384 try {
chnyda625f4b42017-10-11 14:10:31 +0200385 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400386 } catch (Exception er) {
387 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
388 }
389
chnyda625f4b42017-10-11 14:10:31 +0200390 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400391 salt.printSaltCommandResult(out)
392 }
393 }
394
395 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
396
397 try {
398
399 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200400 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400401
402 if (minions.isEmpty()) {
403 throw new Exception("No minion was targeted")
404 }
405
406 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
407 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
408
409 targetLiveAll = minions.join(' or ')
410 common.infoMsg("Found nodes: ${targetLiveAll}")
411 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
412 }
413
414 stage('Confirm rollback on sample nodes') {
415 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
416 }
417
418 stage("Opencontrail compute rollback on sample nodes") {
419
chnyda625f4b42017-10-11 14:10:31 +0200420 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400421 oc_component_repo = oc_component_repo['return'][0].values()[0]
422
423 try {
chnyda625f4b42017-10-11 14:10:31 +0200424 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
425 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
426 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400427 } catch (Exception er) {
428 errorOccured = true
429 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
430 return
431 }
432
433 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
434 check = 'contrail-status'
435
chnyda625f4b42017-10-11 14:10:31 +0200436 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400437 salt.printSaltCommandResult(out)
438
439 try {
chnyda625f4b42017-10-11 14:10:31 +0200440 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400441 } catch (Exception er) {
442 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
443 }
444
chnyda625f4b42017-10-11 14:10:31 +0200445 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400446 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200447 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400448
chnyda625f4b42017-10-11 14:10:31 +0200449 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400450 salt.printSaltCommandResult(out)
451 }
452
453 stage('Confirm rollback on all targeted nodes') {
454 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
455 }
456
457 stage("Opencontrail compute upgrade on all targeted nodes") {
458
chnyda625f4b42017-10-11 14:10:31 +0200459 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)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400460 oc_component_repo = oc_component_repo['return'][0].values()[0]
461
462 try {
chnyda625f4b42017-10-11 14:10:31 +0200463 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
464 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
465 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400466 } catch (Exception er) {
467 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
468 return
469 }
470
471 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
472 check = 'contrail-status'
473
chnyda625f4b42017-10-11 14:10:31 +0200474 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400475 salt.printSaltCommandResult(out)
476
477 try {
chnyda625f4b42017-10-11 14:10:31 +0200478 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400479 } catch (Exception er) {
480 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
481 }
482
chnyda625f4b42017-10-11 14:10:31 +0200483 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400484
485 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200486 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400487
chnyda625f4b42017-10-11 14:10:31 +0200488 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400489 salt.printSaltCommandResult(out)
490 }
491
492 } catch (Throwable e) {
493 // If there was an error or exception thrown, the build failed
494 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200495 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400496 throw e
Jiri Broulik641e4102017-07-13 12:26:18 +0200497 }
498 }
499}