Document for Euphrates test case results
[yardstick.git] / yardstick / benchmark / scenarios / availability / monitor / monitor_multi.py
1 ##############################################################################
2 # Copyright (c) 2017 Huan Li and others
3 # lihuansse@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
10 from __future__ import absolute_import
11 import logging
12 import time
13
14 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
15
16 LOG = logging.getLogger(__name__)
17
18
19 class MultiMonitor(basemonitor.BaseMonitor):
20
21     __monitor_type__ = "multi-monitor"
22
23     def __init__(self, config, context, data):
24         super(MultiMonitor, self).__init__(config, context, data)
25
26         self.monitors = []
27         self.monitor_data = data
28         monitor_type = self._config["monitor_type"]
29         monitor_cls = basemonitor.BaseMonitor.get_monitor_cls(monitor_type)
30
31         monitor_number = self._config.get("monitor_number", 1)
32         for i in range(monitor_number):
33             monitor_ins = monitor_cls(self._config, self._context,
34                                       self.monitor_data)
35             self.monitors.append(monitor_ins)
36
37     def start_monitor(self):
38         for monitor in self.monitors:
39             monitor.start_monitor()
40
41     def wait_monitor(self):
42         for monitor in self.monitors:
43             monitor.wait_monitor()
44
45     def verify_SLA(self):
46         first_outage = time.time()
47         last_outage = 0
48
49         for monitor in self.monitors:
50             monitor_result = monitor.get_result()
51             monitor_first_outage = monitor_result.get('first_outage', 0)
52             monitor_last_outage = monitor_result.get('last_outage', 0)
53
54             if monitor_first_outage == 0 or monitor_last_outage == 0:
55                 continue
56
57             if monitor_first_outage < first_outage:
58                 first_outage = monitor_first_outage
59
60             if monitor_last_outage > last_outage:
61                 last_outage = monitor_last_outage
62         outage_time = (
63             last_outage - first_outage if last_outage > first_outage else 0
64         )
65         LOG.debug("outage_time is: %f", outage_time)
66
67         max_outage_time = 0
68         if "max_outage_time" in self._config["sla"]:
69             max_outage_time = self._config["sla"]["max_outage_time"]
70         elif "max_recover_time" in self._config["sla"]:
71             max_outage_time = self._config["sla"]["max_recover_time"]
72         else:
73             raise RuntimeError("monitor max_outage_time config is not found")
74         self._result = {"outage_time": outage_time}
75
76         if outage_time > max_outage_time:
77             LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)
78             return False
79         else:
80             return True