Merge "fix removing osd"
diff --git a/ceph-enforce-weights.groovy b/ceph-enforce-weights.groovy
new file mode 100644
index 0000000..4e418d7
--- /dev/null
+++ b/ceph-enforce-weights.groovy
@@ -0,0 +1,58 @@
+/**
+ *
+ * Enforce OSD weights from model
+ *
+ * Requred parameters:
+ *  SALT_MASTER_URL             URL of Salt master
+ *  SALT_MASTER_CREDENTIALS     Credentials to the Salt API
+ *
+ *  ADMIN_HOST                  Host (minion id) with admin keyring
+ *
+ */
+
+common = new com.mirantis.mk.Common()
+salt = new com.mirantis.mk.Salt()
+
+// configure global variables
+def saltMaster
+
+def runCephCommand(master, cmd) {
+    return salt.cmdRun(master, ADMIN_HOST, cmd)
+}
+
+node("python") {
+
+    stage('Load cluster information') {
+        // create connection to salt master
+        saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+
+        // get list of disk from grains
+        def grains = salt.getGrain(saltMaster, 'I@ceph:osd')['return'][0]
+
+
+    }
+
+    stage('Enforce weights on OSDs') {
+
+        for (host in grains) {
+            // parse grains
+            def hostGrains = host.value
+            common.prettyPrint(hostGrains)
+
+            def hostname = hostGrains.host
+            def salt_id = hostGrains.id
+            def ceph_host_id = hostGrains.ceph_osd_host_id
+
+            common.infoMsg("Setting weights on host ${hostname} (${salt_id}), ceph_id ${ceph_host_id}")
+            for (disk in hostGrains.ceph_osd_disk) {
+                def osd_id = ceph_host_id + disk.key
+                print(osd_id)
+                print(disk.value)
+                print(disk.key)
+                def cmd = "ceph osd crush set ${osd_id} ${disk.value.weight} host=${hostname}"
+                print(runCephCommand(saltMaster, cmd))
+            }
+        }
+
+    }
+}
diff --git a/test-cookiecutter-reclass.groovy b/test-cookiecutter-reclass.groovy
index 4b93751..52d7c8c 100644
--- a/test-cookiecutter-reclass.groovy
+++ b/test-cookiecutter-reclass.groovy
@@ -80,8 +80,9 @@
     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
-    git.checkoutGitRepository("${testEnv}/classes/system", RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, CREDENTIALS_ID)
+    git.checkoutGitRepository("${testEnv}/classes/system", clusterName, RECLASS_MODEL_URL, RECLASS_MODEL_BRANCH, CREDENTIALS_ID)
     saltModelTesting.setupAndTestNode("cfg01.${clusterDomain}", EXTRA_FORMULAS, testEnv)
 }
 
diff --git a/test-salt-model-node.groovy b/test-salt-model-node.groovy
index a2e6923..913bae9 100644
--- a/test-salt-model-node.groovy
+++ b/test-salt-model-node.groovy
@@ -5,6 +5,7 @@
  *  DEFAULT_GIT_URL
  *  CREDENTIALS_ID
  *  EXTRA_FORMULAS
+ *  CLUSTER_NAME
  *  NODE_TARGET
  *  SYSTEM_GIT_URL
  *  SYSTEM_GIT_REF
