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