Merge "Revert "Remove hardcode for tempest version" Change workflow for cvp-job Oleksii Zhurba, Denis Meltsaykin and I desided that all custom settings in cvp jobs should be taked out from jenkins parameters. These custom values (e.g. version of tempest) will be indicated in bash script from 'cvp-configuration' repository"
diff --git a/src/com/mirantis/mk/Common.groovy b/src/com/mirantis/mk/Common.groovy
index 9a82fbe..7ad1834 100644
--- a/src/com/mirantis/mk/Common.groovy
+++ b/src/com/mirantis/mk/Common.groovy
@@ -539,3 +539,14 @@
}
return userInput
}
+
+/**
+ * Function receives Map variable as input and sorts it
+ * by values ascending. Returns sorted Map
+ * @param _map Map variable
+ */
+@NonCPS
+def SortMapByValueAsc(_map) {
+ def sortedMap = _map.sort {it.value}
+ return sortedMap
+}
diff --git a/src/com/mirantis/mk/Openstack.groovy b/src/com/mirantis/mk/Openstack.groovy
index eedfbd8..f4a42ae 100644
--- a/src/com/mirantis/mk/Openstack.groovy
+++ b/src/com/mirantis/mk/Openstack.groovy
@@ -380,6 +380,40 @@
}
/**
+ * Delete nova key pair
+ *
+ * @param env Connection parameters for OpenStack API endpoint
+ * @param name Name of the key pair to delete
+ * @param path Optional path to the custom virtualenv
+ */
+def deleteKeyPair(env, name, path = null) {
+ def common = new com.mirantis.mk.Common()
+ common.infoMsg("Removing key pair ${name}")
+ def cmd = "openstack keypair delete ${name}"
+ runOpenstackCommand(cmd, env, path)
+}
+
+/**
+ * Get nova key pair
+ *
+ * @param env Connection parameters for OpenStack API endpoint
+ * @param name Name of the key pair to show
+ * @param path Optional path to the custom virtualenv
+ */
+
+def getKeyPair(env, name, path = null) {
+ def common = new com.mirantis.mk.Common()
+ def cmd = "openstack keypair show ${name}"
+ def outputTable
+ try {
+ outputTable = runOpenstackCommand(cmd, env, path)
+ } catch (Exception e) {
+ common.infoMsg("Key pair ${name} not found")
+ }
+ return outputTable
+}
+
+/**
* Stops all services that contain specific string (for example nova,heat, etc.)
* @param env Salt Connection object or pepperEnv
* @param probe single node on which to list service names
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
index 7e3a813..abe4b5d 100644
--- a/src/com/mirantis/mk/Orchestrate.groovy
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -700,7 +700,9 @@
salt.runSaltProcessStep(master, "I@docker:swarm ${extra_tgt}", 'saltutil.refresh_modules')
sleep(5)
salt.enforceState(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker.swarm')
- salt.enforceState(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
+ if (salt.testTarget(master, "I@docker:swarm:role:manager ${extra_tgt}")){
+ salt.enforceState(master, "I@docker:swarm:role:manager ${extra_tgt}", 'docker.swarm')
+ }
sleep(10)
salt.cmdRun(master, "I@docker:swarm:role:master ${extra_tgt}", 'docker node ls')
}
@@ -1272,3 +1274,31 @@
}
salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
}
+
+/**
+ * Function receives connection string, target and configuration yaml pattern
+ * and retrieves config fom salt minion according to pattern. After that it
+ * sorts applications according to priorities and runs orchestration states
+ * @param master Salt Connection object or pepperEnv
+ * @param tgt Target
+ * @param conf Configuration pattern
+ */
+def OrchestrateApplications(master, tgt, conf) {
+ def salt = new com.mirantis.mk.Salt()
+ def common = new com.mirantis.mk.Common()
+ def _orch = salt.getConfig(master, tgt, conf)
+ if ( !_orch['return'][0].values()[0].isEmpty() ) {
+ Map<String,Integer> _orch_app = [:]
+ for (k in _orch['return'][0].values()[0].keySet()) {
+ _orch_app[k] = _orch['return'][0].values()[0][k].values()[0].toInteger()
+ }
+ def _orch_app_sorted = common.SortMapByValueAsc(_orch_app)
+ common.infoMsg("Applications will be deployed in following order:"+_orch_app_sorted.keySet())
+ for (app in _orch_app_sorted.keySet()) {
+ salt.orchestrateSystem(master, ['expression': tgt, 'type': 'compound'], "${app}.orchestrate.deploy")
+ }
+ }
+ else {
+ common.infoMsg("No applications found for orchestration")
+ }
+}
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 88146fa..6530062 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -132,6 +132,16 @@
}
}
+/**
+ * Return config items for given saltId and target
+ * @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
+ * @param target Get grain target
+ * @param config grain name (optional)
+ * @return output of salt command
+ */
+def getConfig(saltId, target, config) {
+ return runSaltCommand(saltId, 'local', ['expression': target, 'type': 'compound'], 'config.get', null, [config.replace('.', ':')], '--out=json')
+}
/**
* Enforces state on given saltId and target
@@ -671,6 +681,9 @@
* @return output of salt command
*/
def orchestrateSystem(saltId, target, orchestrate=[], kwargs = null) {
+ //Since the runSaltCommand uses "arg" (singular) for "runner" client this won`t work correctly on old salt 2016
+ //cause this version of salt used "args" (plural) for "runner" client, see following link for reference:
+ //https://github.com/saltstack/salt/pull/32938
return runSaltCommand(saltId, 'runner', target, 'state.orchestrate', true, orchestrate, kwargs, 7200, 7200)
}