aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
diff options
context:
space:
mode:
authorwym_libra <yimin.wang@huawei.com>2015-12-07 16:02:18 +0800
committerqi liang <liangqi1@huawei.com>2016-01-10 03:17:21 +0000
commit93e5a8fefd2574de339d2f1ae2041b9d233bbc7b (patch)
treeab4a5507c4100cec6485ba9d587aca8728e8d1c7 /tests/unit/benchmark/scenarios/availability/test_basemonitor.py
parent9b792a92f1f0b67159de52f8bd6b94806b35ae7b (diff)
Rewrite the HA test case (2)
idea: refact the Monitor class in old file "monitor.py" with the base class and sub-class. detail: 1) the BaseMonitor is the base class of other monitor 2) each monitor run in independent process 3) there are two monitor("openstack-cmd" and "process") for the first test case 4) MonitorMgr class used to manager monitor process JIRA: YARDSTICK-149 Change-Id: I2eede94481f740812212e6cb673d175b5f543c15 Signed-off-by: wym_libra <yimin.wang@huawei.com> (cherry picked from commit 2733defda816a84d2b9c2e361a5970b9de4923f4)
Diffstat (limited to 'tests/unit/benchmark/scenarios/availability/test_basemonitor.py')
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_basemonitor.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
new file mode 100644
index 000000000..13295273b
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_command
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.monitor import basemonitor
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.BaseMonitor')
+class MonitorMgrTestCase(unittest.TestCase):
+
+ def setUp(self):
+ config = {
+ 'monitor_type': 'openstack-api',
+ }
+
+ self.monitor_configs = []
+ self.monitor_configs.append(config)
+
+ def test__MonitorMgr_setup_successful(self, mock_monitor):
+ instance = basemonitor.MonitorMgr()
+ instance.init_monitors(self.monitor_configs, None)
+ instance.start_monitors()
+ instance.wait_monitors()
+
+ ret = instance.verify_SLA()
+
+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)
+ ins.start_monitor()
+ ins.wait_monitor()
+
+
+ def test__basemonitor_all_successful(self):
+ ins = self.MonitorSimple(self.monitor_cfg, None)
+ ins.setup()
+ ins.run()
+ ins.verify_SLA()
+
+ @mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.multiprocessing')
+ def test__basemonitor_func_false(self, mock_multiprocess):
+ ins = self.MonitorSimple(self.monitor_cfg, None)
+ ins.setup()
+ mock_multiprocess.Event().is_set.return_value = False
+ ins.run()
+ ins.verify_SLA()
+
+ def test__basemonitor_getmonitorcls_successfule(self):
+ cls = None
+ try:
+ cls = basemonitor.BaseMonitor.get_monitor_cls(self.monitor_cfg)
+ except Exception:
+ pass
+ self.assertIsNone(cls)
+