Fix log typos in benchmark/scenarios/availability
[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 from __future__ import absolute_import
10 import logging
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         self.intermediate_variables = {}
29
30     def setup(self):
31         self.director = Director(self.scenario_cfg, self.context_cfg)
32
33     def run(self, result):
34         steps = self.scenario_cfg["options"]["steps"]
35         orderedSteps = sorted(steps, key=lambda x: x['index'])
36         for step in orderedSteps:
37             LOG.debug(
38                 "\033[94m running step: %s .... \033[0m",
39                 orderedSteps.index(step) + 1)
40             try:
41                 actionPlayer = self.director.createActionPlayer(
42                     step['actionType'], step['actionKey'],
43                     self.intermediate_variables)
44                 actionPlayer.action()
45                 actionRollbacker = self.director.createActionRollbacker(
46                     step['actionType'], step['actionKey'])
47                 if actionRollbacker:
48                     self.director.executionSteps.append(actionRollbacker)
49             except Exception:  # pylint: disable=broad-except
50                 LOG.exception("Exception")
51                 LOG.debug(
52                     "\033[91m exception when running step: %s .... \033[0m",
53                     orderedSteps.index(step))
54                 break
55             finally:
56                 pass
57
58         self.director.stopMonitors()
59
60         verify_result = self.director.verify()
61         for k, v in self.director.data.items():
62             if v == 0:
63                 result['sla_pass'] = 0
64                 verify_result = False
65                 LOG.info("\033[92m The service process (%s) not found in the host environment", k)
66
67         result['sla_pass'] = 1 if verify_result else 0
68         self.director.store_result(result)
69
70         assert verify_result is True, "The HA test case NOT passed"
71
72     def teardown(self):
73         self.director.knockoff()