@@ -53,7 +54,7 @@
     stage("test node") {
       if (checkouted) {
         def workspace = common.getWorkspace()
-        saltModelTesting.setupAndTestNode(NODE_TARGET, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE, FORMULAS_REVISION, MAX_CPU_PER_JOB.toInteger())
+        saltModelTesting.setupAndTestNode(NODE_TARGET, CLUSTER_NAME, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE, FORMULAS_REVISION, MAX_CPU_PER_JOB.toInteger())
       }
     }
   } catch (Throwable e) {
diff --git a/test-salt-models-pipeline.groovy b/test-salt-models-pipeline.groovy
index 5b97b5d..9bd2ca5 100644
--- a/test-salt-models-pipeline.groovy
+++ b/test-salt-models-pipeline.groovy
@@ -85,6 +85,7 @@
         def acc = 0
         for (int i = 0; i < nodes.size(); i++) {
           def testTarget = sh(script: "basename ${nodes[i]} .yml", returnStdout: true).trim()
+          def clusterName = testTarget.substring(testTarget.indexOf(".") + 1, testTarget.lastIndexOf("."))
           if (acc >= PARALLEL_NODE_GROUP_SIZE.toInteger()) {
             parallel branches
             branches = [:]
@@ -95,6 +96,7 @@
             build job: "test-salt-model-node", parameters: [
               [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
               [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
+              [$class: 'StringParameterValue', name: 'CLUSTER_NAME', value: clusterName],
               [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget],
               [$class: 'StringParameterValue', name: 'FORMULAS_SOURCE', value: formulasSource],
               [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS],
diff --git a/test-service.groovy b/test-service.groovy
index 29c88b2..f7cdd64 100644
--- a/test-service.groovy
+++ b/test-service.groovy
@@ -87,18 +87,10 @@
 
             writeFile(file: 'report.xml', text: salt.getFileContent(saltMaster, TEST_TEMPEST_TARGET, '/root/report.xml'))
             junit(keepLongStdio: true, testResults: 'report.xml', healthScaleFactor:  Double.parseDouble(TEST_JUNIT_RATIO))
-        }
-        stage("Approve test results"){
-          try {
-            timeout(time: 1, unit: 'HOURS'){
-              userInput = input message: 'Do you want to approve test results?'
+            def testResults = test.collectJUnitResults(currentBuild.rawBuild.getAction(hudson.tasks.test.AbstractTestResultAction.class))
+            if(testResults){
+                currentBuild.desc = String.format("result: %s", testResults["failed"] / testResults["total"])
             }
-            common.successMsg("Test results approved")
-            currentBuild.desc = "result: true"
-          } catch(err) { // timeout reached or input false
-            common.errorMsg("Test results not approved")
-            currentBuild.desc = "result: false"
-          }
         }
     } catch (Throwable e) {
         currentBuild.result = 'FAILURE'
diff --git a/validate-cloud.groovy b/validate-cloud.groovy
index 6c25071..8381d6e 100644
--- a/validate-cloud.groovy
+++ b/validate-cloud.groovy
@@ -11,11 +11,15 @@
  *   TEMPEST_TEST_SET            If not false, run tests matched to pattern only
  *   RUN_TEMPEST_TESTS           If not false, run Tempest tests
  *   RUN_RALLY_TESTS             If not false, run Rally tests
+ *   RUN_K8S_TESTS               If not false, run Kubernetes tests
+ *   TEST_K8S_API_SERVER         Kubernetes API address
+ *   TEST_K8S_CONFORMANCE_IMAGE  Path to docker image with conformance e2e tests
  *
  */
 
 common = new com.mirantis.mk.Common()
 salt = new com.mirantis.mk.Salt()
+test = new com.mirantis.mk.Test()
 validate = new com.mirantis.mcp.Validate()
 
 def saltMaster
@@ -48,6 +52,39 @@
                 common.infoMsg("Skipping Rally tests")
             }
         }
+
+        stage('Run k8s bootstrap tests') {
+            if (RUN_K8S_TESTS.toBoolean() == true) {
+                def image = 'tomkukral/k8s-scripts'
+                def output_file = image.replaceAll('/', '-') + '.output'
+
+                // run image
+                test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
+
+                // collect output
+                def file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
+                writeFile file: "${artifacts_dir}${output_file}", text: file_content
+            } else {
+                common.infoMsg("Skipping k8s bootstrap tests")
+            }
+        }
+
+        stage('Run k8s conformance e2e tests') {
+            if (RUN_K8S_TESTS.toBoolean() == true) {
+                def image = TEST_K8S_CONFORMANCE_IMAGE
+                def output_file = image.replaceAll('/', '-') + '.output'
+
+                // run image
+                test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
+
+                // collect output
+                def file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
+                writeFile file: "${artifacts_dir}${output_file}", text: file_content
+            } else {
+                common.infoMsg("Skipping k8s conformance e2e tests")
+            }
+        }
+
         stage('Collect results') {
             archiveArtifacts artifacts: "${artifacts_dir}/*"
         }