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 ##############################################################################
13 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
16 class MonitorMgrTestCase(unittest.TestCase):
19 self.monitor_configs = [
21 "monitor_type": "openstack-cmd",
22 "command_name": "openstack router list",
30 "monitor_type": "process",
31 "process_name": "neutron-server",
36 "max_recover_time": 20
40 self.MonitorMgr = basemonitor.MonitorMgr([])
41 self.MonitorMgr.init_monitors(self.monitor_configs, None)
42 self.monitor_list = self.MonitorMgr._monitor_list
43 for mo in self.monitor_list:
44 mo._result = {"outage_time": 10}
46 @mock.patch.object(basemonitor, 'BaseMonitor')
47 def test__MonitorMgr_setup_successful(self, *args):
48 instance = basemonitor.MonitorMgr({"nova-api": 10})
49 instance.init_monitors(self.monitor_configs, None)
50 instance.start_monitors()
51 instance.wait_monitors()
53 # TODO(elfoley): Check the return value
54 ret = instance.verify_SLA() # pylint: disable=unused-variable
56 @mock.patch.object(basemonitor, 'BaseMonitor')
57 def test_MonitorMgr_getitem(self, *args):
58 monitorMgr = basemonitor.MonitorMgr({"nova-api": 10})
59 monitorMgr.init_monitors(self.monitor_configs, None)
61 @mock.patch.object(basemonitor, 'BaseMonitor')
62 def test_store_result(self, *args):
63 expect = {'process_neutron-server_outage_time': 10,
64 'openstack-router-list_outage_time': 10}
66 self.MonitorMgr.store_result(result)
67 self.assertDictEqual(result, expect)
70 class BaseMonitorTestCase(unittest.TestCase):
72 class MonitorSimple(basemonitor.BaseMonitor):
73 __monitor_type__ = "MonitorForTest"
76 self.monitor_result = False
78 def monitor_func(self):
79 return self.monitor_result
83 'monitor_type': 'MonitorForTest',
84 'command_name': 'nova image-list',
86 'sla': {'max_outage_time': 5}
89 def test__basemonitor_start_wait_successful(self):
90 ins = basemonitor.BaseMonitor(self.monitor_cfg, None, {"nova-api": 10})
94 def test__basemonitor_all_successful(self):
95 ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10})
100 @mock.patch.object(basemonitor, 'multiprocessing')
101 def test__basemonitor_func_false(self, mock_multiprocess):
102 ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10})
104 mock_multiprocess.Event().is_set.return_value = False
108 # TODO(elfoley): fix this test to not throw an error
109 def test__basemonitor_getmonitorcls_successfule(self):
112 cls = basemonitor.BaseMonitor.get_monitor_cls(self.monitor_cfg)
113 except Exception: # pylint: disable=broad-except
115 self.assertIsNone(cls)