Move rebooting HW node before the booting cfg node

MOSSUST-109

Change-Id: Ic9c27851098837ee1be45d108fdec9e2489b2b97
diff --git a/jobs/pipelines/deploy-cicd-and-run-tests.groovy b/jobs/pipelines/deploy-cicd-and-run-tests.groovy
index 10536c7..24f65a7 100644
--- a/jobs/pipelines/deploy-cicd-and-run-tests.groovy
+++ b/jobs/pipelines/deploy-cicd-and-run-tests.groovy
@@ -131,11 +131,24 @@
   node ("${NODE_NAME}") {
     env.slave_workdir = pwd()
     try {
+        if (env.IPMI_CREDS) {
+            withCredentials([
+               [$class          : 'UsernamePasswordMultiBinding',
+               credentialsId   : "${IPMI_CREDS}",
+               passwordVariable: 'IPMI_PASS',
+               usernameVariable: 'IPMI_USER']
+                ]) {
+                env.IPMI_PASS = IPMI_PASS
+                env.IPMI_USER = IPMI_USER
+                shared.reboot_hardware_nodes("${IPMI_CREDS}")
+            }
+        }
 
         // run deploy stages
         deploy(shared, common, steps, env_manager, batch_size, dist_upgrade_nodes, upgrade_saltstack)
         // run test stages
         test(shared, common, steps, env_manager)
+
     } catch (e) {
         common.printMsg("Job is failed: " + e.message, "purple")
         throw e
diff --git a/jobs/templates/bm-cicd-pike-ovs-maas.yml b/jobs/templates/bm-cicd-pike-ovs-maas.yml
index cd44b20..8a51c81 100644
--- a/jobs/templates/bm-cicd-pike-ovs-maas.yml
+++ b/jobs/templates/bm-cicd-pike-ovs-maas.yml
@@ -180,12 +180,9 @@
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
-    - password:
-        name: IPMI_USER
-        default: 'engineer'
-    - password:
-        name: IPMI_PASS
-        default: 'KBwdcRqwed3w2'
+    - string:
+        name: IPMI_CREDS
+        default: 'lab_engineer'
     - string:
         default: ''
         description: ''
diff --git a/jobs/templates/bm-cicd-queens-ovs-maas.yml b/jobs/templates/bm-cicd-queens-ovs-maas.yml
index b8f2ccc..be5b487 100644
--- a/jobs/templates/bm-cicd-queens-ovs-maas.yml
+++ b/jobs/templates/bm-cicd-queens-ovs-maas.yml
@@ -180,12 +180,9 @@
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
-    - password:
-        name: IPMI_USER
-        default: 'engineer'
-    - password:
-        name: IPMI_PASS
-        default: 'KBwdcRqwed3w2'
+    - string:
+        name: IPMI_CREDS
+        default: 'lab_engineer'
     - string:
         default: ''
         description: ''
diff --git a/jobs/templates/bm-e7-cicd-pike-ovs-maas.yml b/jobs/templates/bm-e7-cicd-pike-ovs-maas.yml
index c85ff11..668b189 100644
--- a/jobs/templates/bm-e7-cicd-pike-ovs-maas.yml
+++ b/jobs/templates/bm-e7-cicd-pike-ovs-maas.yml
@@ -180,12 +180,9 @@
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
-    - password:
-        name: IPMI_USER
-        default: 'engineer'
-    - password:
-        name: IPMI_PASS
-        default: 'K7wy5Y39g6Ii'
+    - string:
+        name: IPMI_CREDS
+        default: 'e_lab_engineer'
     - string:
         default: ''
         description: ''
diff --git a/jobs/templates/heat-bm-cicd-pike-contrail-sl.yml b/jobs/templates/heat-bm-cicd-pike-contrail-sl.yml
index ba5b6da..c52d71e 100644
--- a/jobs/templates/heat-bm-cicd-pike-contrail-sl.yml
+++ b/jobs/templates/heat-bm-cicd-pike-contrail-sl.yml
@@ -187,12 +187,9 @@
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
-    - password:
-        name: IPMI_USER
-        default: 'engineer'
-    - password:
-        name: IPMI_PASS
-        default: 'KBwdcRqwed3w2'
+    - string:
+        name: IPMI_CREDS
+        default: 'lab_engineer'
     - string:
         default: ''
         description: ''
diff --git a/jobs/templates/heat-bm-cicd-queens-contrail-sl.yml b/jobs/templates/heat-bm-cicd-queens-contrail-sl.yml
index a46b7c1..1d7c0bc 100644
--- a/jobs/templates/heat-bm-cicd-queens-contrail-sl.yml
+++ b/jobs/templates/heat-bm-cicd-queens-contrail-sl.yml
@@ -188,12 +188,9 @@
         description: ''
         name: UPDATE_VERSION
         trim: 'false'
-    - password:
-        name: IPMI_USER
-        default: 'engineer'
-    - password:
-        name: IPMI_PASS
-        default: 'KBwdcRqwed3w2'
+    - string:
+        name: IPMI_CREDS
+        default: 'lab_engineer'
     - string:
         default: ''
         description: ''
diff --git a/src/com/mirantis/system_qa/SharedPipeline.groovy b/src/com/mirantis/system_qa/SharedPipeline.groovy
index 72ff052..e83a94b 100644
--- a/src/com/mirantis/system_qa/SharedPipeline.groovy
+++ b/src/com/mirantis/system_qa/SharedPipeline.groovy
@@ -780,3 +780,16 @@
     return ret
   }
 }
