blob: d6b08c3a0c0945e7ead50db1a509f54b1e9dea0e [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 {
Jakub Pavlike7a399a2017-06-12 21:45:44 +020044 salt.cmdRun(saltMaster, targetLiveAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020045 } 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 {
Jakub Pavlikd7fb22d2017-06-12 22:44:19 +020052 salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'test.ping')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020053 } 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")
Jakub Pavlike7a399a2017-06-12 21:45:44 +020063 salt.enforceState(saltMaster, targetLiveAll, 'linux,openssh,ntp,salt', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020064 retry(2) {
Jakub Pavlikd7fb22d2017-06-12 22:44:19 +020065 salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'state.apply')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020066 }
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}