Merge "WA for stuck tests in docker images"
diff --git a/src/com/mirantis/mcp/MCPArtifactory.groovy b/src/com/mirantis/mcp/MCPArtifactory.groovy
index b272e25..0101eb8 100644
--- a/src/com/mirantis/mcp/MCPArtifactory.groovy
+++ b/src/com/mirantis/mcp/MCPArtifactory.groovy
@@ -47,13 +47,13 @@
     def properties_str = ''
     for (int i = 0; i < properties.size(); i++) {
         // avoid serialization errors
-        key = properties.entrySet().toArray()[i].key
-        value = properties.entrySet().toArray()[i].value
-        properties_str += "${key}=${value}&"
+        key = properties.entrySet().toArray()[i].key.trim()
+        value = properties.entrySet().toArray()[i].value.trim()
+        properties_str += /${key}=${value}&/
     }
     def search_url = "${artifactoryURL}/api/search/prop?${properties_str}"
 
-    def result = sh(script: "bash -c \"curl -X GET \'${search_url}\'\"",
+    def result = sh(script: /curl -X GET '${search_url}'/,
             returnStdout: true).trim()
     def content = new groovy.json.JsonSlurperClassic().parseText(result)
     def uri = content.get("results")
@@ -280,7 +280,7 @@
              passwordVariable: 'ARTIFACTORY_PASSWORD',
              usernameVariable: 'ARTIFACTORY_LOGIN']
     ]) {
-        sh "bash -c \"curl  -u ${ARTIFACTORY_LOGIN}:${ARTIFACTORY_PASSWORD} -H \"Content-Type:application/json\" -X POST -d @${queryFile} ${url}\""
+        sh "bash -c \"curl --fail -u ${ARTIFACTORY_LOGIN}:${ARTIFACTORY_PASSWORD} -H \"Content-Type:application/json\" -X POST -d @${queryFile} ${url}\""
     }
     sh "rm -v ${queryFile}"
 }
diff --git a/src/com/mirantis/mcp/Validate.groovy b/src/com/mirantis/mcp/Validate.groovy
index 02030e0..d1188de 100644
--- a/src/com/mirantis/mcp/Validate.groovy
+++ b/src/com/mirantis/mcp/Validate.groovy
@@ -469,15 +469,21 @@
                        conf_script_path="", ext_variables = []) {
     def salt = new com.mirantis.mk.Salt()
     if (testing_tools_repo != "" ) {
-        salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo} cvp-configuration")
-        configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh"
-    } else {
-        configure_script = conf_script_path != "" ? conf_script_path : "/opt/devops-qa-tools/deployment/configure.sh"
+        if (testing_tools_repo.contains('http://') || testing_tools_repo.contains('https://')) {
+            salt.cmdRun(master, target, "docker exec cvp git clone ${testing_tools_repo} cvp-configuration")
+            configure_script = conf_script_path != "" ? conf_script_path : "cvp-configuration/configure.sh"
+        }
+        else {
+            configure_script = testing_tools_repo
+        }
+        ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
+                             "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
+                             "tempest_version=${tempest_version}")
+        salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " cvp bash -c ${configure_script}")
     }
-    ext_variables.addAll("PROXY=${proxy}", "TEMPEST_REPO=${tempest_repo}",
-                         "TEMPEST_ENDPOINT_TYPE=${tempest_endpoint_type}",
-                         "tempest_version=${tempest_version}")
-    salt.cmdRun(master, target, "docker exec -e " + ext_variables.join(' -e ') + " cvp bash -c ${configure_script}")
+    else {
+        common.infoMsg("TOOLS_REPO is empty, no confguration is needed for container")
+    }
 }
 
 /**
@@ -669,10 +675,22 @@
             repo_name = repo_url.tokenize()[0].tokenize("/").last()
         }
     }
+    path_venv = "${env.WORKSPACE}/venv"
+    path_req = "${env.WORKSPACE}/${repo_name}/requirements.txt"
     sh "rm -rf ${repo_name}"
-    withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
+    // this is temporary W/A for offline deployments
+    // Jenkins slave image has /opt/pip-mirror/ folder
+    // where pip wheels for cvp projects are located
+    if (proxy != 'offline') {
+        withEnv(["HTTPS_PROXY=${proxy}", "HTTP_PROXY=${proxy}", "https_proxy=${proxy}", "http_proxy=${proxy}"]) {
+            sh "git clone ${repo_url}"
+            python.setupVirtualenv(path_venv, "python2", [], path_req, true)
+        }
+    }
+    else {
         sh "git clone ${repo_url}"
-        python.setupVirtualenv("${env.WORKSPACE}/venv", "python2", [], "${env.WORKSPACE}/${repo_name}/requirements.txt", true)
+        sh "virtualenv ${path_venv} --python python2"
+        python.runVirtualenvCommand(path_venv, "pip install --no-index --find-links=/opt/pip-mirror/ -r ${path_req}", true)
     }
 }