blob: 91c0f792add7d1a06837c9e44723c9b07f37c546 [file] [log] [blame]
Jakub Pavlik77fe1542017-06-12 13:02:52 +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 [https://10.10.10.1:8000].
7 * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
8 *
9**/
10
11def common = new com.mirantis.mk.Common()
12def salt = new com.mirantis.mk.Salt()
13
14def saltMaster
15def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
16def minions
17def result
18def command
19def commandKwargs
20
21
22node() {
23 try {
24
25 stage('Connect to Salt master') {
26 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
27 }
28
29 stage('List target servers') {
30 minions = salt.getMinions(saltMaster, targetAll)
31
32 if (minions.isEmpty()) {
33 throw new Exception("No minion was targeted")
34 }
35
36 targetLiveAll = minions.join(' or ')
37 common.infoMsg("Found nodes: ${targetLiveAll}")
38 common.infoMsg("Selected nodes: ${targetLiveAll}")
39 }
40
41 stage("Setup network for compute") {
42 common.infoMsg("Now all network configuration will be enforced, which caused reboot of nodes: ${targetLiveAll}")
43 try {
44 salt.cmdRun(saltMaster, targetAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot')
45 } catch(e) {
46 common.infoMsg("no respond from nodes due reboot")
47 }
48 common.infoMsg("Now pipeline is waiting until node reconnect to salt master")
49 timeout(800) {
50 retry(666) {
51 try {
52 salt.runSaltCommand(saltMaster, 'local', targetAll, 'test.ping', null, null, kwargs)
53 } catch(e) {
54 common.infoMsg("Still waiting for node to come up")
55 sleep(10)
56 }
57 }
58 }
59 }
60
61 stage("Deploy Compute") {
62 common.infoMsg("Lets run rest of the states to finish deployment")
63 salt.enforceState(saltMaster, targetAll, 'linux,openssh,ntp,salt', true)
64 retry(2) {
65 salt.runSaltCommand(saltMaster, 'local', targetAll, 'state.apply', null, null, kwargs)
66 }
67 }
68
69 } catch (Throwable e) {
70 // If there was an error or exception thrown, the build failed
71 currentBuild.result = "FAILURE"
72 throw e
73 }
74}