aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/availability/actionrollbackers.py
blob: 28c338d60518bbed138ee983906f4c3bd7287be1 (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
##############################################################################
# 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
##############################################################################
from __future__ import absolute_import
import logging

LOG = logging.getLogger(__name__)


class ActionRollbacker(object):
    """
    Abstract the rollback functions of attacker, operation
    and mybe others in future
    """

    def rollback(self):
        pass


class AttackerRollbacker(ActionRollbacker):

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

    def rollback(self):
        LOG.debug(
            "\033[93m recovering attacker %s \033[0m",
            self.underlyingAttacker.key)
        self.underlyingAttacker.recover()


class OperationRollbacker(ActionRollbacker):

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

    def rollback(self):
        LOG.debug(
            "\033[93m rollback operation %s \033[0m",
            self.underlyingOperation.key)
        self.underlyingOperation.rollback()