summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqiujuan <juan_qiu@tongji.edu.cn>2017-09-03 12:31:13 +0800
committerRoss Brattain <ross.b.brattain@intel.com>2017-10-06 02:05:46 -0700
commitb6c7cfb4ffe0c472f2f4a9efc32df59a831b3cc0 (patch)
treef3f972b2a079828bc360323c49cbb65cf0d50f55
parent2674b71734aad447253d8d11e5fb67d5ef93bd56 (diff)
Add intermediate variables for attacker,monitor,result_checker
JIRA: YARDSTICK-790 Change-Id: I6bb36c98b8673155d3142fc54cfb39315d5ce613 Signed-off-by: qiujuan <juan_qiu@tongji.edu.cn>
-rw-r--r--tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml8
-rw-r--r--tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml4
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_util.py4
-rw-r--r--yardstick/benchmark/scenarios/availability/actionplayers.py12
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_general.py22
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/baseattacker.py1
-rw-r--r--yardstick/benchmark/scenarios/availability/director.py6
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/basemonitor.py1
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/monitor_general.py42
-rw-r--r--yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py1
-rw-r--r--yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py18
-rw-r--r--yardstick/benchmark/scenarios/availability/util.py2
12 files changed, 69 insertions, 52 deletions
diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml
index 322e2bd76..28aa0b6bd 100644
--- a/tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml
+++ b/tests/opnfv/test_cases/opnfv_yardstick_tc057.yaml
@@ -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"
diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml
index dc0675bec..7fb7daf62 100644
--- a/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml
+++ b/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml
@@ -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:
diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py
index 2e4fff417..0974f385a 100644
--- a/tests/unit/benchmark/scenarios/availability/test_util.py
+++ b/tests/unit/benchmark/scenarios/availability/test_util.py
@@ -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'}
diff --git a/yardstick/benchmark/scenarios/availability/actionplayers.py b/yardstick/benchmark/scenarios/availability/actionplayers.py
index c5e199ba6..d5a531e8a 100644
--- a/yardstick/benchmark/scenarios/availability/actionplayers.py
+++ b/yardstick/benchmark/scenarios/availability/actionplayers.py
@@ -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()
diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
index 48863af93..11b02a222 100644
--- a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
+++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
@@ -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",
diff --git a/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py b/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py
index 61698da43..d03d04420 100644
--- a/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py
+++ b/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py
@@ -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):
diff --git a/yardstick/benchmark/scenarios/availability/director.py b/yardstick/benchmark/scenarios/availability/director.py
index f152af090..71690c135 100644
--- a/yardstick/benchmark/scenarios/availability/director.py
+++ b/yardstick/benchmark/scenarios/availability/director.py
@@ -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)
diff --git a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
index a6c1a28bd..50a63f53d 100644
--- a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
+++ b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
@@ -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):
diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
index c16765fe0..b058ae2b1 100644
--- a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
+++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
@@ -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
diff --git a/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py b/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py
index 05b660105..d1750ab65 100644
--- a/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py
+++ b/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py
@@ -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):
diff --git a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
index 454338175..0802aa452 100644
--- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
+++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
@@ -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(
diff --git a/yardstick/benchmark/scenarios/availability/util.py b/yardstick/benchmark/scenarios/availability/util.py
index d288fcbc1..adc20b844 100644
--- a/yardstick/benchmark/scenarios/availability/util.py
+++ b/yardstick/benchmark/scenarios/availability/util.py
@@ -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):