1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
import time
from yardstick.benchmark.scenarios import base
from yardstick.benchmark.scenarios.availability import monitor
from yardstick.benchmark.scenarios.availability.attacker import baseattacker
LOG = logging.getLogger(__name__)
class ServiceHA(base.Scenario):
"""TODO: docstring of ServiceHA
"""
__scenario_type__ = "ServiceHA"
def __init__(self, scenario_cfg, context_cfg):
LOG.debug(
"scenario_cfg:%s context_cfg:%s" %
(scenario_cfg, context_cfg))
self.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
self.setup_done = False
def setup(self):
'''scenario setup'''
nodes = self.context_cfg.get("nodes", None)
if nodes is None:
LOG.error("the nodes info is none")
return
self.attackers = []
attacker_cfgs = self.scenario_cfg["options"]["attackers"]
for attacker_cfg in attacker_cfgs:
attacker_cls = baseattacker.BaseAttacker.get_attacker_cls(
attacker_cfg)
attacker_ins = attacker_cls(attacker_cfg, nodes)
attacker_ins.setup()
self.attackers.append(attacker_ins)
monitor_cfgs = self.scenario_cfg["options"]["monitors"]
self.monitor_ins = monitor.Monitor()
self.monitor_ins.setup(monitor_cfgs[0])
self.monitor_ins.monitor_time = monitor_cfgs[0]["monitor_time"]
self.setup_done = True
def run(self, result):
"""execute the benchmark"""
if not self.setup_done:
LOG.error("The setup not finished!")
return
self.monitor_ins.start()
LOG.info("monitor start!")
for attacker in self.attackers:
attacker.inject_fault()
time.sleep(self.monitor_ins.monitor_time)
self.monitor_ins.stop()
LOG.info("monitor stop!")
ret = self.monitor_ins.get_result()
LOG.info("The monitor result:%s" % ret)
outage_time = ret.get("outage_time")
result["outage_time"] = outage_time
LOG.info("the result:%s" % result)
if "sla" in self.scenario_cfg:
sla_outage_time = int(self.scenario_cfg["sla"]["outage_time"])
assert outage_time <= sla_outage_time, "outage_time %f > sla:outage_time(%f)" % \
(outage_time, sla_outage_time)
return
def teardown(self):
'''scenario teardown'''
for attacker in self.attackers:
if not attacker.check():
attacker.recover()
def _test(): # pragma: no cover
'''internal test function'''
host = {
"ip": "10.20.0.5",
"user": "root",
"key_filename": "/root/.ssh/id_rsa"
}
ctx = {"nodes": {"node1": host}}
attacker_cfg = {
"fault_type": "kill-process",
"process_name": "nova-api",
"host": "node1"
}
attacker_cfgs = []
attacker_cfgs.append(attacker_cfg)
monitor_cfg = {
"monitor_cmd": "nova image-list",
"monitor_tme": 10
}
monitor_cfgs = []
monitor_cfgs.append(monitor_cfg)
options = {
"attackers": attacker_cfgs,
"monitors": monitor_cfgs
}
sla = {"outage_time": 5}
args = {"options": options, "sla": sla}
print "create instance"
terstInstance = ServiceHA(args, ctx)
terstInstance.setup()
result = {}
terstInstance.run(result)
print result
terstInstance.teardown()
if __name__ == '__main__': # pragma: no cover
_test()
|