+def reboot_hardware_nodes(creds_name) {
+    bm_ips_file = readFile("tcp_tests/templates/${creds_name}")
+    bm_ips = bm_ips_file.split("\n")
+    withCredentials([
+       [$class          : 'UsernamePasswordMultiBinding',
+       credentialsId   : creds_name,
+       passwordVariable: 'lab_pass',
+       usernameVariable: 'lab_user']
+    ]) {
+        for (String ip : bm_ips)  { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} -I lanplus  chassis power off")}
+        for (String ip : bm_ips)  { sh ("ipmitool -H ${ip} -U ${lab_user} -P ${lab_pass} -I lanplus  chassis bootdev pxe")}
+    }
+}
diff --git a/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml b/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
index f0b727e..9fba121 100644
--- a/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
+++ b/tcp_tests/templates/bm-cicd-pike-ovs-maas/salt.yaml
@@ -15,24 +15,6 @@
   skip_fail: false
 
 {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
-{{ SHARED_MAAS.REBOOT_HW_NODES('engineer', 'KBwdcRqwed3w2',
-  [
-      "185.8.59.227",
-      "185.8.59.229",
-      "5.43.225.88",
-      "5.43.225.112",
-      "5.43.225.208",
-      "5.43.227.118",
-      "185.8.58.248",
-      "185.8.59.222",
-      "5.43.225.228",
-      "5.43.229.28",
-      "5.43.225.23",
-      "185.8.58.9",
-      "185.8.58.246",
-      "185.8.58.243",
-      "185.8.58.244"
-  ]) }}
 
 {{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
 
diff --git a/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml b/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
index f008071..7b33cd2 100644
--- a/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
+++ b/tcp_tests/templates/bm-cicd-queens-ovs-maas/salt.yaml
@@ -15,24 +15,6 @@
   skip_fail: false
 
 {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
-{{ SHARED_MAAS.REBOOT_HW_NODES('engineer', 'KBwdcRqwed3w2',
-  [
-      "185.8.59.227",
-      "185.8.59.229",
-      "5.43.225.88",
-      "5.43.225.112",
-      "5.43.225.208",
-      "5.43.227.118",
-      "185.8.58.248",
-      "185.8.59.222",
-      "5.43.225.228",
-      "5.43.229.28",
-      "5.43.225.23",
-      "185.8.58.9",
-      "185.8.58.246",
-      "185.8.58.243",
-      "185.8.58.244"
-  ]) }}
 
 {{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
 
diff --git a/tcp_tests/templates/bm-e7-cicd-pike-ovs-maas/salt.yaml b/tcp_tests/templates/bm-e7-cicd-pike-ovs-maas/salt.yaml
index 2bc00c8..a9617f1 100644
--- a/tcp_tests/templates/bm-e7-cicd-pike-ovs-maas/salt.yaml
+++ b/tcp_tests/templates/bm-e7-cicd-pike-ovs-maas/salt.yaml
@@ -15,18 +15,6 @@
   skip_fail: false
 
 {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
-{{ SHARED_MAAS.REBOOT_HW_NODES('engineer', 'K7wy5Y39g6Ii',
-  [
-      "176.74.217.64",
-      "185.8.59.228",
-      "5.43.225.89",
-      "5.43.227.11",
-      "5.43.227.19",
-      "5.43.225.74",
-      "5.43.225.16",
-      "5.43.225.172"
-  ]) }}
-
 
 {{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
 
diff --git a/tcp_tests/templates/e_lab_engineer b/tcp_tests/templates/e_lab_engineer
new file mode 100644
index 0000000..91bcf2f
--- /dev/null
+++ b/tcp_tests/templates/e_lab_engineer
@@ -0,0 +1,8 @@
+176.74.217.64
+185.8.59.228
+5.43.225.89
+5.43.227.11
+5.43.227.19
+5.43.225.74
+5.43.225.16
+5.43.225.172
\ No newline at end of file
diff --git a/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml b/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
index d069df0..561c8a1 100644
--- a/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
+++ b/tcp_tests/templates/heat-bm-cicd-pike-contrail-sl/salt.yaml
@@ -17,24 +17,6 @@
   skip_fail: false
 
 {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
-{{ SHARED_MAAS.REBOOT_HW_NODES('engineer', 'KBwdcRqwed3w2',
-  [
-      "185.8.59.227",
-      "185.8.59.229",
-      "5.43.225.88",
-      "5.43.225.112",
-      "5.43.225.208",
-      "5.43.227.118",
-      "185.8.58.248",
-      "185.8.59.222",
-      "5.43.225.228",
-      "5.43.229.28",
-      "5.43.225.23",
-      "185.8.58.9",
-      "185.8.58.246",
-      "185.8.58.243",
-      "185.8.58.244"
-  ]) }}
 
 {{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
 
diff --git a/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml b/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
index 06b692c..df263e9 100644
--- a/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
+++ b/tcp_tests/templates/heat-bm-cicd-queens-contrail-sl/salt.yaml
@@ -17,24 +17,6 @@
   skip_fail: false
 
 {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
-{{ SHARED_MAAS.REBOOT_HW_NODES('engineer', 'KBwdcRqwed3w2',
-  [
-      "185.8.59.227",
-      "185.8.59.229",
-      "5.43.225.88",
-      "5.43.225.112",
-      "5.43.225.208",
-      "5.43.227.118",
-      "185.8.58.248",
-      "185.8.59.222",
-      "5.43.225.228",
-      "5.43.229.28",
-      "5.43.225.23",
-      "185.8.58.9",
-      "185.8.58.246",
-      "185.8.58.243",
-      "185.8.58.244"
-  ]) }}
 
 {{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
 
diff --git a/tcp_tests/templates/lab_engineer b/tcp_tests/templates/lab_engineer
new file mode 100644
index 0000000..c6496ac
--- /dev/null
+++ b/tcp_tests/templates/lab_engineer
@@ -0,0 +1,15 @@
+185.8.59.227
+185.8.59.229
+5.43.225.88
+5.43.225.112
+5.43.225.208
+5.43.227.118
+185.8.58.248
+185.8.59.222
+5.43.225.228
+5.43.229.28
+5.43.225.23
+185.8.58.9
+185.8.58.246
+185.8.58.243
+185.8.58.244
\ No newline at end of file