Merge "Add host&targer in scenario['options']['server_name'] support"
[yardstick.git] / yardstick / benchmark / scenarios / availability / util.py
index eadbfa5..d288fcb 100644 (file)
@@ -14,13 +14,8 @@ LOG = logging.getLogger(__name__)
 
 
 def buildshellparams(param, remote=True):
-    i = 0
-    values = []
     result = '/bin/bash -s' if remote else ''
-    for key in param.keys():
-        values.append(param[key])
-        result += " {%d}" % i
-        i = i + 1
+    result += "".join(" {%d}" % i for i in range(len(param)))
     return result
 
 
@@ -36,5 +31,31 @@ def execute_shell_command(command):
         output = traceback.format_exc()
         LOG.error("exec command '%s' error:\n ", command)
         LOG.error(traceback.format_exc())
-
     return exitcode, output
+
+PREFIX = '$'
+
+
+def build_shell_command(param_config, remote=True, intermediate_variables=None):
+    param_template = '/bin/bash -s' if remote else ''
+    if intermediate_variables:
+        for key, val in param_config.items():
+            if str(val).startswith(PREFIX):
+                try:
+                    param_config[key] = intermediate_variables[val]
+                except KeyError:
+                    pass
+    result = param_template + "".join(" {}".format(v) for v in param_config.values())
+    LOG.debug("THE RESULT OF build_shell_command IS: %s", result)
+    return result
+
+
+def read_stdout_item(stdout, key):
+    if key == "all":
+        return stdout
+    for item in stdout.splitlines():
+        if key in item:
+            attributes = item.split("|")
+            if attributes[1].lstrip().startswith(key):
+                return attributes[2].strip()
+    return None