1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
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 print_function
10 from __future__ import absolute_import
12 from yardstick.benchmark.scenarios import base
13 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
14 from yardstick.benchmark.scenarios.availability.attacker import baseattacker
16 LOG = logging.getLogger(__name__)
19 class ServiceHA(base.Scenario):
20 """TODO: docstring of ServiceHA
22 __scenario_type__ = "ServiceHA"
24 def __init__(self, scenario_cfg, context_cfg):
26 "scenario_cfg:%s context_cfg:%s",
27 scenario_cfg, context_cfg)
28 self.scenario_cfg = scenario_cfg
29 self.context_cfg = context_cfg
30 self.setup_done = False
36 nodes = self.context_cfg.get("nodes", None)
38 LOG.error("the nodes info is none")
42 attacker_cfgs = self.scenario_cfg["options"]["attackers"]
43 for attacker_cfg in attacker_cfgs:
44 attacker_cls = baseattacker.BaseAttacker.get_attacker_cls(
46 attacker_ins = attacker_cls(attacker_cfg, nodes)
48 self.attackers.append(attacker_ins)
49 self.data = dict(self.data.items() + attacker_ins.data.items())
51 monitor_cfgs = self.scenario_cfg["options"]["monitors"]
53 self.monitorMgr = basemonitor.MonitorMgr(self.data)
54 self.monitorMgr.init_monitors(monitor_cfgs, nodes)
56 self.setup_done = True
58 def run(self, result):
59 """execute the benchmark"""
60 if not self.setup_done:
61 LOG.error("The setup not finished!")
64 self.monitorMgr.start_monitors()
65 LOG.info("HA monitor start!")
67 for attacker in self.attackers:
68 attacker.inject_fault()
70 self.monitorMgr.wait_monitors()
71 LOG.info("HA monitor stop!")
73 sla_pass = self.monitorMgr.verify_SLA()
74 for k, v in self.data.items():
76 result['sla_pass'] = 0
77 self.pass_flag = False
78 LOG.info("The service process not found in the host envrioment, \
79 the HA test case NOT pass")
81 self.monitorMgr.store_result(result)
83 result['sla_pass'] = 1
84 LOG.info("The HA test case PASS the SLA")
86 result['sla_pass'] = 0
87 self.pass_flag = False
88 assert sla_pass is True, "The HA test case NOT pass the SLA"
93 """scenario teardown"""
94 for attacker in self.attackers:
97 assert self.pass_flag, "The HA test case NOT passed"
100 def _test(): # pragma: no cover
101 """internal test function"""
105 "key_filename": "/root/.ssh/id_rsa"
107 ctx = {"nodes": {"node1": host}}
109 "fault_type": "kill-process",
110 "process_name": "nova-api",
114 attacker_cfgs.append(attacker_cfg)
116 "monitor_cmd": "nova image-list"
119 monitor_cfgs.append(monitor_cfg)
122 "attackers": attacker_cfgs,
124 "monitors": monitor_cfgs
126 sla = {"outage_time": 5}
127 args = {"options": options, "sla": sla}
129 print("create instance")
130 terstInstance = ServiceHA(args, ctx)
132 terstInstance.setup()
134 terstInstance.run(result)
137 terstInstance.teardown()
140 if __name__ == '__main__': # pragma: no cover