Merge "Fix prometheus update during compute node deploy"
diff --git a/cvp-ha.groovy b/cvp-ha.groovy
index 4952502..4bb5018 100644
--- a/cvp-ha.groovy
+++ b/cvp-ha.groovy
@@ -29,6 +29,7 @@
 def artifacts_dir = 'validation_artifacts/'
 def remote_artifacts_dir = '/root/qa_results/'
 def current_target_node = ''
+def first_node = ''
 def tempest_result = ''
 timeout(time: 12, unit: 'HOURS') {
     node() {
@@ -61,6 +62,7 @@
                 current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES)
                 common.warningMsg("Shutdown current vip node ${current_target_node}")
                 validate.shutdown_vm_node(saltMaster, current_target_node, 'soft_shutdown')
+                sleep 15
             }
             stage('Check during shutdown') {
                 tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_shutdown")
@@ -79,6 +81,9 @@
                 if (status == null) {
                     throw new Exception("Node ${current_target_node} cannot start")
                 }
+                first_node = current_target_node
+                current_target_node = ''
+                sleep 30
             }
             stage('Check after shutdown') {
                 tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_shutdown")
@@ -96,10 +101,12 @@
                         input message: "Are you sure you want to hard shutdown current vip node?"
                     }
                 }
-                salt.cmdRun(saltMaster, current_target_node, "service keepalived stop")
+                salt.cmdRun(saltMaster, first_node, "service keepalived stop")
                 current_target_node = validate.get_vip_node(saltMaster, TARGET_NODES)
                 common.warningMsg("Shutdown current vip node ${current_target_node}")
                 validate.shutdown_vm_node(saltMaster, current_target_node, 'hard_shutdown')
+                sleep 10
+                salt.cmdRun(saltMaster, first_node, "service keepalived start")
             }
             stage('Check during hard shutdown') {
                 tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_during_hard_shutdown")
@@ -116,9 +123,10 @@
                 common.infoMsg("Checking that node is UP")
                 status = salt.minionsReachable(saltMaster, 'I@salt:master', current_target_node, null, 10, num_retries)
                 if (status == null) {
-                    throw new Exception("Command execution failed")
+                    throw new Exception("Node ${current_target_node} cannot start")
                 }
-                salt.cmdRun(saltMaster, TARGET_NODES, "service keepalived start")
+                current_target_node = ''
+                sleep 30
             }
             stage('Check after hard shutdown') {
                 tempest_result = validate.runCVPtempest(saltMaster, TEMPEST_TARGET_NODE, TEMPEST_TEST_PATTERN, SKIP_LIST_PATH, remote_artifacts_dir, "docker_tempest_after_hard_shutdown")
@@ -127,7 +135,7 @@
                     currentBuild.result = "FAILURE"
                     throw new Exception("Tempest tests failed")
                 }
-                sleep 15
+                sleep 5
             }
 
             stage('Reboot') {
@@ -148,6 +156,7 @@
                     currentBuild.result = "FAILURE"
                     throw new Exception("Tempest tests failed")
                 }
+                sleep 30
             }
             stage('Check after reboot') {
                 common.warningMsg("Checking that node is UP")
@@ -175,6 +184,11 @@
             if (DEBUG_MODE == 'false') {
                 salt.cmdRun(saltMaster, TEMPEST_TARGET_NODE, "rm -rf ${remote_artifacts_dir}")
                 validate.runCleanup(saltMaster, TEMPEST_TARGET_NODE)
+                if (current_target_node != '') {
+                    common.warningMsg("Powering on node ${current_target_node}")
+                    kvm = validate.locate_node_on_kvm(saltMaster, current_target_node)
+                    salt.cmdRun(saltMaster, kvm, "virsh start ${current_target_node}")
+                }
             }
         }
     }
diff --git a/cvp-runner.groovy b/cvp-runner.groovy
new file mode 100644
index 0000000..dd58da5
--- /dev/null
+++ b/cvp-runner.groovy
@@ -0,0 +1,39 @@
+/**
+ *
+ * Launch pytest frameworks in Jenkins
+ *
+ * Expected parameters:
+ *   SALT_MASTER_URL                 URL of Salt master
+ *   SALT_MASTER_CREDENTIALS         Credentials to the Salt API
+ *
+ *   TESTS_SET                       Leave empty for full run or choose a file (test)
+ *   TESTS_REPO                      Repo to clone
+ *   TESTS_SETTINGS                  Additional environment varibales to apply
+ *   PROXY                           Proxy to use for cloning repo or for pip
+ *
+ */
+
+validate = new com.mirantis.mcp.Validate()
+
+def artifacts_dir = 'validation_artifacts/'
+
+node() {
+    try{
+        stage('Initialization') {
+            validate.prepareVenv(TESTS_REPO, PROXY)
+        }
+
+        stage('Run Tests') {
+            sh "mkdir -p ${artifacts_dir}"
+            validate.runTests(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS, TESTS_SET, artifacts_dir, TESTS_SETTINGS)
+        }
+        stage ('Publish results') {
+            archiveArtifacts artifacts: "${artifacts_dir}/*"
+            junit "${artifacts_dir}/*.xml"
+        }
+    } catch (Throwable e) {
+        // If there was an error or exception thrown, the build failed
+        currentBuild.result = "FAILURE"
+        throw e
+    }
+}