1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
3 # juan_ qiu@tongji.edu.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
12 from yardstick.benchmark.scenarios.availability.attacker import baseattacker
13 from yardstick.benchmark.scenarios.availability.operation import baseoperation
14 from yardstick.benchmark.scenarios.availability.result_checker \
15 import baseresultchecker
16 from yardstick.benchmark.scenarios.availability import ActionType
17 from yardstick.benchmark.scenarios.availability import actionplayers
18 from yardstick.benchmark.scenarios.availability import actionrollbackers
20 LOG = logging.getLogger(__name__)
23 class Director(object):
25 Director is used to direct a test scenaio
26 including the creation of action players, test result verification
27 and rollback of actions.
30 def __init__(self, scenario_cfg, context_cfg):
32 # A stack store Rollbacker that will be called after
33 # all actionplayers finish.
34 self.executionSteps = []
36 self.scenario_cfg = scenario_cfg
37 self.context_cfg = context_cfg
38 nodes = self.context_cfg.get("nodes", None)
40 if "attackers" in self.scenario_cfg["options"]:
41 LOG.debug("start init attackers...")
42 attacker_cfgs = self.scenario_cfg["options"]["attackers"]
43 self.attackerMgr = baseattacker.AttackerMgr()
44 self.attackerMgr.init_attackers(attacker_cfgs, nodes)
46 if "monitors" in self.scenario_cfg["options"]:
47 LOG.debug("start init monitors...")
48 monitor_cfgs = self.scenario_cfg["options"]["monitors"]
49 self.monitorMgr = basemonitor.MonitorMgr()
50 self.monitorMgr.init_monitors(monitor_cfgs, nodes)
52 if "operations" in self.scenario_cfg["options"]:
53 LOG.debug("start init operations...")
54 operation_cfgs = self.scenario_cfg["options"]["operations"]
55 self.operationMgr = baseoperation.OperationMgr()
56 self.operationMgr.init_operations(operation_cfgs, nodes)
57 # setup result checker
58 if "resultCheckers" in self.scenario_cfg["options"]:
59 LOG.debug("start init resultCheckers...")
60 result_check_cfgs = self.scenario_cfg["options"]["resultCheckers"]
61 self.resultCheckerMgr = baseresultchecker.ResultCheckerMgr()
62 self.resultCheckerMgr.init_ResultChecker(result_check_cfgs, nodes)
64 def createActionPlayer(self, type, key):
66 "the type of current action is %s, the key is %s", type, key)
67 if type == ActionType.ATTACKER:
68 return actionplayers.AttackerPlayer(self.attackerMgr[key])
69 if type == ActionType.MONITOR:
70 return actionplayers.MonitorPlayer(self.monitorMgr[key])
71 if type == ActionType.RESULTCHECKER:
72 return actionplayers.ResultCheckerPlayer(
73 self.resultCheckerMgr[key])
74 if type == ActionType.OPERATION:
75 return actionplayers.OperationPlayer(self.operationMgr[key])
76 LOG.debug("something run when creatactionplayer")
78 def createActionRollbacker(self, type, key):
80 "the type of current action is %s, the key is %s", type, key)
81 if type == ActionType.ATTACKER:
82 return actionrollbackers.AttackerRollbacker(self.attackerMgr[key])
83 if type == ActionType.OPERATION:
84 return actionrollbackers.OperationRollbacker(
85 self.operationMgr[key])
86 LOG.debug("no rollbacker created for %s", key)
90 if hasattr(self, 'monitorMgr'):
91 result &= self.monitorMgr.verify_SLA()
92 if hasattr(self, 'resultCheckerMgr'):
93 result &= self.resultCheckerMgr.verify()
95 LOG.debug("monitors are passed")
98 def stopMonitors(self):
99 if "monitors" in self.scenario_cfg["options"]:
100 self.monitorMgr.wait_monitors()
103 LOG.debug("knock off ....")
104 while self.executionSteps:
105 singleStep = self.executionSteps.pop()
106 singleStep.rollback()