blob: 35cc99f97bc32ad85c8747400fbe8fc6dc1f1a6f [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()
chnyda625f4b42017-10-11 14:10:31 +020018def python = new com.mirantis.mk.Python()
Ales Komarek374cc382017-03-16 08:49:01 +010019
chnyda625f4b42017-10-11 14:10:31 +020020def pepperEnv = "pepperEnv"
Ales Komarek374cc382017-03-16 08:49:01 +010021def targetTestSubset
22def targetLiveSubset
23def targetLiveAll
24def minions
25def result
26def states
Jakub Josefa63f9862018-01-11 17:58:38 +010027timeout(time: 12, unit: 'HOURS') {
28 node() {
29 try {
Ales Komarek374cc382017-03-16 08:49:01 +010030
Jakub Josefa63f9862018-01-11 17:58:38 +010031 if (TARGET_STATES != "") {
32 states = TARGET_STATES
Ales Komarek374cc382017-03-16 08:49:01 +010033 }
34 else {
Jakub Josefa63f9862018-01-11 17:58:38 +010035 states = null
Ales Komarek374cc382017-03-16 08:49:01 +010036 }
Ales Komarek374cc382017-03-16 08:49:01 +010037
Jakub Josefa63f9862018-01-11 17:58:38 +010038 stage('Setup virtualenv for Pepper') {
39 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ales Komarek374cc382017-03-16 08:49:01 +010040 }
Ales Komarek374cc382017-03-16 08:49:01 +010041
Jakub Josefa63f9862018-01-11 17:58:38 +010042 if (common.validInputParam("PULL_MODEL") && PULL_MODEL.toBoolean() == true) {
43 stage('Update the reclass cluster model') {
44 def saltMasterTarget = ['expression': 'I@salt:master', 'type': 'compound']
45 result = salt.runSaltCommand(pepperEnv, 'local', saltMasterTarget, 'state.apply', null, "reclass.storage.data")
46 salt.checkResult(result)
47 }
Ales Komarek374cc382017-03-16 08:49:01 +010048 }
Ales Komarek374cc382017-03-16 08:49:01 +010049
Jakub Josefa63f9862018-01-11 17:58:38 +010050 stage('List target servers') {
51 minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
52 if (minions.isEmpty()) {
53 throw new Exception("No minion was targeted")
54 }
55 if (TARGET_SUBSET_TEST != "") {
56 targetTestSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or '), 'type': 'compound']
57 }
58 else {
59 targetTestSubset = ['expression': minions.join(' or '), 'type': 'compound']
60 }
61 targetLiveSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or '), 'type': 'compound']
62 targetLiveAll = ['expression': minions.join(' or '), 'type': 'compound']
63 common.infoMsg("Found nodes: ${targetLiveAll.expression}")
64 common.infoMsg("Selected test nodes: ${targetTestSubset.expression}")
65 common.infoMsg("Selected sample nodes: ${targetLiveSubset.expression}")
66 }
Ales Komarek374cc382017-03-16 08:49:01 +010067
Jakub Josefa63f9862018-01-11 17:58:38 +010068 stage('Test config changes') {
69 def kwargs = [
70 'test': true
71 ]
72 result = salt.runSaltCommand(pepperEnv, 'local', targetTestSubset, 'state.apply', null, states, kwargs)
73 salt.checkResult(result)
74 }
75
76 stage('Confirm live changes on sample') {
77 timeout(time: 2, unit: 'HOURS') {
78 input message: "Approve live config change on ${targetLiveSubset.expression} nodes?"
79 }
80 }
81
82 stage('Apply config changes on sample') {
83 result = salt.runSaltCommand(pepperEnv, 'local', targetLiveSubset, 'state.apply', null, states)
84 salt.checkResult(result)
85 }
86
87 stage('Confirm live changes on all nodes') {
88 timeout(time: 2, unit: 'HOURS') {
89 input message: "Approve live config change on ${targetLiveAll.expression} nodes?"
90 }
91 }
92
93 stage('Apply config changes on all nodes') {
94 result = salt.runSaltCommand(pepperEnv, 'local', targetLiveAll, 'state.apply', null, states)
95 salt.checkResult(result)
96 }
97
98 } catch (Throwable e) {
99 currentBuild.result = 'FAILURE'
100 throw e
101 }
Ales Komarek374cc382017-03-16 08:49:01 +0100102 }
103}