Add function for checking minions readiness for new commands
Function will check availability of target minions (optionally) and then
readiness of all minions.
Change-Id: I086dd979cbb32a4a796e85bfca6d668a2578c9df
Related-Prod: PROD-26381 (PROD:26381)
(cherry picked from commit a1edabaca734af23b6673ea59636f59f4be911b9)
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index d126964..df64286 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -484,6 +484,39 @@
}
/**
+ * You can call this function when need to check that all minions are available, free and ready for command execution
+ * @param config LinkedHashMap config parameter, which contains next:
+ * @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
+ * @param target unique identification of a minion or group of salt minions
+ * @param target_reachable unique identification of a minion or group of salt minions to check availability
+ * @param wait timeout between retries to check target minions (default 5)
+ * @param retries finite number of iterations to check minions (default 10)
+ * @param timeout timeout for the salt command if minions do not return (default 5)
+ * @param availability check that minions also are available before checking readiness (default true)
+ */
+def checkTargetMinionsReady(LinkedHashMap config) {
+ def common = new com.mirantis.mk.Common()
+ def saltId = config.get('saltId')
+ def target = config.get('target')
+ def target_reachable = config.get('target_reachable', target)
+ def wait = config.get('wait', 30)
+ def retries = config.get('retries', 10)
+ def timeout = config.get('timeout', 5)
+ def checkAvailability = config.get('availability', true)
+ common.retry(retries, wait) {
+ if (checkAvailability) {
+ minionsReachable(saltId, 'I@salt:master', target_reachable)
+ }
+ def running = runSaltProcessStep(saltId, target, 'saltutil.running', [], null, true, timeout)
+ for (value in running.get("return")[0].values()) {
+ if (value != []) {
+ throw new Exception("Not all salt-minions are ready for execution")
+ }
+ }
+ }
+}
+
+/**
* Run command on salt minion (salt cmd.run wrapper)
* @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
* @param target Get pillar target