c5e199ba6445fa2460ead7e9a8d3e368071381cd
[yardstick.git] / yardstick / benchmark / scenarios / availability / actionplayers.py
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 ##############################################################################
9
10
11 class ActionPlayer(object):
12     """
13     Abstract the action functions of attacker,
14     monitor, operation, resultchecker and mybe others in future
15     """
16
17     def action(self):
18         pass
19
20
21 class AttackerPlayer(ActionPlayer):
22
23     def __init__(self, attacker):
24         self.underlyingAttacker = attacker
25
26     def action(self):
27         self.underlyingAttacker.inject_fault()
28
29
30 class OperationPlayer(ActionPlayer):
31
32     def __init__(self, operation, intermediate_variables):
33         self.underlyingOperation = operation
34         self.underlyingOperation.intermediate_variables \
35             = intermediate_variables
36
37     def action(self):
38         self.underlyingOperation.run()
39
40
41 class MonitorPlayer(ActionPlayer):
42
43     def __init__(self, monitor):
44         self.underlyingmonitor = monitor
45
46     def action(self):
47         self.underlyingmonitor.start_monitor()
48
49
50 class ResultCheckerPlayer(ActionPlayer):
51
52     def __init__(self, resultChecker):
53         self.underlyingresultChecker = resultChecker
54
55     def action(self):
56         self.underlyingresultChecker.verify()