[CVP,Q4] Backport runContainer method for new cvp-func job
Related-PROD: PROD-29562
Related to http://gerrit.mcp.mirantis.com/37958/
Change-Id: I9530ef8704edb44d5b9c9547ab58f1dd09dfc958
diff --git a/src/com/mirantis/mcp/Validate.groovy b/src/com/mirantis/mcp/Validate.groovy
index b95b3ae..44c633e 100644
--- a/src/com/mirantis/mcp/Validate.groovy
+++ b/src/com/mirantis/mcp/Validate.groovy
@@ -33,34 +33,55 @@
/**
* Run docker container with parameters
*
- * @param target Host to run container
- * @param dockerImageLink Docker image link. May be custom or default rally image
- * @param name Name for container
- * @param env_var Environment variables to set in container
- * @param entrypoint Set entrypoint to /bin/bash or leave default
+ * @param target Host to run container
+ * @param dockerImageLink Docker image link. May be custom or default rally image
+ * @param name Name for container
+ * @param env_var Environment variables to set in container
+ * @param entrypoint Set entrypoint to /bin/bash or leave default
+ * @param mounts Map with mounts for container
**/
-
-def runContainer(master, target, dockerImageLink, name='cvp', env_var=[], entrypoint=true){
- def salt = new com.mirantis.mk.Salt()
+def runContainer(Map params){
def common = new com.mirantis.mk.Common()
+ defaults = ["name": "cvp", "env_var": [], "entrypoint": true]
+ params = defaults + params
+ def salt = new com.mirantis.mk.Salt()
def variables = ''
def entry_point = ''
- def cluster_name = salt.getPillar(master, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
- if ( salt.cmdRun(master, target, "docker ps -f name=${name} -q", false, null, false)['return'][0].values()[0] ) {
- salt.cmdRun(master, target, "docker rm -f ${name}")
+ def tempest_conf_mount = ''
+ def mounts = ''
+ def cluster_name = salt.getPillar(params.master, 'I@salt:master', '_param:cluster_name')['return'][0].values()[0]
+ default_mounts = ["/etc/ssl/certs/": "/etc/ssl/certs/",
+ "/srv/salt/pki/${cluster_name}/": "/etc/certs",
+ "/root/test/": "/root/tempest/",
+ "/tmp/": "/tmp/",
+ "/etc/hosts": "/etc/hosts"]
+ params.mounts = default_mounts + params.mounts
+ if ( salt.cmdRun(params.master, params.target, "docker ps -f name=${params.name} -q", false, null, false)['return'][0].values()[0] ) {
+ salt.cmdRun(params.master, params.target, "docker rm -f ${params.name}")
}
- if (env_var.size() > 0) {
- variables = ' -e ' + env_var.join(' -e ')
+ if (params.env_var.size() > 0) {
+ variables = ' -e ' + params.env_var.join(' -e ')
}
- if (entrypoint) {
+ if (params.entrypoint) {
entry_point = '--entrypoint /bin/bash'
}
- salt.cmdRun(master, target, "docker run -tid --net=host --name=${name} " +
- "-u root ${entry_point} ${variables} " +
- "-v /srv/salt/pki/${cluster_name}/:/etc/certs ${dockerImageLink}")
+ params.mounts.each { local, container ->
+ mounts = mounts + " -v ${local}:${container}"
+ }
+ salt.cmdRun(params.master, params.target, "docker run -tid --net=host --name=${params.name}" +
+ "${mounts} -u root ${entry_point} ${variables} ${params.dockerImageLink}")
}
+def runContainer(master, target, dockerImageLink, name='cvp', env_var=[], entrypoint=true, mounts=[:]){
+ def common = new com.mirantis.mk.Common()
+ common.infoMsg("This method will be deprecated. Convert you method call to use Map as input parameter")
+ // Convert to Map
+ params = ['master': master, 'target': target, 'dockerImageLink': dockerImageLink, 'name': name, 'env_var': env_var,
+ 'entrypoint': entrypoint, 'mounts': mounts]
+ // Call new method with Map as parameter
+ return runContainer(params)
+}
/**
* Get v2 Keystone credentials from pillars