Merge "add support for suite to support constraints and task_args"
[yardstick.git] / yardstick / benchmark / scenarios / availability / actionrollbackers.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 import logging
10
11 LOG = logging.getLogger(__name__)
12
13
14 class ActionRollbacker(object):
15     """
16     Abstract the rollback functions of attacker, operation
17     and mybe others in future
18     """
19
20     def rollback(self):
21         pass
22
23
24 class AttackerRollbacker(ActionRollbacker):
25
26     def __init__(self, attacker):
27         self.underlyingAttacker = attacker
28
29     def rollback(self):
30         LOG.debug(
31             "\033[93m recovering attacker %s \033[0m"
32             % (self.underlyingAttacker.key))
33         self.underlyingAttacker.recover()
34
35
36 class OperationRollbacker(ActionRollbacker):
37
38     def __init__(self, operation):
39         self.underlyingOperation = operation
40
41     def rollback(self):
42         LOG.debug(
43             "\033[93m rollback operation %s \033[0m"
44             % (self.underlyingOperation.key))
45         self.underlyingOperation.rollback()