Support queue=true/false for salt states
While enforcing state "reclass" we allow to fail, but in many cases "timeout" is short
and state still running and running another state without queue=true causes the 2nd state to fail.
Change-Id: I92a1219b66ca0084f46e430ab334ede39d36241b
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
index c554fc6..5efc6d3 100644
--- a/src/com/mirantis/mk/Orchestrate.groovy
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -17,7 +17,7 @@
def installFoundationInfra(master) {
def salt = new com.mirantis.mk.Salt()
- salt.enforceState(master, 'I@salt:master', ['salt.master', 'reclass'], true, false, null, false, 60, 2)
+ salt.enforceState(master, 'I@salt:master', ['salt.master', 'reclass'], true, false, null, false, 120, 2)
salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 853965e..248f8eb 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -175,11 +175,12 @@
* @param output print output (optional, default true)
* @param failOnError throw exception on salt state result:false (optional, default true)
* @param batch salt batch parameter integer or string with percents (optional, default null - disable batch)
- * @param read_timeout http session read timeout
- * @param retries Retry count for salt state.
+ * @param read_timeout http session read timeout (optional, default -1 - disabled)
+ * @param retries Retry count for salt state. (optional, default -1 - no retries)
+ * @param queue salt queue parameter for state.sls calls (optional, default true) - CANNOT BE USED WITH BATCH
* @return output of salt command
*/
-def enforceState(master, target, state, output = true, failOnError = true, batch = null, optional = false, read_timeout=-1, retries=-1) {
+def enforceState(master, target, state, output = true, failOnError = true, batch = null, optional = false, read_timeout=-1, retries=-1, queue=true) {
def common = new com.mirantis.mk.Common()
def run_states
@@ -191,15 +192,19 @@
common.infoMsg("Running state ${run_states} on ${target}")
def out
+ def kwargs = [:]
+
+ if (queue && batch == null) {
+ kwargs["queue"] = true
+ }
if (optional == false || testTarget(master, target)){
if (retries != -1){
retry(retries){
- out = runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], null, -1, read_timeout)
+ out = runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], kwargs, -1, read_timeout)
}
- }
- else {
- out = runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], null, -1, read_timeout)
+ } else {
+ out = runSaltCommand(master, 'local', ['expression': target, 'type': 'compound'], 'state.sls', batch, [run_states], kwargs, -1, read_timeout)
}
checkResult(out, failOnError, output)
return out