diff options
author | Emma Foley <emma.l.foley@intel.com> | 2017-11-29 22:56:21 +0000 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-02-12 16:57:56 +0000 |
commit | ba4e9e6e47bd10ecc803bab920178ea973c2fa86 (patch) | |
tree | 54576c199cabe8ccc29d04eedfe0e4f88b2bd598 /yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py | |
parent | babe3cc2882e19c6dafdbf41d502d7ba5560635a (diff) |
Move tests: unit/benchmark
* Fix pylint errors
* Add TODOs
Some errors are ignored locally, as they were a symptom of other problems.
These issues have been flagged with a TODO, and should be fixed later.
Change-Id: I30eb4b0aafe0575d0cddbc946108291f21a98ed8
Jira: YARDSTICK-837
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py')
-rw-r--r-- | yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py new file mode 100644 index 000000000..9bc04ebf4 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py @@ -0,0 +1,119 @@ +############################################################################## +# 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 mock +import unittest + +from yardstick.benchmark.scenarios.availability.monitor import basemonitor + + +class MonitorMgrTestCase(unittest.TestCase): + + def setUp(self): + self.monitor_configs = [ + { + "monitor_type": "openstack-cmd", + "command_name": "openstack router list", + "monitor_time": 10, + "monitor_number": 3, + "sla": { + "max_outage_time": 5 + } + }, + { + "monitor_type": "process", + "process_name": "neutron-server", + "host": "node1", + "monitor_time": 20, + "monitor_number": 3, + "sla": { + "max_recover_time": 20 + } + } + ] + self.MonitorMgr = basemonitor.MonitorMgr([]) + self.MonitorMgr.init_monitors(self.monitor_configs, None) + self.monitor_list = self.MonitorMgr._monitor_list + for mo in self.monitor_list: + mo._result = {"outage_time": 10} + + @mock.patch.object(basemonitor, 'BaseMonitor') + def test__MonitorMgr_setup_successful(self, *args): + instance = basemonitor.MonitorMgr({"nova-api": 10}) + instance.init_monitors(self.monitor_configs, None) + instance.start_monitors() + instance.wait_monitors() + + # TODO(elfoley): Check the return value + ret = instance.verify_SLA() # pylint: disable=unused-variable + + @mock.patch.object(basemonitor, 'BaseMonitor') + def test_MonitorMgr_getitem(self, *args): + monitorMgr = basemonitor.MonitorMgr({"nova-api": 10}) + monitorMgr.init_monitors(self.monitor_configs, None) + + @mock.patch.object(basemonitor, 'BaseMonitor') + def test_store_result(self, *args): + expect = {'process_neutron-server_outage_time': 10, + 'openstack-router-list_outage_time': 10} + result = {} + self.MonitorMgr.store_result(result) + self.assertDictEqual(result, expect) + + +class BaseMonitorTestCase(unittest.TestCase): + + class MonitorSimple(basemonitor.BaseMonitor): + __monitor_type__ = "MonitorForTest" + + def setup(self): + self.monitor_result = False + + def monitor_func(self): + return self.monitor_result + + def setUp(self): + self.monitor_cfg = { + 'monitor_type': 'MonitorForTest', + 'command_name': 'nova image-list', + 'monitor_time': 0.01, + 'sla': {'max_outage_time': 5} + } + + def test__basemonitor_start_wait_successful(self): + ins = basemonitor.BaseMonitor(self.monitor_cfg, None, {"nova-api": 10}) + ins.start_monitor() + ins.wait_monitor() + + def test__basemonitor_all_successful(self): + ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10}) + ins.setup() + ins.run() + ins.verify_SLA() + + @mock.patch.object(basemonitor, 'multiprocessing') + def test__basemonitor_func_false(self, mock_multiprocess): + ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10}) + ins.setup() + mock_multiprocess.Event().is_set.return_value = False + ins.run() + ins.verify_SLA() + + # TODO(elfoley): fix this test to not throw an error + def test__basemonitor_getmonitorcls_successfule(self): + cls = None + try: + cls = basemonitor.BaseMonitor.get_monitor_cls(self.monitor_cfg) + except Exception: # pylint: disable=broad-except + pass + self.assertIsNone(cls) + + +if __name__ == "__main__": + unittest.main() |