Merge "Fix saltModelTesting.setupAndTestNode call's"
diff --git a/generate-cookiecutter-products.groovy b/generate-cookiecutter-products.groovy
index 6964653..0a5cbfb 100644
--- a/generate-cookiecutter-products.groovy
+++ b/generate-cookiecutter-products.groovy
@@ -166,27 +166,33 @@
                 git.commitGitChanges(modelEnv, "Create model ${clusterName}", "${user}@localhost", "${user}")
             }
 
-            stage("Test") {
-                if (sharedReclassUrl != "" && TEST_MODEL && TEST_MODEL.toBoolean()) {
-                    sh("cp -r ${modelEnv} ${testEnv}")
-                    def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
-                    saltModelTesting.setupAndTestNode(
-                            "${saltMaster}.${clusterDomain}",
-                            "",
-                            "",
-                            testEnv,
-                            'pkg',
-                            'stable',
-                            'master',
-                            0,
-                            false,
-                            false,
-                            '',
-                            '',
-                            DockerCName)
-                }
+          stage("Test") {
+            if (sharedReclassUrl != "" && TEST_MODEL && TEST_MODEL.toBoolean()) {
+              sh("cp -r ${modelEnv} ${testEnv}")
+              def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
+              def testResult = false
+              testResult = saltModelTesting.setupAndTestNode(
+                  "${saltMaster}.${clusterDomain}",
+                  "",
+                  "",
+                  testEnv,
+                  'pkg',
+                  'stable',
+                  'master',
+                  0,
+                  false,
+                  false,
+                  '',
+                  '',
+                  DockerCName)
             }
-
+            if (testResult) {
+              common.infoMsg("Test finished: SUCCESS")
+            } else {
+              error('Test finished: FAILURE')
+              currentBuild.result = "FAILURE"
+            }
+          }
             stage("Generate config drives") {
                 // apt package genisoimage is required for this stage
 
diff --git a/test-cookiecutter-reclass.groovy b/test-cookiecutter-reclass.groovy
index fedbd14..eb74b22 100644
--- a/test-cookiecutter-reclass.groovy
+++ b/test-cookiecutter-reclass.groovy
@@ -77,49 +77,43 @@
 }
 
 def testModel(modelFile, testEnv) {
-    def templateEnv = "${env.WORKSPACE}"
-    def content = readFile(file: "${templateEnv}/contexts/${modelFile}.yml")
-    def templateContext = readYaml text: content
-    def clusterName = templateContext.default_context.cluster_name
-    def clusterDomain = templateContext.default_context.cluster_domain
-    if (SYSTEM_GIT_URL == "") {
-        git.checkoutGitRepository("${testEnv}/classes/system", RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, CREDENTIALS_ID)
-    } else {
-        dir("${testEnv}/classes/system") {
-            if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
-              common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
-            }
-        }
+  def templateEnv = "${env.WORKSPACE}"
+  def content = readFile(file: "${templateEnv}/contexts/${modelFile}.yml")
+  def templateContext = readYaml text: content
+  def clusterName = templateContext.default_context.cluster_name
+  def clusterDomain = templateContext.default_context.cluster_domain
+  if (SYSTEM_GIT_URL == "") {
+    git.checkoutGitRepository("${testEnv}/classes/system", RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, CREDENTIALS_ID)
+  } else {
+    dir("${testEnv}/classes/system") {
+      if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
+        common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
+      }
     }
+  }
 
-    def nbTry = 0
-    while (nbTry < 5) {
-        nbTry++
-        try {
-            def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
-            saltModelTesting.setupAndTestNode(
-                    "cfg01.${clusterDomain}",
-                    clusterName,
-                    EXTRA_FORMULAS,
-                    testEnv,
-                    'pkg',
-                    DISTRIB_REVISION,
-                    'master',
-                    0,
-                    false,
-                    false,
-                    '',
-                    '',
-                    DockerCName)
-            break
-        } catch (Exception e) {
-            if (e.getMessage() == "script returned exit code 124") {
-                common.errorMsg("Impossible to test node due to timeout of salt-master, retriggering")
-            } else {
-                throw e
-            }
-        }
-    }
+  def testResult = false
+  def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
+  testResult = saltModelTesting.setupAndTestNode(
+      "cfg01.${clusterDomain}",
+      clusterName,
+      EXTRA_FORMULAS,
+      testEnv,
+      'pkg',
+      DISTRIB_REVISION,
+      'master',
+      0,
+      false,
+      false,
+      '',
+      '',
+      DockerCName)
+  if (testResult) {
+    common.infoMsg("testModel finished: SUCCESS")
+  } else {
+    error('testModel finished: FAILURE')
+    currentBuild.result = "FAILURE"
+  }
 
 }
 
diff --git a/test-salt-model-node.groovy b/test-salt-model-node.groovy
index 694f048..9e72555 100644
--- a/test-salt-model-node.groovy
+++ b/test-salt-model-node.groovy
@@ -62,11 +62,11 @@
         stage("test node") {
           if (checkouted) {
             def workspace = common.getWorkspace()
+            def testResult = false
             common.infoMsg("Running salt model test for node ${NODE_TARGET} in cluster ${CLUSTER_NAME}")
             try {
               def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}"
-
-              test_result = saltModelTesting.setupAndTestNode(
+              testResult = saltModelTesting.setupAndTestNode(
                   NODE_TARGET,
                   CLUSTER_NAME,
                   EXTRA_FORMULAS,
@@ -88,10 +88,10 @@
                 throw e
               }
             }
-            if (test_result) {
+            if (testResult) {
               common.infoMsg("Test finished: SUCCESS")
             } else {
-              common.warningMsg("Test finished: FAILURE")
+              error('Test finished: FAILURE')
               currentBuild.result = "FAILURE"
             }
           }