aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/availability/actionplayers.py
blob: d5a531e8a578ca776c5099a67c0c2b50d66a799d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
##############################################################################
# Copyright (c) 2016 Juan Qiu and others
# juan_ qiu@tongji.edu.cn
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################


class ActionPlayer(object):
    """
    Abstract the action functions of attacker,
    monitor, operation, resultchecker and mybe others in future
    """

    def action(self):
        pass


class AttackerPlayer(ActionPlayer):

    def __init__(self, attacker, intermediate_variables):
        self.underlyingAttacker = attacker
        self.underlyingAttacker.intermediate_variables \
            = intermediate_variables

    def action(self):
        self.underlyingAttacker.inject_fault()


class OperationPlayer(ActionPlayer):

    def __init__(self, operation, intermediate_variables):
        self.underlyingOperation = operation
        self.underlyingOperation.intermediate_variables \
            = intermediate_variables

    def action(self):
        self.underlyingOperation.run()


class MonitorPlayer(ActionPlayer):

    def __init__(self, monitor, intermediate_variables):
        self.underlyingmonitor = monitor
        self.underlyingmonitor.intermediate_variables \
            = intermediate_variables

    def action(self):
        self.underlyingmonitor.start_monitor()


class ResultCheckerPlayer(ActionPlayer):

    def __init__(self, resultChecker, intermediate_variables):
        self.underlyingresultChecker = resultChecker
        self.underlyingresultChecker.intermediate_variables \
            = intermediate_variables

    def action(self):
        self.underlyingresultChecker.verify()