Merge "Fix return value for check_36461"
diff --git a/src/com/mirantis/mk/KaasUtils.groovy b/src/com/mirantis/mk/KaasUtils.groovy
index a183cb2..bc264d5 100644
--- a/src/com/mirantis/mk/KaasUtils.groovy
+++ b/src/com/mirantis/mk/KaasUtils.groovy
@@ -367,7 +367,10 @@
     }
 
     // calculate weight of current demo run to manage lockable resources
-    def demoWeight = (deployChild || runUie2e) ? 2 : 1 // management = 1, child = 1
+    def demoWeight = deployChild ? 2 : 1 // management = 1, child += 1
+    if (runUie2e) {
+        demoWeight += 1
+    }
 
     if (commitMsg ==~ /(?s).*\[bootstrapv2-scenario\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*bootstrapv2-scenario\.*/) {
         bootstrapV2Scenario = true
@@ -413,7 +416,7 @@
         Equinix provider deployment scheduled: ${equinixOnDemandDemo}
         EquinixmetalV2 provider deployment scheduled: ${equinixMetalV2OnDemandDemo}
         EquinixmetalV2 child deploy in a separate metro scheduled: ${equinixMetalV2ChildDiffMetro}
-        EquinixmetalV2 mgmt will be deployed on the ${equinixMetalV2Metro} metro
+        EquinixmetalV2 mgmt will be deployed on the metro: ${equinixMetalV2Metro?:'auto'}
         Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
         Azure provider deployment scheduled: ${azureOnDemandDemo}
         Azure@AWS child cluster deployment scheduled: ${azureOnAwsDemo}
@@ -1112,17 +1115,34 @@
     def metalUrl = "https://artifactory.mcp.mirantis.net:443/artifactory/binary-dev-kaas-local/core/bin/mirror/metal-${version}-linux"
     def metros = []
     def out = ''
+    def retries = 10 // number of retries
+    def i = 0
+    def delay = 60 // 1 minute sleep
     try {
         sh "curl -o metal -# ${metalUrl} && chmod +x metal"
         withCredentials([string(credentialsId: env.KAAS_EQUINIX_API_TOKEN, variable: 'KAAS_EQUINIX_API_TOKEN')]) {
             sh 'echo "project-id: ${KAAS_EQUINIX_PROJECT_ID}\ntoken: ${KAAS_EQUINIX_API_TOKEN}" >metal.yaml'
-            out = sh(script: "./metal --config metal.yaml capacity get -m -P ${nodeType}|awk '/${nodeType}/ {print \$2}'|paste -s -d,|xargs ./metal --config metal.yaml capacity check -P ${nodeType} -q ${nodeCount} -m|grep true|awk '{print \$2}'|paste -s -d,", returnStdout: true).trim()
-            sh 'rm metal.yaml'
         }
-        metros = out.tokenize(',')
+        common.infoMsg("Selecting available Equinix metro with free ${nodeCount} ${nodeType} hosts")
+        while (metros.size() == 0 && i < retries) {
+            common.infoMsg("Try ${i+1}/${retries} ...")
+            if (i > 0 ) { // skip sleep on first step
+                sleep(delay)
+            }
+            out = sh(script: "./metal --config metal.yaml capacity get -m -P ${nodeType}|awk '/${nodeType}/ {print \$2}'|paste -s -d,|xargs ./metal --config metal.yaml capacity check -P ${nodeType} -q ${nodeCount} -m|grep true|awk '{print \$2}'|paste -s -d,", returnStdout: true).trim()
+            metros = out.tokenize(',')
+            i++
+        }
     } catch (Exception e) {
         common.errorMsg "Exception: '${e}'"
         return []
+    } finally {
+        sh 'rm metal.yaml'
+    }
+    if (metros.size() > 0) {
+        common.infoMsg("Selected metros: ${metros}")
+    } else {
+        common.warningMsg('No any metros have been selected !!! :(')
     }
     return metros
 }