Merge "Get api version / remove hardcoded v2"
diff --git a/src/com/mirantis/mcp/Validate.groovy b/src/com/mirantis/mcp/Validate.groovy
index 2c66b71..48f73a7 100644
--- a/src/com/mirantis/mcp/Validate.groovy
+++ b/src/com/mirantis/mcp/Validate.groovy
@@ -371,7 +371,7 @@
  * @param skip_scenarios    Comma-delimited list of scenarios names to skip
  * @param bundle_file       Bundle name to create
 */
-def bundle_up_scenarios(scenarios_path, skip_scenarios, bundle_file) {
+def bundle_up_scenarios(scenarios_path, skip_scenarios, bundle_file = '' ) {
       def skip_names = ''
       def skip_dirs = ''
       def result = ''
@@ -385,12 +385,17 @@
           }
         }
       }
-      result = "if [ -f ${scenarios_path} ]; then cp ${scenarios_path} ${bundle_file}; " +
+      if (bundle_file != '') {
+        result = "if [ -f ${scenarios_path} ]; then cp ${scenarios_path} ${bundle_file}; " +
           "else " +
           "find -L ${scenarios_path} " + skip_dirs +
           " -name '*.yaml' " + skip_names +
           "-exec cat {} >> ${bundle_file} \\; ; " +
           "sed -i '/---/d' ${bundle_file}; fi; "
+      } else {
+        result = "find -L ${scenarios_path} " + skip_dirs +
+            " -name '*.yaml' " + skip_names
+      }
 
       return result
 }
@@ -484,20 +489,26 @@
     } else {
       throw new Exception("Platform ${platform} is not supported yet")
     }
-    cmd_rally_checkout += bundle_up_scenarios(scenarios, skip_list, "scenarios_${platform.type}.yaml")
-    cmd_rally_start = "rally $rally_extra_args task start scenarios_${platform.type}.yaml "
-    if (config_repo != '' ) {
-      switch(tasks_args_file) {
-        case 'none':
-          cmd_rally_task_args = '; '
-          break
-        case '':
-          cmd_rally_task_args = '--task-args-file test_config/job-params-light.yaml; '
-          break
-        default:
-          cmd_rally_task_args = "--task-args-file ${tasks_args_file}; "
+    switch(tasks_args_file) {
+      case 'none':
+        cmd_rally_task_args = '; '
         break
-      }
+      case '':
+        cmd_rally_task_args = '--task-args-file test_config/job-params-light.yaml; '
+        break
+      default:
+        cmd_rally_task_args = "--task-args-file ${tasks_args_file}; "
+      break
+    }
+    if (platform['type'] == 'k8s') {
+      cmd_rally_start = "for task in \\\$(" + bundle_up_scenarios(scenarios, skip_list) +
+          "); do " +
+          "rally $rally_extra_args task start \\\$task ${cmd_rally_task_args}" +
+          "done; "
+    } else {
+      cmd_rally_checkout += bundle_up_scenarios(scenarios, skip_list, "scenarios_${platform.type}.yaml")
+      cmd_rally_start = "rally $rally_extra_args task start " +
+          "scenarios_${platform.type}.yaml ${cmd_rally_task_args}"
     }
     cmd_rally_report= "rally task export --uuid \\\$(rally task list --uuids-only --status finished) " +
         "--type junit-xml --to ${dest_folder}/report-rally.xml; " +
@@ -507,7 +518,7 @@
     full_cmd = 'set -xe; ' + cmd_rally_plugins +
         cmd_rally_init + cmd_rally_checkout +
         'set +e; ' + cmd_rally_start +
-        cmd_rally_task_args + cmd_rally_stacklight +
+        cmd_rally_stacklight +
         cmd_rally_report
     salt.runSaltProcessStep(master, target, 'file.touch', ["${results}/rally.db"])
     salt.cmdRun(master, target, "chmod 666 ${results}/rally.db")
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
index c705ca9..7f49db9 100644
--- a/src/com/mirantis/mk/Orchestrate.groovy
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -195,7 +195,7 @@
     // Install galera
     if (salt.testTarget(master, "I@galera:master ${extra_tgt}") || salt.testTarget(master, "I@galera:slave ${extra_tgt}")) {
         salt.enforceState(master, "I@galera:master ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
-        salt.enforceStateWithTest(master, "I@galera:slave ${extra_tgt}", 'galera', true, true, null, false, -1, 2)
+        salt.enforceStateWithTest(master, "I@galera:slave ${extra_tgt}", 'galera', "", true, true, null, false, -1, 2)
 
         // Check galera status
         salt.runSaltProcessStep(master, "I@galera:master ${extra_tgt}", 'mysql.status')
@@ -282,8 +282,6 @@
     def common = new com.mirantis.mk.Common()
     def first_target
 
-    // Install horizon dashboard
-    salt.enforceStateWithTest(master, "I@horizon:server ${extra_tgt}", 'horizon')
     // Install sphinx server
     salt.enforceStateWithTest(master, "I@sphinx:server ${extra_tgt}", 'sphinx')
     salt.enforceStateWithTest(master, "I@nginx:server ${extra_tgt}", 'salt.minion')
@@ -335,7 +333,6 @@
         }
     }
 
-
     // Create nova resources
     salt.enforceStateWithTest(master, "I@nova:client ${extra_tgt}", 'nova.client')
 
@@ -439,6 +436,9 @@
         salt.enforceState(master, "${first_target} ${extra_tgt}", 'aodh')
         salt.enforceState(master, "I@aodh:server ${extra_tgt}", 'aodh')
     }
+
+    // Install horizon dashboard
+    salt.enforceStateWithTest(master, "I@horizon:server ${extra_tgt}", 'horizon')
 }
 
 
@@ -1130,6 +1130,11 @@
         salt.enforceState(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", 'ceph.mon')
         salt.runSaltProcessStep(master, "I@ceph:mon ${extra_tgt}", 'saltutil.sync_grains')
         salt.runSaltProcessStep(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}", 'mine.update')
+
+        // on target nodes mine is used to get pillar from 'ceph:common:keyring:admin' via grain.items
+        // we need to refresh all pillar/grains to make data sharing work correctly
+        salt.fullRefresh(master, "( I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin ) ${extra_tgt}")
+
         sleep(5)
     }
     // install Ceph Mons