Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 1 | /** |
| 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 Stoelinga | 893393d | 2017-09-14 09:21:30 -0700 | [diff] [blame] | 12 | * PULL_MODEL Pull the latest cluster model using reclass.storage.data state |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 13 | * |
| 14 | **/ |
| 15 | |
| 16 | def common = new com.mirantis.mk.Common() |
| 17 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 18 | def python = new com.mirantis.mk.Python() |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 19 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 20 | def pepperEnv = "pepperEnv" |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 21 | def targetTestSubset |
| 22 | def targetLiveSubset |
| 23 | def targetLiveAll |
| 24 | def minions |
| 25 | def result |
| 26 | def states |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | try { |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 30 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 31 | if (TARGET_STATES != "") { |
| 32 | states = TARGET_STATES |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 33 | } |
| 34 | else { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 35 | states = null |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 36 | } |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 37 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 38 | stage('Setup virtualenv for Pepper') { |
| 39 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 40 | } |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 41 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 42 | 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 Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 48 | } |
Ales Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 49 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 50 | 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 Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 67 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 68 | 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 Komarek | 374cc38 | 2017-03-16 08:49:01 +0100 | [diff] [blame] | 102 | } |
| 103 | } |