Merge "updating the traffic profile to enable static cgnapt for ixnet"
[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         self.pass_flag = True
30
31     def setup(self):
32         self.director = Director(self.scenario_cfg, self.context_cfg)
33
34     def run(self, result):
35         steps = self.scenario_cfg["options"]["steps"]
36         orderedSteps = sorted(steps, key=lambda x: x['index'])
37         for step in orderedSteps:
38             LOG.debug(
39                 "\033[94m running step: %s .... \033[0m",
40                 orderedSteps.index(step) + 1)
41             try:
42                 actionPlayer = self.director.createActionPlayer(
43                     step['actionType'], step['actionKey'],
44                     self.intermediate_variables)
45                 actionPlayer.action()
46                 actionRollbacker = self.director.createActionRollbacker(
47                     step['actionType'], step['actionKey'])
48                 if actionRollbacker:
49                     self.director.executionSteps.append(actionRollbacker)
50             except Exception:
51                 LOG.exception("Exception")
52                 LOG.debug(
53                     "\033[91m exception when running step: %s .... \033[0m",
54                     orderedSteps.index(step))
55                 break
56             finally:
57                 pass
58
59         self.director.stopMonitors()
60
61         verify_result = self.director.verify()
62
63         self.director.store_result(result)
64
65         for k, v in self.director.data.items():
66             if v == 0:
67                 result['sla_pass'] = 0
68                 verify_result = False
69                 self.pass_flag = False
70                 LOG.info(
71                     "\033[92m The service process not found in the host \
72 envrioment, the HA test case NOT pass")
73
74         if verify_result:
75             result['sla_pass'] = 1
76             LOG.info(
77                 "\033[92m Congratulations, "
78                 "the HA test case PASS! \033[0m")
79         else:
80             result['sla_pass'] = 0
81             self.pass_flag = False
82             LOG.info(
83                 "\033[91m Aoh, the HA test case FAIL,"
84                 "please check the detail debug information! \033[0m")
85
86     def teardown(self):
87         self.director.knockoff()
88
89         assert self.pass_flag, "The HA test case NOT passed"