blob: f59dd276448e98b1ce81657b10e72e800df83d3b [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.
12 *
13**/
14
15def common = new com.mirantis.mk.Common()
16def salt = new com.mirantis.mk.Salt()
17
18def saltMaster
19def targetTestSubset
20def targetLiveSubset
21def targetLiveAll
22def minions
23def result
24def args
25def command
26def commandKwargs
27def probe = 1
28
29timestamps {
30 node() {
31
32 stage('Connect to Salt API') {
33 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
34 }
35
36 if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) {
37 // # actual upgrade
38
39 stage('Opencontrail controllers upgrade') {
40
41 oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
42
43 //oc_component_repo = salt.cmdRun(saltMaster, 'I@opencontrail:control and *01*', 'grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\'')
44 //print oc_component_repo
45 oc_component_repo = oc_component_repo['return'][0].values()[0]
46 print oc_component_repo
47
48 try {
49 //salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm ${oc_component_repo}")
50 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
51 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true)
52 salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo')
53 } catch (Exception er) {
54 common.errorMsg('Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.')
55 return
56 }
57
58 try {
59 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'")
60 } catch (Exception er) {
61 common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.')
62 return
63 }
64
65 try {
66 salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'")
67 } catch (Exception er) {
68 common.errorMsg('Cassandra failed to backup. Please fix it before continuing.')
69 return
70 }
71
72 // args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
73
74 // database // while sleeping nodetool-status
75 command = 'cmd.shell'
76 args = 'apt install contrail-database -y;'
77 check = 'nodetool status'
78
79 // ntw01
80 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *01*', 'type': 'compound'], command, null, args, null)
81 salt.printSaltCommandResult(out)
82 sleep(30)
83 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *01*', 'type': 'compound'], command, null, check, null)
84 salt.printSaltCommandResult(out)
85 input message: "Please check the output of ${check} and continue if it is correct."
86
87 // ntw02
88 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *02*', 'type': 'compound'], command, null, args, null)
89 salt.printSaltCommandResult(out)
90 sleep(30)
91 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *02*', 'type': 'compound'], command, null, check, null)
92 salt.printSaltCommandResult(out)
93 input message: "Please check the output of ${check} and continue if it is correct."
94
95 // ntw03
96 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *03*', 'type': 'compound'], command, null, args, null)
97 salt.printSaltCommandResult(out)
98 sleep(30)
99 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *03*', 'type': 'compound'], command, null, check, null)
100 salt.printSaltCommandResult(out)
101 input message: "Please check the output of ${check} and continue if it is correct."
102
103
104 // pkgs // while sleeping contrail-status // pridat jeste 20 sekund sleep
105 args = 'apt install -o Dpkg::Options::=\"--force-confold\" 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 -y --force-yes;'
106 check = 'contrail-status'
107
108 // ntw01
109 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *01*', 'type': 'compound'], command, null, args, null)
110 salt.printSaltCommandResult(out)
111 sleep(30)
112 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *01*', 'type': 'compound'], command, null, check, null)
113 salt.printSaltCommandResult(out)
114 input message: "Please check the output of ${check} and continue if it is correct."
115
116 // ntw02
117 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *02*', 'type': 'compound'], command, null, args, null)
118 salt.printSaltCommandResult(out)
119 sleep(30)
120 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *02*', 'type': 'compound'], command, null, check, null)
121 salt.printSaltCommandResult(out)
122 input message: "Please check the output of ${check} and continue if it is correct."
123
124 // ntw03
125 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *03*', 'type': 'compound'], command, null, args, null)
126 salt.printSaltCommandResult(out)
127 sleep(30)
128 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control and *03*', 'type': 'compound'], command, null, check, null)
129 salt.printSaltCommandResult(out)
130 input message: "Please check the output of ${check} and continue if it is correct."
131
132
133 // co se stane kdyz tohle neprojede a ma to fixnout manualne? Pokracovat nebo ne nebo co?
134 try {
135 salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail')
136 } catch (Exception er) {
137 common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.')
138 }
139
140 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null)
141 salt.printSaltCommandResult(out)
142
143 common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.')
144 }
145 }
146
147 if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true) {
148
149 stage('Ask for manual confirmation') {
150 input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?"
151 }
152
153 stage('Opencontrail analytics upgrade') {
154
155 oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
156
157 //oc_component_repo = salt.cmdRun(saltMaster, 'I@opencontrail:collector and *01*', 'grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\'')
158 //print oc_component_repo
159 oc_component_repo = oc_component_repo['return'][0].values()[0]
160 print oc_component_repo
161
162 try {
163 //salt.cmdRun(saltMaster, 'I@opencontrail:collector', "rm ${oc_component_repo}")
164 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
165 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true)
166 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo')
167 } catch (Exception er) {
168 common.errorMsg('Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.')
169 return
170 }
171
172 // args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
173
174 // database // while sleeping nodetool-status
175 command = 'cmd.shell'
176 args = 'apt install contrail-database -y;'
177 check = 'nodetool status'
178
179 // po apt install contrail-database tak 2 min pockat nez pojedu dalsi nod
180 // ntw01
181 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *01*', 'type': 'compound'], command, null, args, null)
182 salt.printSaltCommandResult(out)
183 sleep(30)
184 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *01*', 'type': 'compound'], command, null, check, null)
185 salt.printSaltCommandResult(out)
186 input message: "Please check the output of ${check} and continue if it is correct."
187
188 // ntw02
189 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *02*', 'type': 'compound'], command, null, args, null)
190 salt.printSaltCommandResult(out)
191 sleep(30)
192 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *02*', 'type': 'compound'], command, null, check, null)
193 salt.printSaltCommandResult(out)
194 input message: "Please check the output of ${check} and continue if it is correct."
195
196 // ntw03
197 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *03*', 'type': 'compound'], command, null, args, null)
198 salt.printSaltCommandResult(out)
199 sleep(30)
200 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *03*', 'type': 'compound'], command, null, check, null)
201 salt.printSaltCommandResult(out)
202 input message: "Please check the output of ${check} and continue if it is correct."
203
204
205 // pkgs // while sleeping contrail-status // pridat jeste 20 sekund sleep
206 args = 'apt install -o Dpkg::Options::="--force-confold" contrail-analytics contrail-lib contrail-nodemgr contrail-utils python-contrail -y --force-yes;'
207 check = 'contrail-status'
208
209 // ntw01
210 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *01*', 'type': 'compound'], command, null, args, null)
211 salt.printSaltCommandResult(out)
212 sleep(30)
213 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *01*', 'type': 'compound'], command, null, check, null)
214 salt.printSaltCommandResult(out)
215 input message: "Please check the output of ${check} and continue if it is correct."
216
217 // ntw02
218 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *02*', 'type': 'compound'], command, null, args, null)
219 salt.printSaltCommandResult(out)
220 sleep(30)
221 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *02*', 'type': 'compound'], command, null, check, null)
222 salt.printSaltCommandResult(out)
223 input message: "Please check the output of ${check} and continue if it is correct."
224
225 // ntw03
226 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *03*', 'type': 'compound'], command, null, args, null)
227 salt.printSaltCommandResult(out)
228 sleep(30)
229 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector and *03*', 'type': 'compound'], command, null, check, null)
230 salt.printSaltCommandResult(out)
231 input message: "Please check the output of ${check} and continue if it is correct."
232
233
234 // co se stane kdyz tohle neprojede a ma to fixnout manualne? Pokracovat nebo ne nebo co?
235 try {
236 salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail')
237 } catch (Exception er) {
238 common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.')
239 }
240
241 out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null)
242 salt.printSaltCommandResult(out)
243 }
244
245 }
246
247 if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) {
248
249 try {
250
251 stage('List targeted compute servers') {
252 minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS)
253
254 if (minions.isEmpty()) {
255 throw new Exception("No minion was targeted")
256 }
257
258 targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ')
259 targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
260
261 targetLiveAll = minions.join(' or ')
262 common.infoMsg("Found nodes: ${targetLiveAll}")
263 common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
264 }
265
266 stage('Confirm upgrade on sample nodes') {
267 input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}"
268 }
269
270 stage("Opencontrail compute upgrade on sample nodes") {
271
272 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ['grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
273 oc_component_repo = oc_component_repo['return'][0].values()[0]
274 print oc_component_repo
275
276 try {
277 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
278 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true)
279 salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo')
280 } catch (Exception er) {
281 common.errorMsg('Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.')
282 return
283 }
284
285 // args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
286
287 command = 'cmd.shell'
288 args = 'export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" 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 -y;'
289 check = 'contrail-status'
290
291 // pkgs // while sleeping contrail-status // pridat jeste 20 sekund sleep
292 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null)
293 salt.printSaltCommandResult(out)
294 sleep(30)
295
296 // co se stane kdyz tohle neprojede a ma to fixnout manualne? Pokracovat nebo ne nebo co?
297 try {
298 salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail')
299 } catch (Exception er) {
300 common.errorMsg('Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.')
301 }
302
303 salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;"], null, true)
304 sleep(30)
305
306 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null)
307 salt.printSaltCommandResult(out)
308 }
309
310 stage('Confirm upgrade on all targeted nodes') {
311 timeout(time: 2, unit: 'HOURS') {
312 input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?"
313 }
314 }
315 stage("Opencontrail compute upgrade on all targeted nodes") {
316
317 oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ['grep -R \'oc\\([0-9]*\\)\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true)
318 oc_component_repo = oc_component_repo['return'][0].values()[0]
319 print oc_component_repo
320
321 try {
322 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true)
323 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true)
324 salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo')
325 } catch (Exception er) {
326 common.errorMsg('Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.')
327 return
328 }
329
330 // args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
331
332 command = 'cmd.shell'
333 args = 'export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" 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 -y;'
334 check = 'contrail-status'
335
336 // pkgs // while sleeping contrail-status // pridat jeste 20 sekund sleep
337 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null)
338 salt.printSaltCommandResult(out)
339 sleep(30)
340
341 // co se stane kdyz tohle neprojede a ma to fixnout manualne? Pokracovat nebo ne nebo co?
342 try {
343 salt.enforceState(saltMaster, targetLiveAll, 'opencontrail')
344 } catch (Exception er) {
345 common.errorMsg('Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.')
346 }
347
348 sleep(3)
349 salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;"], null, true)
350 sleep(30)
351
352 out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null)
353 salt.printSaltCommandResult(out)
354 }
355
356 } catch (Throwable e) {
357 // If there was an error or exception thrown, the build failed
358 currentBuild.result = "FAILURE"
359 throw e
360 }
361 }
362 }
363}