Fix guess for distrib version

  * Requred for cross-version tests,
    aka CC from release, RS from master

Bug-release: PROD-00000

Change-Id: I4f3359189fc06951ce7da766ec98d3c409d64e25
diff --git a/test-cookiecutter-reclass-chunk.groovy b/test-cookiecutter-reclass-chunk.groovy
index 8c804a1..de30e65 100644
--- a/test-cookiecutter-reclass-chunk.groovy
+++ b/test-cookiecutter-reclass-chunk.groovy
@@ -15,7 +15,7 @@
             extraVars = readYaml text: EXTRA_VARIABLES_YAML
             try {
                 currentBuild.description = extraVars.modelFile
-                sh(script:  'find . -mindepth 1 -delete || true', returnStatus: true)
+                sh(script: 'find . -mindepth 1 -delete || true', returnStatus: true)
                 sh(script: """
                     wget --progress=dot:mega --auth-no-challenge -O models.tar.gz ${extraVars.MODELS_TARGZ}
                     tar -xzf models.tar.gz
@@ -25,14 +25,14 @@
                 def content = readFile(file: extraVars.modelFile)
                 def templateContext = readYaml text: content
                 def config = [
-                    'dockerHostname': "cfg01",
-                    'domain': "${templateContext.default_context.cluster_domain}",
-                    'clusterName': templateContext.default_context.cluster_name,
-                    'reclassEnv': extraVars.testReclassEnv,
-                    'distribRevision': extraVars.DISTRIB_REVISION,
+                    'dockerHostname'     : "cfg01",
+                    'domain'             : "${templateContext.default_context.cluster_domain}",
+                    'clusterName'        : templateContext.default_context.cluster_name,
+                    'reclassEnv'         : extraVars.testReclassEnv,
+                    'distribRevision'    : extraVars.DISTRIB_REVISION,
                     'dockerContainerName': extraVars.DockerCName,
-                    'testContext': extraVars.modelFile,
-                    'dockerExtraOpts': [ '--memory=3g' ]
+                    'testContext'        : extraVars.modelFile,
+                    'dockerExtraOpts'    : ['--memory=3g']
                 ]
                 if (extraVars.DISTRIB_REVISION == 'nightly') {
                     config['nodegenerator'] = true
@@ -50,9 +50,9 @@
             } finally {
                 stage('Save artifacts to Artifactory') {
                     def artifactory = new com.mirantis.mcp.MCPArtifactory()
-                    def envGerritVars = [ "GERRIT_PROJECT=${extraVars.get('GERRIT_PROJECT', '')}", "GERRIT_CHANGE_NUMBER=${extraVars.get('GERRIT_CHANGE_NUMBER', '')}",
-                                          "GERRIT_PATCHSET_NUMBER=${extraVars.get('GERRIT_PATCHSET_NUMBER', '')}", "GERRIT_CHANGE_ID=${extraVars.get('GERRIT_CHANGE_ID', '')}",
-                                          "GERRIT_PATCHSET_REVISION=${extraVars.get('GERRIT_PATCHSET_REVISION', '')}" ]
+                    def envGerritVars = ["GERRIT_PROJECT=${extraVars.get('GERRIT_PROJECT', '')}", "GERRIT_CHANGE_NUMBER=${extraVars.get('GERRIT_CHANGE_NUMBER', '')}",
+                                         "GERRIT_PATCHSET_NUMBER=${extraVars.get('GERRIT_PATCHSET_NUMBER', '')}", "GERRIT_CHANGE_ID=${extraVars.get('GERRIT_CHANGE_ID', '')}",
+                                         "GERRIT_PATCHSET_REVISION=${extraVars.get('GERRIT_PATCHSET_REVISION', '')}"]
                     withEnv(envGerritVars) {
                         def artifactoryLink = artifactory.uploadJobArtifactsToArtifactory(['artifactory': 'mcp-ci', 'artifactoryRepo': "drivetrain-local/${JOB_NAME}/${BUILD_NUMBER}"])
                         currentBuild.description += "<br/>${artifactoryLink}"
diff --git a/test-cookiecutter-reclass.groovy b/test-cookiecutter-reclass.groovy
index aa695f2..b7004f6 100644
--- a/test-cookiecutter-reclass.groovy
+++ b/test-cookiecutter-reclass.groovy
@@ -209,6 +209,12 @@
     gerritDataRSHEAD << gerritDataRS
     gerritDataRSHEAD['gerritRefSpec'] = null
     gerritDataRSHEAD['GERRIT_CHANGE_NUMBER'] = null
+    // check for test XXX vs RELEASE branch, to get correct formulas
+    if (gerritDataCC['gerritBranch'].contains('release/')) {
+        testDistribRevision = gerritDataCC['gerritBranch']
+    } else if (gerritDataRS['gerritBranch'].contains('release')) {
+        testDistribRevision = gerritDataRS['gerritBranch']
+    }
     // 'binary' branch logic w\o 'release/' prefix
     if (testDistribRevision.contains('/')) {
         testDistribRevision = testDistribRevision.split('/')[-1]
@@ -219,8 +225,8 @@
     if (!binTest.linux_system_repo_url || !binTest.linux_system_repo_ubuntu_url) {
         common.errorMsg("Binary release: ${testDistribRevision} not exist or not full. Fallback to 'proposed'! ")
         testDistribRevision = 'proposed'
-        messages.add("DISTRIB_REVISION => ${testDistribRevision}")
     }
+    messages.add("DISTRIB_REVISION => ${testDistribRevision}")
     def message = messages.join(newline) + newline
     currentBuild.description = currentBuild.description ? message + currentBuild.description : message
 }
@@ -390,7 +396,7 @@
                 result = '\n' + common.comparePillars(compareRoot, env.BUILD_URL, "-Ev \'infra/secrets.yml|\\.git\'")
                 currentBuild.description = currentBuild.description ? currentBuild.description + result : result
             }
-            stage("TestContexts Head/Patched") {
+            stage('TestContexts Head/Patched') {
                 def stepsForParallel = [:]
                 stepsForParallel.failFast = true
                 common.infoMsg("Found: ${contextFileListHead.size()} HEAD contexts to test.")
@@ -406,7 +412,7 @@
                 parallel stepsForParallel
                 common.infoMsg('All TestContexts tests done')
             }
-            stage("Compare NodesInfo Head/Patched") {
+            stage('Compare NodesInfo Head/Patched') {
                 // Download all artifacts
                 def stepsForParallel = [:]
                 stepsForParallel.failFast = true
@@ -480,3 +486,4 @@
         }
     }
 }
+