blob: 83f17ee53dc8f7c7bb008884855c625a5d7f52c9 [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}
Jiri Broulik641e4102017-07-13 12:26:18 +020057
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040058node() {
Jiri Broulik641e4102017-07-13 12:26:18 +020059
chnyda625f4b42017-10-11 14:10:31 +020060 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070061 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040062 }
Jiri Broulik641e4102017-07-13 12:26:18 +020063
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040064 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) {
Jiri Broulik641e4102017-07-13 12:26:18 +020065
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066 stage('Opencontrail controllers upgrade') {
Jiri Broulik641e4102017-07-13 12:26:18 +020067
chnyda625f4b42017-10-11 14:10:31 +020068 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 +020069
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040070 oc_component_repo = oc_component_repo['return'][0].values()[0]
Jiri Broulik641e4102017-07-13 12:26:18 +020071
72 try {
chnyda625f4b42017-10-11 14:10:31 +020073 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
78 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
79 return
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020080 }
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020081
Jiri Broulikcda54f82017-11-30 17:24:50 +010082 salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup')
83 salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup')
84
Jiri Broulikbdfa2fb2017-07-17 16:26:12 +020085 try {
chnyda625f4b42017-10-11 14:10:31 +020086 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) {
Jiri Broulik375b0b32017-12-11 11:36:58 +010088 throw new Exception('Zookeeper failed to backup. Please fix it before continuing.')
Jiri Broulik641e4102017-07-13 12:26:18 +020089 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040090
Jiri Broulikcda54f82017-11-30 17:24:50 +010091 salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup')
92 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup')
93
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040094 try {
chnyda625f4b42017-10-11 14:10:31 +020095 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 +040096 } catch (Exception er) {
Jiri Broulik375b0b32017-12-11 11:36:58 +010097 throw new Exception('Cassandra failed to backup. Please fix it before continuing.')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040098 }
99
100 args = 'apt install contrail-database -y;'
101 check = 'nodetool status'
102
103 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200104 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400105 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200106 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400107 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200108 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400109
110 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
111 check = 'contrail-status'
112
113 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200114 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400115 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200116 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400117 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200118 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400119
120 try {
chnyda625f4b42017-10-11 14:10:31 +0200121 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400122 } catch (Exception er) {
123 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
124 }
125
chnyda625f4b42017-10-11 14:10:31 +0200126 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)
128
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?"
137 }
138
139 stage('Opencontrail analytics upgrade') {
140
chnyda625f4b42017-10-11 14:10:31 +0200141 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 +0400142
143 oc_component_repo = oc_component_repo['return'][0].values()[0]
144
145 try {
chnyda625f4b42017-10-11 14:10:31 +0200146 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
151 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
152 return
153 }
154
155 args = 'apt install contrail-database -y;'
156 check = 'nodetool status'
157
158 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200159 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400160 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200161 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400162 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200163 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400164
165 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
166 check = 'contrail-status'
167
168 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200169 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400170 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200171 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400172 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200173 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400174
175 try {
chnyda625f4b42017-10-11 14:10:31 +0200176 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400177 } catch (Exception er) {
178 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
179 }
180
chnyda625f4b42017-10-11 14:10:31 +0200181 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 }
184 }
185
186 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
187
188 try {
189
190 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200191 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400192
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
chnyda625f4b42017-10-11 14:10:31 +0200211 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 +0400212 oc_component_repo = oc_component_repo['return'][0].values()[0]
213
214 try {
chnyda625f4b42017-10-11 14:10:31 +0200215 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400218 } 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
chnyda625f4b42017-10-11 14:10:31 +0200227 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400228 salt.printSaltCommandResult(out)
229
230 try {
chnyda625f4b42017-10-11 14:10:31 +0200231 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400232 } catch (Exception er) {
233 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
234 }
235
chnyda625f4b42017-10-11 14:10:31 +0200236 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400237
238 //sleep(10)
Petr Jediný0fd757e2017-12-01 11:35:17 +0100239 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400240
chnyda625f4b42017-10-11 14:10:31 +0200241 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400242 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
chnyda625f4b42017-10-11 14:10:31 +0200250 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 +0400251 oc_component_repo = oc_component_repo['return'][0].values()[0]
252
253 try {
chnyda625f4b42017-10-11 14:10:31 +0200254 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400257 } 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
chnyda625f4b42017-10-11 14:10:31 +0200265 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400266 salt.printSaltCommandResult(out)
267
268 try {
chnyda625f4b42017-10-11 14:10:31 +0200269 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400270 } catch (Exception er) {
271 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
272 }
273
chnyda625f4b42017-10-11 14:10:31 +0200274 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400275 //sleep(10)
Petr Jediný0fd757e2017-12-01 11:35:17 +0100276 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400277
chnyda625f4b42017-10-11 14:10:31 +0200278 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400279 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"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200285 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400286 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?"
295 }
296
297 stage('Opencontrail controllers rollback') {
298
chnyda625f4b42017-10-11 14:10:31 +0200299 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 {
chnyda625f4b42017-10-11 14:10:31 +0200303 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) {
307 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.")
309 return
310 }
311
312 args = 'apt install contrail-database -y --force-yes;'
313 check = 'nodetool status'
314
315 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200316 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400317 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200318 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400319 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200320 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400321
322 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
323 check = 'contrail-status'
324
325 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200326 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400327 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200328 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400329 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200330 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400331
332 try {
chnyda625f4b42017-10-11 14:10:31 +0200333 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400334 } catch (Exception er) {
335 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
336 }
337
chnyda625f4b42017-10-11 14:10:31 +0200338 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)
340
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?"
349 }
350
351 stage('Opencontrail analytics rollback') {
352
chnyda625f4b42017-10-11 14:10:31 +0200353 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 +0400354 oc_component_repo = oc_component_repo['return'][0].values()[0]
355
356 try {
chnyda625f4b42017-10-11 14:10:31 +0200357 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400360 } 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
chnyda625f4b42017-10-11 14:10:31 +0200370 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400371 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200372 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400373 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200374 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400375
376 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
377 check = 'contrail-status'
378
379 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200380 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400381 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200382 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400383 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200384 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400385
386 try {
chnyda625f4b42017-10-11 14:10:31 +0200387 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400388 } catch (Exception er) {
389 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
390 }
391
chnyda625f4b42017-10-11 14:10:31 +0200392 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400393 salt.printSaltCommandResult(out)
394 }
395 }
396
397 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
398
399 try {
400
401 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200402 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400403
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
chnyda625f4b42017-10-11 14:10:31 +0200422 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 +0400423 oc_component_repo = oc_component_repo['return'][0].values()[0]
424
425 try {
chnyda625f4b42017-10-11 14:10:31 +0200426 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400429 } 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
chnyda625f4b42017-10-11 14:10:31 +0200438 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400439 salt.printSaltCommandResult(out)
440
441 try {
chnyda625f4b42017-10-11 14:10:31 +0200442 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400443 } catch (Exception er) {
444 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
445 }
446
chnyda625f4b42017-10-11 14:10:31 +0200447 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400448 //sleep(10)
Petr Jediný0fd757e2017-12-01 11:35:17 +0100449 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400450
chnyda625f4b42017-10-11 14:10:31 +0200451 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400452 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
chnyda625f4b42017-10-11 14:10:31 +0200461 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 +0400462 oc_component_repo = oc_component_repo['return'][0].values()[0]
463
464 try {
chnyda625f4b42017-10-11 14:10:31 +0200465 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400468 } 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
chnyda625f4b42017-10-11 14:10:31 +0200476 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400477 salt.printSaltCommandResult(out)
478
479 try {
chnyda625f4b42017-10-11 14:10:31 +0200480 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400481 } catch (Exception er) {
482 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
483 }
484
chnyda625f4b42017-10-11 14:10:31 +0200485 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400486
487 //sleep(10)
Petr Jediný0fd757e2017-12-01 11:35:17 +0100488 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400489
chnyda625f4b42017-10-11 14:10:31 +0200490 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400491 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"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200497 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400498 throw e
Jiri Broulik641e4102017-07-13 12:26:18 +0200499 }
500 }
501}