Add intermediate variables for attacker,monitor,result_checker 25/44425/1
authorqiujuan <juan_qiu@tongji.edu.cn>
Sun, 3 Sep 2017 04:31:13 +0000 (12:31 +0800)
committerRoss Brattain <ross.b.brattain@intel.com>
Fri, 6 Oct 2017 09:05:46 +0000 (02:05 -0700)
JIRA: YARDSTICK-790

Change-Id: I6bb36c98b8673155d3142fc54cfb39315d5ce613
Signed-off-by: qiujuan <juan_qiu@tongji.edu.cn>
12 files changed:
tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml
tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml
tests/unit/benchmark/scenarios/availability/test_util.py
yardstick/benchmark/scenarios/availability/actionplayers.py
yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
yardstick/benchmark/scenarios/availability/attacker/baseattacker.py
yardstick/benchmark/scenarios/availability/director.py
yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py
yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
yardstick/benchmark/scenarios/availability/util.py

index 322e2bd..28aa0b6 100644 (file)
@@ -81,7 +81,7 @@ scenarios:
           action_parameter:
             vip_name: {{vip_mgmt}}
           return_parameter:
-            all: "$vip_mgmt_host"
+            all: "@vip_mgmt_host"
 
         -
           operation_type: "general-operation"
@@ -91,7 +91,7 @@ scenarios:
           action_parameter:
             vip_name: {{vip_vrouter}}
           return_parameter:
-            all: "$vip_router_host"
+            all: "@vip_router_host"
 
       resultCheckers:
         -
@@ -101,7 +101,7 @@ scenarios:
           host: {{check_host}}
           parameter:
             resource_name: "p_rabbitmq-server"
-            resource_host: "$vip_mgmt_host"
+            resource_host: "@vip_mgmt_host"
           expectedValue: "Masters"
           condition: "in"
 
@@ -112,7 +112,7 @@ scenarios:
           host: {{check_host}}
           parameter:
             resource_name: "p_conntrackd"
-            resource_host: "$vip_router_host"
+            resource_host: "@vip_router_host"
           expectedValue: "Masters"
           condition: "in"
 
index dc0675b..7fb7daf 100644 (file)
@@ -48,7 +48,7 @@ scenarios:
           sla:
             max_outage_time: 5
           parameter:
-            ip_address: "$floating_ip"
+            ip_address: "@floating_ip"
 
       operations:
         -
@@ -58,7 +58,7 @@ scenarios:
           action_parameter:
             server_name: "tc058"
           return_parameter:
-            all: "$floating_ip"
+            all: "@floating_ip"
 
 
       steps:
index 2e4fff4..0974f38 100644 (file)
@@ -20,8 +20,8 @@ from yardstick.benchmark.scenarios.availability import util
 class ExecuteShellTestCase(unittest.TestCase):
 
     def setUp(self):
-        self.param_config = {'serviceName': '$serviceName', 'value': 1}
-        self.intermediate_variables = {'$serviceName': 'nova-api'}
+        self.param_config = {'serviceName': '@serviceName', 'value': 1}
+        self.intermediate_variables = {'@serviceName': 'nova-api'}
         self.std_output = '| id       | 1                     |'
         self.cmd_config = {'cmd':'ls','param':'-a'}
 
index c5e199b..d5a531e 100644 (file)
@@ -20,8 +20,10 @@ class ActionPlayer(object):
 
 class AttackerPlayer(ActionPlayer):
 
-    def __init__(self, attacker):
+    def __init__(self, attacker, intermediate_variables):
         self.underlyingAttacker = attacker
+        self.underlyingAttacker.intermediate_variables \
+            = intermediate_variables
 
     def action(self):
         self.underlyingAttacker.inject_fault()
@@ -40,8 +42,10 @@ class OperationPlayer(ActionPlayer):
 
 class MonitorPlayer(ActionPlayer):
 
-    def __init__(self, monitor):
+    def __init__(self, monitor, intermediate_variables):
         self.underlyingmonitor = monitor
+        self.underlyingmonitor.intermediate_variables \
+            = intermediate_variables
 
     def action(self):
         self.underlyingmonitor.start_monitor()
@@ -49,8 +53,10 @@ class MonitorPlayer(ActionPlayer):
 
 class ResultCheckerPlayer(ActionPlayer):
 
-    def __init__(self, resultChecker):
+    def __init__(self, resultChecker, intermediate_variables):
         self.underlyingresultChecker = resultChecker
