Pipeline verification

- Added stage for report generation
This stage depends on the value of boolean GENERATE_REPORT variable which will be defined in the CI job
- Added report generation for K8S
- Added parameter TEST_K8S_NODE
- Depends on https://gerrit.mcp.mirantis.net/#/c/9483/

Change-Id: I4fc5051d80ca8db4cd203662030f08a513d65233
diff --git a/validate-cloud.groovy b/validate-cloud.groovy
index 5768f59..d412877 100644
--- a/validate-cloud.groovy
+++ b/validate-cloud.groovy
@@ -21,6 +21,9 @@
  *   SPT_AVAILABILITY_ZONE       The name of availability zone
  *   TEST_K8S_API_SERVER         Kubernetes API address
  *   TEST_K8S_CONFORMANCE_IMAGE  Path to docker image with conformance e2e tests
+ *   TEST_K8S_NODE               Kubernetes node to run tests from
+ *   GENERATE_REPORT             If not false, run report generation command
+ *   ACCUMULATE_RESULTS          If true, results from the previous build will be used
  *
  */
 
@@ -40,6 +43,9 @@
 
         stage('Configure') {
             validate.installDocker(saltMaster, TARGET_NODE)
+            if (ACCUMULATE_RESULTS.toBoolean() == false) {
+                sh "rm -r ${artifacts_dir}"
+            }
             sh "mkdir -p ${artifacts_dir}"
             def spt_variables = "-e spt_ssh_user=${SPT_SSH_USER} " +
                     "-e spt_floating_network=${SPT_FLOATING_NETWORK} " +
@@ -75,13 +81,12 @@
         stage('Run k8s bootstrap tests') {
             if (RUN_K8S_TESTS.toBoolean() == true) {
                 def image = 'tomkukral/k8s-scripts'
-                def output_file = image.replaceAll('/', '-') + '.output'
+                def output_file = 'k8s-bootstrap-tests.txt'
+                def containerName = 'conformance_tests'
+                def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output'
+                test.runConformanceTests(saltMaster, TEST_K8S_NODE, TEST_K8S_API_SERVER, image)
 
-                // run image
-                test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
-
-                // collect output
-                def file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
+                def file_content = validate.getFileContent(saltMaster, TEST_K8S_NODE, outfile)
                 writeFile file: "${artifacts_dir}${output_file}", text: file_content
             } else {
                 common.infoMsg("Skipping k8s bootstrap tests")
@@ -91,19 +96,25 @@
         stage('Run k8s conformance e2e tests') {
             if (RUN_K8S_TESTS.toBoolean() == true) {
                 def image = TEST_K8S_CONFORMANCE_IMAGE
-                def output_file = image.replaceAll('/', '-') + '.output'
+                def output_file = 'report-k8s-e2e-tests.txt'
+                def containerName = 'conformance_tests'
+                def outfile = "/tmp/" + image.replaceAll('/', '-') + '.output'
+                test.runConformanceTests(saltMaster, TEST_K8S_NODE, TEST_K8S_API_SERVER, image)
 
-                // run image
-                test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
-
-                // collect output
-                def file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
+                def file_content = validate.getFileContent(saltMaster, TEST_K8S_NODE, outfile)
                 writeFile file: "${artifacts_dir}${output_file}", text: file_content
             } else {
                 common.infoMsg("Skipping k8s conformance e2e tests")
             }
         }
-
+        stage('Generate report') {
+            if (GENERATE_REPORT.toBoolean() == true) {
+                print("Generating html test report ...")
+                validate.generateTestReport(saltMaster, TARGET_NODE, artifacts_dir)
+            } else {
+                common.infoMsg("Skipping report generation")
+            }
+        }
         stage('Collect results') {
             archiveArtifacts artifacts: "${artifacts_dir}/*"
         }