# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import logging
from yardstick.benchmark.scenarios.availability.monitor import basemonitor
class Director(object):
"""
Director is used to direct a test scenaio
- including the creation of action players, test result verification
+ including the creation of action players, test result verification
and rollback of actions.
"""
# A stack store Rollbacker that will be called after
# all actionplayers finish.
self.executionSteps = []
+ self.data = {}
self.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
nodes = self.context_cfg.get("nodes", None)
# setup attackers
if "attackers" in self.scenario_cfg["options"]:
- LOG.debug("start init attackers...")
+ LOG.debug("Start init attackers...")
attacker_cfgs = self.scenario_cfg["options"]["attackers"]
self.attackerMgr = baseattacker.AttackerMgr()
- self.attackerMgr.init_attackers(attacker_cfgs, nodes)
+ self.data = self.attackerMgr.init_attackers(attacker_cfgs,
+ nodes)
+
# setup monitors
if "monitors" in self.scenario_cfg["options"]:
- LOG.debug("start init monitors...")
+ LOG.debug("Start init monitors...")
monitor_cfgs = self.scenario_cfg["options"]["monitors"]
- self.monitorMgr = basemonitor.MonitorMgr()
+ self.monitorMgr = basemonitor.MonitorMgr(self.data)
self.monitorMgr.init_monitors(monitor_cfgs, nodes)
# setup operations
if "operations" in self.scenario_cfg["options"]:
- LOG.debug("start init operations...")
+ LOG.debug("Start init operations...")
operation_cfgs = self.scenario_cfg["options"]["operations"]
self.operationMgr = baseoperation.OperationMgr()
self.operationMgr.init_operations(operation_cfgs, nodes)
# setup result checker
if "resultCheckers" in self.scenario_cfg["options"]:
- LOG.debug("start init resultCheckers...")
+ LOG.debug("Start init resultCheckers...")
result_check_cfgs = self.scenario_cfg["options"]["resultCheckers"]
self.resultCheckerMgr = baseresultchecker.ResultCheckerMgr()
self.resultCheckerMgr.init_ResultChecker(result_check_cfgs, nodes)
- def createActionPlayer(self, type, key):
+ def createActionPlayer(self, type, key, intermediate_variables=None):
+ if intermediate_variables is None:
+ intermediate_variables = {}
LOG.debug(
- "the type of current action is %s, the key is %s", type, key)
+ "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])
- LOG.debug("something run when creatactionplayer")
+ return actionplayers.OperationPlayer(self.operationMgr[key],
+ intermediate_variables)
+ LOG.debug("The type is not recognized by createActionPlayer")
def createActionRollbacker(self, type, key):
LOG.debug(
- "the type of current action is %s, the key is %s", type, key)
+ "The type of current action is %s, the key is %s", type, key)
if type == ActionType.ATTACKER:
return actionrollbackers.AttackerRollbacker(self.attackerMgr[key])
if type == ActionType.OPERATION:
return actionrollbackers.OperationRollbacker(
self.operationMgr[key])
- LOG.debug("no rollbacker created for %s", key)
+ LOG.debug("No rollbacker created for key: %s", key)
def verify(self):
result = True
if hasattr(self, 'resultCheckerMgr'):
result &= self.resultCheckerMgr.verify()
if result:
- LOG.debug("monitors are passed")
+ LOG.debug("Monitor results are passed")
return result
def stopMonitors(self):
self.monitorMgr.wait_monitors()
def knockoff(self):
- LOG.debug("knock off ....")
+ LOG.debug("Knock off ....")
while self.executionSteps:
singleStep = self.executionSteps.pop()
singleStep.rollback()
+
+ def store_result(self, result):
+ LOG.debug("Store result ....")
+ if hasattr(self, 'monitorMgr'):
+ self.monitorMgr.store_result(result)