+        self.underlyingresultChecker.intermediate_variables \
+            = intermediate_variables
 
     def action(self):
         self.underlyingresultChecker.verify()
index 48863af..11b02a2 100644 (file)
@@ -13,6 +13,8 @@ import yardstick.ssh as ssh
 from yardstick.benchmark.scenarios.availability import util
 from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \
     BaseAttacker
+from yardstick.benchmark.scenarios.availability.util \
+    import read_stdout_item, build_shell_command
 
 LOG = logging.getLogger(__name__)
 
@@ -33,13 +35,7 @@ class GeneralAttacker(BaseAttacker):
         self.attack_key = self._config['attack_key']
 
         if "action_parameter" in self._config:
-            actionParameter = self._config['action_parameter']
-            str = util.buildshellparams(actionParameter)
-            LOG.debug("inject parameter is: %s", actionParameter)
-            LOG.debug("inject parameter values are: %s",
-                      list(actionParameter.values()))
-            l = list(actionParameter.values())
-            self.action_param = str.format(*l)
+            self.actionParameter_config = self._config['action_parameter']
 
         if "rollback_parameter" in self._config:
             rollbackParameter = self._config['rollback_parameter']
@@ -59,8 +55,12 @@ class GeneralAttacker(BaseAttacker):
     def inject_fault(self):
         LOG.debug("%s starting inject!", self.key)
         LOG.debug("the inject_script path:%s", self.inject_script)
-
         if "action_parameter" in self._config:
