blob: 311cfefee0921c0a4d5b2bfdb2bfb154ad57dc1b [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
78 try {
chnyda625f4b42017-10-11 14:10:31 +020079 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040080 } catch (Exception er) {
81 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
82 return
Jiri Broulik641e4102017-07-13 12:26:18 +020083 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040084
85 try {
chnyda625f4b42017-10-11 14:10:31 +020086 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 +040087 } catch (Exception er) {
88 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
89 return
90 }
91
92 args = 'apt install contrail-database -y;'
93 check = 'nodetool status'
94
95 // ntw01
chnyda625f4b42017-10-11 14:10:31 +020096 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040097 // ntw02
chnyda625f4b42017-10-11 14:10:31 +020098 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040099 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200100 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400101
102 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
103 check = 'contrail-status'
104
105 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200106 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400107 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200108 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400109 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200110 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400111
112 try {
chnyda625f4b42017-10-11 14:10:31 +0200113 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400114 } catch (Exception er) {
115 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
116 }
117
chnyda625f4b42017-10-11 14:10:31 +0200118 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400119 salt.printSaltCommandResult(out)
120
121 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
122 }
123 }
124
125 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) {
126
127 stage('Ask for manual confirmation') {
128 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
129 }
130
131 stage('Opencontrail analytics upgrade') {
132
chnyda625f4b42017-10-11 14:10:31 +0200133 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 +0400134
135 oc_component_repo = oc_component_repo['return'][0].values()[0]
136
137 try {
chnyda625f4b42017-10-11 14:10:31 +0200138 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
139 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
140 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400141 } catch (Exception er) {
142 errorOccured = true
143 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
144 return
145 }
146
147 args = 'apt install contrail-database -y;'
148 check = 'nodetool status'
149
150 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200151 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400152 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200153 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400154 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200155 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400156
157 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
158 check = 'contrail-status'
159
160 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200161 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400162 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200163 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400164 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200165 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400166
167 try {
chnyda625f4b42017-10-11 14:10:31 +0200168 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400169 } catch (Exception er) {
170 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
171 }
172
chnyda625f4b42017-10-11 14:10:31 +0200173 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400174 salt.printSaltCommandResult(out)
175 }
176 }
177
178 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) {
179
180 try {
181
182 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200183 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400184
185 if (minions.isEmpty()) {
186 throw new Exception("No minion was targeted")
187 }
188
189 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
190 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
191
192 targetLiveAll = minions.join(' or ')
193 common.infoMsg("Found nodes: ${targetLiveAll}")
194 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
195 }
196
197 stage('Confirm upgrade on sample nodes') {
198 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
199 }
200
201 stage("Opencontrail compute upgrade on sample nodes") {
202
chnyda625f4b42017-10-11 14:10:31 +0200203 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 +0400204 oc_component_repo = oc_component_repo['return'][0].values()[0]
205
206 try {
chnyda625f4b42017-10-11 14:10:31 +0200207 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
208 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
209 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400210 } catch (Exception er) {
211 errorOccured = true
212 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
213 return
214 }
215
216 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
217 check = 'contrail-status'
218
chnyda625f4b42017-10-11 14:10:31 +0200219 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400220 salt.printSaltCommandResult(out)
221
222 try {
chnyda625f4b42017-10-11 14:10:31 +0200223 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400224 } catch (Exception er) {
225 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
226 }
227
chnyda625f4b42017-10-11 14:10:31 +0200228 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400229
230 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200231 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400232
chnyda625f4b42017-10-11 14:10:31 +0200233 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400234 salt.printSaltCommandResult(out)
235 }
236
237 stage('Confirm upgrade on all targeted nodes') {
238 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
239 }
240 stage("Opencontrail compute upgrade on all targeted nodes") {
241
chnyda625f4b42017-10-11 14:10:31 +0200242 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 +0400243 oc_component_repo = oc_component_repo['return'][0].values()[0]
244
245 try {
chnyda625f4b42017-10-11 14:10:31 +0200246 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
247 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
248 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400249 } catch (Exception er) {
250 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
251 return
252 }
253
254 args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
255 check = 'contrail-status'
256
chnyda625f4b42017-10-11 14:10:31 +0200257 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400258 salt.printSaltCommandResult(out)
259
260 try {
chnyda625f4b42017-10-11 14:10:31 +0200261 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400262 } catch (Exception er) {
263 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
264 }
265
chnyda625f4b42017-10-11 14:10:31 +0200266 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400267 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200268 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400269
chnyda625f4b42017-10-11 14:10:31 +0200270 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400271 salt.printSaltCommandResult(out)
272 }
273
274 } catch (Throwable e) {
275 // If there was an error or exception thrown, the build failed
276 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200277 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400278 throw e
279 }
280 }
281
282
283 if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) {
284
285 stage('Ask for manual confirmation') {
286 input message: "Do you want to continue with the Opencontrail control nodes rollback?"
287 }
288
289 stage('Opencontrail controllers rollback') {
290
chnyda625f4b42017-10-11 14:10:31 +0200291 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 +0400292 oc_component_repo = oc_component_repo['return'][0].values()[0]
293
294 try {
chnyda625f4b42017-10-11 14:10:31 +0200295 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
296 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
297 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400298 } catch (Exception er) {
299 errorOccured = true
300 common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
301 return
302 }
303
304 args = 'apt install contrail-database -y --force-yes;'
305 check = 'nodetool status'
306
307 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200308 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400309 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200310 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400311 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200312 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400313
314 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;"
315 check = 'contrail-status'
316
317 // ntw01
chnyda625f4b42017-10-11 14:10:31 +0200318 runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400319 // ntw02
chnyda625f4b42017-10-11 14:10:31 +0200320 runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400321 // ntw03
chnyda625f4b42017-10-11 14:10:31 +0200322 runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400323
324 try {
chnyda625f4b42017-10-11 14:10:31 +0200325 salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400326 } catch (Exception er) {
327 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
328 }
329
chnyda625f4b42017-10-11 14:10:31 +0200330 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400331 salt.printSaltCommandResult(out)
332
333 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
334 }
335 }
336
337 if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) {
338
339 stage('Ask for manual confirmation') {
340 input message: "Do you want to continue with the Opencontrail analytic nodes rollback?"
341 }
342
343 stage('Opencontrail analytics rollback') {
344
chnyda625f4b42017-10-11 14:10:31 +0200345 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 +0400346 oc_component_repo = oc_component_repo['return'][0].values()[0]
347
348 try {
chnyda625f4b42017-10-11 14:10:31 +0200349 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
350 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
351 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400352 } catch (Exception er) {
353 errorOccured = true
354 common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
355 return
356 }
357
358 args = 'apt install contrail-database -y --force-yes;'
359 check = 'nodetool status'
360
361 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200362 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400363 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200364 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400365 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200366 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400367
368 args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;"
369 check = 'contrail-status'
370
371 // nal01
chnyda625f4b42017-10-11 14:10:31 +0200372 runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400373 // nal02
chnyda625f4b42017-10-11 14:10:31 +0200374 runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400375 // nal03
chnyda625f4b42017-10-11 14:10:31 +0200376 runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400377
378 try {
chnyda625f4b42017-10-11 14:10:31 +0200379 salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400380 } catch (Exception er) {
381 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
382 }
383
chnyda625f4b42017-10-11 14:10:31 +0200384 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400385 salt.printSaltCommandResult(out)
386 }
387 }
388
389 if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) {
390
391 try {
392
393 stage('List targeted compute servers') {
chnyda625f4b42017-10-11 14:10:31 +0200394 minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400395
396 if (minions.isEmpty()) {
397 throw new Exception("No minion was targeted")
398 }
399
400 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
401 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
402
403 targetLiveAll = minions.join(' or ')
404 common.infoMsg("Found nodes: ${targetLiveAll}")
405 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
406 }
407
408 stage('Confirm rollback on sample nodes') {
409 input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}"
410 }
411
412 stage("Opencontrail compute rollback on sample nodes") {
413
chnyda625f4b42017-10-11 14:10:31 +0200414 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 +0400415 oc_component_repo = oc_component_repo['return'][0].values()[0]
416
417 try {
chnyda625f4b42017-10-11 14:10:31 +0200418 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
419 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
420 salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400421 } catch (Exception er) {
422 errorOccured = true
423 common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
424 return
425 }
426
427 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
428 check = 'contrail-status'
429
chnyda625f4b42017-10-11 14:10:31 +0200430 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400431 salt.printSaltCommandResult(out)
432
433 try {
chnyda625f4b42017-10-11 14:10:31 +0200434 salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400435 } catch (Exception er) {
436 common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.")
437 }
438
chnyda625f4b42017-10-11 14:10:31 +0200439 salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400440 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200441 salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400442
chnyda625f4b42017-10-11 14:10:31 +0200443 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400444 salt.printSaltCommandResult(out)
445 }
446
447 stage('Confirm rollback on all targeted nodes') {
448 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
449 }
450
451 stage("Opencontrail compute upgrade on all targeted nodes") {
452
chnyda625f4b42017-10-11 14:10:31 +0200453 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 +0400454 oc_component_repo = oc_component_repo['return'][0].values()[0]
455
456 try {
chnyda625f4b42017-10-11 14:10:31 +0200457 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
458 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
459 salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400460 } catch (Exception er) {
461 common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.")
462 return
463 }
464
465 args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;"
466 check = 'contrail-status'
467
chnyda625f4b42017-10-11 14:10:31 +0200468 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400469 salt.printSaltCommandResult(out)
470
471 try {
chnyda625f4b42017-10-11 14:10:31 +0200472 salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400473 } catch (Exception er) {
474 common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.")
475 }
476
chnyda625f4b42017-10-11 14:10:31 +0200477 salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400478
479 //sleep(10)
chnyda625f4b42017-10-11 14:10:31 +0200480 salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400481
chnyda625f4b42017-10-11 14:10:31 +0200482 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400483 salt.printSaltCommandResult(out)
484 }
485
486 } catch (Throwable e) {
487 // If there was an error or exception thrown, the build failed
488 currentBuild.result = "FAILURE"
Jakub Josefd2efd7d2017-08-22 17:49:57 +0200489 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +0400490 throw e
Jiri Broulik641e4102017-07-13 12:26:18 +0200491 }
492 }
493}