Update-packages and change-configs pipelines
Change-Id: Icc976aef5acad7276f744dd298062f330cc5a945
diff --git a/change-config.groovy b/change-config.groovy
new file mode 100644
index 0000000..69f7519
--- /dev/null
+++ b/change-config.groovy
@@ -0,0 +1,93 @@
+/**
+ * Make change to the node(s) configuration
+ *
+ * Expected parameters:
+ * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
+ * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000].
+ * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian].
+ * TARGET_STATES States to be applied, empty string means running highstate [linux, linux,openssh, salt.minion.grains].
+ * TARGET_SUBSET_TEST Number of nodes to test config changes, empty string means all targetted nodes.
+ * TARGET_SUBSET_LIVE Number of selected noded to live apply selected config changes.
+ * TARGET_BATCH_LIVE Batch size for the complete live config changes on all nodes, empty string means apply to all targetted nodes.
+ *
+**/
+
+def common = new com.mirantis.mk.Common()
+def salt = new com.mirantis.mk.Salt()
+
+def saltMaster
+def targetAll = ['expression': TARGET_SERVERS, 'type': 'compound']
+def targetTestSubset
+def targetLiveSubset
+def targetLiveAll
+def minions
+def result
+def states
+
+node() {
+ try {
+
+ if (TARGET_STATES != "") {
+ states = TARGET_STATES
+ }
+ else {
+ states = null
+ }
+
+ stage('Connect to Salt master') {
+ saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+ }
+
+ stage('List target servers') {
+ minions = salt.getMinions(saltMaster, targetAll)
+ if (TARGET_SUBSET_TEST != "") {
+ targetTestSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or '), 'type': 'compound']
+ }
+ else {
+ targetTestSubset = ['expression': minions.join(' or '), 'type': 'compound']
+ }
+ targetLiveSubset = ['expression': minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or '), 'type': 'compound']
+ targetLiveAll = ['expression': minions.join(' or '), 'type': 'compound']
+ common.infoMsg("Found nodes: ${targetLiveAll.expression}")
+ common.infoMsg("Selected test nodes: ${targetTestSubset.expression}")
+ common.infoMsg("Selected sample nodes: ${targetLiveSubset.expression}")
+ }
+
+ stage('Test config changes') {
+ def kwargs = [
+ 'test': true
+ ]
+ result = salt.runSaltCommand(saltMaster, 'local', targetTestSubset, 'state.apply', null, states, kwargs)
+ salt.printSaltStateResult(result)
+ }
+
+ stage('Confirm live changes on sample') {
+ timeout(time: 2, unit: 'HOURS') {
+ input message: "Approve live config change on ${targetLiveSubset.expression} nodes?"
+ }
+ }
+
+ stage('Apply config changes on sample') {
+ result = salt.runSaltCommand(saltMaster, 'local', targetLiveSubset, 'state.apply', null, states)
+ salt.printSaltStateResult(result)
+ }
+
+ stage('Confirm live changes on all nodes') {
+ timeout(time: 2, unit: 'HOURS') {
+ input message: "Approve live config change on ${targetLiveAll.expression} nodes?"
+ }
+ }
+
+ stage('Apply config changes on all nodes') {
+ result = salt.runSaltCommand(saltMaster, 'local', targetLiveAll, 'state.apply', null, states)
+ salt.printSaltStateResult(result)
+ }
+
+ } catch (Throwable e) {
+ currentBuild.result = 'FAILURE'
+ throw e
+ } finally {
+ // send notification
+ //common.sendNotification(currentBuild.result,HEAT_STACK_NAME,["slack"])
+ }
+}