blob: 8d0eb554702277cfb097173dfb15e231045da64a [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
Jakub Pavlik77fe1542017-06-12 13:02:52 +020015def minions
16def result
17def command
18def commandKwargs
19
20
21node() {
22 try {
23
24 stage('Connect to Salt master') {
25 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
26 }
27
28 stage('List target servers') {
Tomáš Kukrálc86c8b42017-07-13 10:26:51 +020029 minions = salt.getMinions(saltMaster, TARGET_SERVERS)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020030
31 if (minions.isEmpty()) {
32 throw new Exception("No minion was targeted")
33 }
34
35 targetLiveAll = minions.join(' or ')
36 common.infoMsg("Found nodes: ${targetLiveAll}")
37 common.infoMsg("Selected nodes: ${targetLiveAll}")
38 }
39
40 stage("Setup network for compute") {
41 common.infoMsg("Now all network configuration will be enforced, which caused reboot of nodes: ${targetLiveAll}")
42 try {
Jakub Pavlike7a399a2017-06-12 21:45:44 +020043 salt.cmdRun(saltMaster, targetLiveAll, 'salt-call state.sls linux.system.user,openssh,linux.network;reboot')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020044 } catch(e) {
45 common.infoMsg("no respond from nodes due reboot")
46 }
47 common.infoMsg("Now pipeline is waiting until node reconnect to salt master")
48 timeout(800) {
49 retry(666) {
50 try {
Jakub Pavlikd7fb22d2017-06-12 22:44:19 +020051 salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'test.ping')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020052 } catch(e) {
53 common.infoMsg("Still waiting for node to come up")
54 sleep(10)
55 }
56 }
57 }
58 }
59
60 stage("Deploy Compute") {
61 common.infoMsg("Lets run rest of the states to finish deployment")
Jakub Pavlike7a399a2017-06-12 21:45:44 +020062 salt.enforceState(saltMaster, targetLiveAll, 'linux,openssh,ntp,salt', true)
Jakub Pavlik77fe1542017-06-12 13:02:52 +020063 retry(2) {
Jakub Pavlikd7fb22d2017-06-12 22:44:19 +020064 salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], 'state.apply')
Jakub Pavlik77fe1542017-06-12 13:02:52 +020065 }
66 }
67
68 } catch (Throwable e) {
69 // If there was an error or exception thrown, the build failed
70 currentBuild.result = "FAILURE"
71 throw e
72 }
73}