+            self.action_param = \
+                build_shell_command(
+                    self.actionParameter_config,
+                    bool(self.connection),
+                    self.intermediate_variables)
             LOG.debug("the shell command is: %s", self.action_param)
             with open(self.inject_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
@@ -75,6 +75,12 @@ class GeneralAttacker(BaseAttacker):
         LOG.debug("the inject_fault's exit status is: %s", exit_status)
         if exit_status == 0:
             LOG.debug("success,the inject_fault's output is: %s", stdout)
+            if "return_parameter" in self._config:
+                returnParameter = self._config['return_parameter']
+                for key, item in returnParameter.items():
+                    value = read_stdout_item(stdout, key)
+                    LOG.debug("intermediate variables %s: %s", item, value)
+                    self.intermediate_variables[item] = value
         else:
             LOG.error(
                 "the inject_fault's error, stdout:%s, stderr:%s",
index 61698da..d03d044 100644 (file)
@@ -62,6 +62,7 @@ class BaseAttacker(object):
         self._context = context
         self.data = {}
         self.setup_done = False
+        self.intermediate_variables = {}
 
     @staticmethod
     def get_attacker_cls(attacker_cfg):
index f152af0..71690c1 100644 (file)
@@ -71,12 +71,12 @@ class Director(object):
         LOG.debug(
             "the type of current action is %s, the key is %s", type, key)
         if type == ActionType.ATTACKER:
-            return actionplayers.AttackerPlayer(self.attackerMgr[key])
+            return actionplayers.AttackerPlayer(self.attackerMgr[key], intermediate_variables)
         if type == ActionType.MONITOR:
-            return actionplayers.MonitorPlayer(self.monitorMgr[key])
+            return actionplayers.MonitorPlayer(self.monitorMgr[key], intermediate_variables)
         if type == ActionType.RESULTCHECKER:
             return actionplayers.ResultCheckerPlayer(
-                self.resultCheckerMgr[key])
+                self.resultCheckerMgr[key], intermediate_variables)
         if type == ActionType.OPERATION:
             return actionplayers.OperationPlayer(self.operationMgr[key],
                                                  intermediate_variables)
index a6c1a28..50a63f5 100644 (file)
@@ -94,6 +94,7 @@ class BaseMonitor(multiprocessing.Process):
         self.monitor_data = data
         self.setup_done = False
         self.tag = ""
+        self.intermediate_variables = {}
 
     @staticmethod
     def get_monitor_cls(monitor_type):
index c16765f..b058ae2 100644 (file)
@@ -11,8 +11,8 @@ import logging
 import yardstick.ssh as ssh
 
 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
-from yardstick.benchmark.scenarios.availability.util import buildshellparams
-
+from yardstick.benchmark.scenarios.availability.util \
+    import build_shell_command, execute_shell_command
 
 LOG = logging.getLogger(__name__)
 
@@ -23,37 +23,41 @@ class GeneralMonitor(basemonitor.BaseMonitor):
     __monitor_type__ = "general-monitor"
 
     def setup(self):
-        host = self._context[self._config["host"]]
+        host = self._context.get(self._config.get('host', None), None)
+        self.connection = None
+        if host:
+            self.connection = ssh.SSH.from_node(
+                host, defaults={"user": "root"})
+            self.connection.wait(timeout=600)
+            LOG.debug("ssh host success!")
         self.key = self._config["key"]
         self.monitor_key = self._config["monitor_key"]
         self.monitor_type = self._config["monitor_type"]
-
         if "parameter" in self._config:
-            parameter = self._config['parameter']
-            str = buildshellparams(parameter)
-            l = list(item for item in parameter.values())
-            self.cmd_param = str.format(*l)
-
+            self.parameter_config = self._config['parameter']
         self.monitor_cfg = basemonitor.BaseMonitor.monitor_cfgs.get(
             self.monitor_key)
         self.monitor_script = self.get_script_fullpath(
             self.monitor_cfg['monitor_script'])
-        self.connection = ssh.SSH.from_node(host, defaults={"user": "root"})
-        self.connection.wait(timeout=600)
         LOG.debug("ssh host success!")
 
     def monitor_func(self):
         if "parameter" in self._config:
-            with open(self.monitor_script, "r") as stdin_file:
-                exit_status, stdout, stderr = self.connection.execute(
-                    "sudo {}".format(self.cmd_param),
-                    stdin=stdin_file)
+            self.cmd_param = \
+                build_shell_command(
+                    self.parameter_config,
+                    bool(self.connection),
+                    self.intermediate_variables)
+            cmd_remote = "sudo {}".format(self.cmd_param)
+            cmd_local = "/bin/bash {0} {1}".format(self.monitor_script, self.cmd_param)
         else:
+            cmd_remote = "sudo /bin/sh -s "
+            cmd_local = "/bin/bash {0}".format(self.monitor_script)
+        if self.connection:
             with open(self.monitor_script, "r") as stdin_file:
-                exit_status, stdout, stderr = self.connection.execute(
-                    "sudo /bin/bash -s ",
-                    stdin=stdin_file)
-
+                exit_status, stdout, stderr = self.connection.execute(cmd_remote, stdin=stdin_file)
+        else:
+            exit_status, stdout = execute_shell_command(cmd_local)
         if exit_status:
             return False
         return True
index 05b6601..d1750ab 100644 (file)
@@ -66,6 +66,7 @@ class BaseResultChecker(object):
         self._config = config
         self._context = context
         self.setup_done = False
+        self.intermediate_variables = {}
 
     @staticmethod
     def get_resultchecker_cls(type):
index 4543381..0802aa4 100644 (file)
@@ -15,7 +15,7 @@ from yardstick.benchmark.scenarios.availability.result_checker \
 from yardstick.benchmark.scenarios.availability import Condition
 import yardstick.ssh as ssh
 from yardstick.benchmark.scenarios.availability.util \
-    import buildshellparams, execute_shell_command
+    import execute_shell_command, build_shell_command
 
 LOG = logging.getLogger(__name__)
 
@@ -40,22 +40,20 @@ class GeneralResultChecker(BaseResultChecker):
         self.condition = self._config['condition']
         self.expectedResult = self._config['expectedValue']
         self.actualResult = object()
-
         self.key = self._config['key']
         if "parameter" in self._config:
-            parameter = self._config['parameter']
-            str = buildshellparams(
-                parameter, True if self.connection else False)
-            l = list(item for item in parameter.values())
-            self.shell_cmd = str.format(*l)
-
-        self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
-            self.resultchecker_key)
+            self.parameter_config = self._config['parameter']
+        self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(self.resultchecker_key)
         self.verify_script = self.get_script_fullpath(
             self.resultchecker_cfgs['verify_script'])
 
     def verify(self):
         if "parameter" in self._config:
+            self.shell_cmd = \
+                build_shell_command(
+                    self.parameter_config,
+                    bool(self.connection),
+                    self.intermediate_variables)
             if self.connection:
                 with open(self.verify_script, "r") as stdin_file:
                     exit_status, stdout, stderr = self.connection.execute(
index d288fcb..adc20b8 100644 (file)
@@ -33,7 +33,7 @@ def execute_shell_command(command):
         LOG.error(traceback.format_exc())
     return exitcode, output
 
-PREFIX = '$'
+PREFIX = '@'
 
 
 def build_shell_command(param_config, remote=True, intermediate_variables=None):