blob: 16cd629f1db7fdc4c8e2606ccab6447f6071a8d7 [file] [log] [blame]
Ales Komarek374cc382017-03-16 08:49:01 +01001/**
2 * Make change to the node(s) configuration
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 * TARGET_STATES States to be applied, empty string means running highstate [linux, linux,openssh, salt.minion.grains].
9 * TARGET_SUBSET_TEST Number of nodes to test config changes, empty string means all targetted nodes.
10 * TARGET_SUBSET_LIVE Number of selected noded to live apply selected config changes.
11 * TARGET_BATCH_LIVE Batch size for the complete live config changes on all nodes, empty string means apply to all targetted nodes.
Sam Stoelinga893393d2017-09-14 09:21:30 -070012 * PULL_MODEL Pull the latest cluster model using reclass.storage.data state
Ales Komarek374cc382017-03-16 08:49:01 +010013 *
14**/
15
16def common = new com.mirantis.mk.Common()
17def salt = new com.mirantis.mk.Salt()
18
19def saltMaster
Ales Komarek374cc382017-03-16 08:49:01 +010020def targetTestSubset
21def targetLiveSubset
22def targetLiveAll
23def minions
24def result
25def states
26
27node() {
28 try {
29
30 if (TARGET_STATES != "") {
31 states = TARGET_STATES
32 }
33 else {
34 states = null
35 }
36
37 stage('Connect to Salt master') {
38 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
39 }
40
Sam Stoelinga893393d2017-09-14 09:21:30 -070041 if (common.validInputParam("PULL_MODEL") && PULL_MODEL.toBoolean() == true) {
42 stage('Update the reclass cluster model') {
43 def saltMasterTarget = ['expression': 'I@salt:master', 'type': 'compound']
44 result = salt.runSaltCommand(saltMaster, 'local', saltMasterTarget, 'state.apply', null, "reclass.storage.data")
45 salt.checkResult(result)
46 }
47 }
48
Ales Komarek374cc382017-03-16 08:49:01 +010049 stage('List target servers') {
Tomáš Kukrálc86c8b42017-07-13 10:26:51 +020050 minions = salt.getMinions(saltMaster, TARGET_SERVERS)
Jakub Josefcd15ce72017-04-25 18:55:23 +020051 if (minions.isEmpty()) {
52 throw new Exception("No minion was targeted")
53 }
Ales Komarek374cc382017-03-16 08:49:01 +010054 if (TARGET_SUBSET_TEST != "") {
55 targetTestSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or '), 'type': 'compound']
56 }
57 else {
58 targetTestSubset = ['expression': minions.join(' or '), 'type': 'compound']
59 }
60 targetLiveSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or '), 'type': 'compound']
61 targetLiveAll = ['expression': minions.join(' or '), 'type': 'compound']
62 common.infoMsg("Found nodes: ${targetLiveAll.expression}")
63 common.infoMsg("Selected test nodes: ${targetTestSubset.expression}")
64 common.infoMsg("Selected sample nodes: ${targetLiveSubset.expression}")
65 }
66
67 stage('Test config changes') {
68 def kwargs = [
69 'test': true
70 ]
71 result = salt.runSaltCommand(saltMaster, 'local', targetTestSubset, 'state.apply', null, states, kwargs)
Jakub Josefcd15ce72017-04-25 18:55:23 +020072 salt.checkResult(result)
Ales Komarek374cc382017-03-16 08:49:01 +010073 }
74
75 stage('Confirm live changes on sample') {
76 timeout(time: 2, unit: 'HOURS') {
77 input message: "Approve live config change on ${targetLiveSubset.expression} nodes?"
78 }
79 }
80
81 stage('Apply config changes on sample') {
82 result = salt.runSaltCommand(saltMaster, 'local', targetLiveSubset, 'state.apply', null, states)
Jakub Josefcd15ce72017-04-25 18:55:23 +020083 salt.checkResult(result)
Ales Komarek374cc382017-03-16 08:49:01 +010084 }
85
86 stage('Confirm live changes on all nodes') {
87 timeout(time: 2, unit: 'HOURS') {
88 input message: "Approve live config change on ${targetLiveAll.expression} nodes?"
89 }
90 }
91
92 stage('Apply config changes on all nodes') {
93 result = salt.runSaltCommand(saltMaster, 'local', targetLiveAll, 'state.apply', null, states)
Jakub Josefcd15ce72017-04-25 18:55:23 +020094 salt.checkResult(result)
Ales Komarek374cc382017-03-16 08:49:01 +010095 }
96
97 } catch (Throwable e) {
98 currentBuild.result = 'FAILURE'
99 throw e
Ales Komarek374cc382017-03-16 08:49:01 +0100100 }
101}