Merge "Add test case description and task file for TC052"
[yardstick.git] / yardstick / benchmark / scenarios / availability / scenario_general.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 import traceback
11
12 from yardstick.benchmark.scenarios import base
13 from yardstick.benchmark.scenarios.availability.director import Director
14
15 LOG = logging.getLogger(__name__)
16
17
18 class ScenarioGeneral(base.Scenario):
19     """Support orchestrating general HA test scenarios."""
20
21     __scenario_type__ = "GeneralHA"
22
23     def __init__(self, scenario_cfg, context_cfg):
24         LOG.debug(
25             "scenario_cfg:%s context_cfg:%s" % (scenario_cfg, context_cfg))
26         self.scenario_cfg = scenario_cfg
27         self.context_cfg = context_cfg
28
29     def setup(self):
30         self.director = Director(self.scenario_cfg, self.context_cfg)
31
32     def run(self, args):
33         steps = self.scenario_cfg["options"]["steps"]
34         orderedSteps = sorted(steps, key=lambda x: x['index'])
35         for step in orderedSteps:
36             LOG.debug(
37                 "\033[94m running step: {0} .... \033[0m"
38                 .format(orderedSteps.index(step)+1))
39             try:
40                 actionPlayer = self.director.createActionPlayer(
41                     step['actionType'], step['actionKey'])
42                 actionPlayer.action()
43                 actionRollbacker = self.director.createActionRollbacker(
44                     step['actionType'], step['actionKey'])
45                 if actionRollbacker:
46                     self.director.executionSteps.append(actionRollbacker)
47             except Exception, e:
48                 LOG.debug(e.message)
49                 traceback.print_exc()
50                 LOG.debug(
51                     "\033[91m exception when running step: {0} .... \033[0m"
52                     .format(orderedSteps.index(step)))
53                 break
54             finally:
55                 pass
56
57         self.director.stopMonitors()
58         if self.director.verify():
59             LOG.debug(
60                 "\033[92m congratulations, "
61                 "the test cases scenario is pass! \033[0m")
62         else:
63             LOG.debug(
64                 "\033[91m aoh,the test cases scenario failed,"
65                 "please check the detail debug information! \033[0m")
66
67     def teardown(self):
68         self.director.knockoff()