aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark')
-rw-r--r--tests/unit/benchmark/contexts/test_kubernetes.py7
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_basemonitor.py45
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_create_keypair.py11
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py25
4 files changed, 63 insertions, 25 deletions
diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py
index b0ee792db..4976a9fe0 100644
--- a/tests/unit/benchmark/contexts/test_kubernetes.py
+++ b/tests/unit/benchmark/contexts/test_kubernetes.py
@@ -81,9 +81,14 @@ class KubernetesTestCase(unittest.TestCase):
self.assertTrue(mock_get_rc_pods.called)
self.assertTrue(mock_wait_until_running.called)
+ @mock.patch('{}.paramiko'.format(prefix), **{"resource_filename.return_value": ""})
+ @mock.patch('{}.pkg_resources'.format(prefix), **{"resource_filename.return_value": ""})
+ @mock.patch('{}.utils'.format(prefix))
+ @mock.patch('{}.open'.format(prefix), create=True)
@mock.patch('{}.k8s_utils.delete_config_map'.format(prefix))
@mock.patch('{}.k8s_utils.create_config_map'.format(prefix))
- def test_ssh_key(self, mock_create, mock_delete):
+ def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils, mock_resources,
+ mock_paramiko):
k8s_context = KubernetesContext()
k8s_context.init(context_cfg)
diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
index 3b7e07376..92ae8aa88 100644
--- a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
+++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -25,13 +25,32 @@ from yardstick.benchmark.scenarios.availability.monitor import basemonitor
class MonitorMgrTestCase(unittest.TestCase):
def setUp(self):
- config = {
- 'monitor_type': 'openstack-api',
- 'key': 'service-status'
- }
-
- self.monitor_configs = []
- self.monitor_configs.append(config)
+ 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}
def test__MonitorMgr_setup_successful(self, mock_monitor):
instance = basemonitor.MonitorMgr({"nova-api": 10})
@@ -44,7 +63,13 @@ class MonitorMgrTestCase(unittest.TestCase):
def test_MonitorMgr_getitem(self, mock_monitor):
monitorMgr = basemonitor.MonitorMgr({"nova-api": 10})
monitorMgr.init_monitors(self.monitor_configs, None)
- monitorIns = monitorMgr['service-status']
+
+ def test_store_result(self, mock_monitor):
+ 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):
@@ -94,3 +119,7 @@ class BaseMonitorTestCase(unittest.TestCase):
except Exception:
pass
self.assertIsNone(cls)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/unit/benchmark/scenarios/lib/test_create_keypair.py b/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
index 99e6b9afa..4b9b72013 100644
--- a/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
+++ b/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
@@ -8,15 +8,16 @@
##############################################################################
import unittest
import mock
-import paramiko
from yardstick.benchmark.scenarios.lib.create_keypair import CreateKeypair
+PREFIX = "yardstick.benchmark.scenarios.lib.create_keypair"
-class CreateKeypairTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.create_keypair')
- def test_create_keypair(self, mock_create_keypair):
+class CreateKeypairTestCase(unittest.TestCase):
+ @mock.patch('{}.paramiko'.format(PREFIX))
+ @mock.patch('{}.op_utils'.format(PREFIX))
+ def test_create_keypair(self, mock_op_utils, mock_paramiko):
options = {
'key_name': 'yardstick_key',
'key_path': '/tmp/yardstick_key'
@@ -24,7 +25,7 @@ class CreateKeypairTestCase(unittest.TestCase):
args = {"options": options}
obj = CreateKeypair(args, {})
obj.run({})
- self.assertTrue(mock_create_keypair.called)
+ self.assertTrue(mock_op_utils.create_keypair.called)
def main():
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
index de5bae2f3..5759f0a90 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
@@ -118,7 +118,8 @@ class VsperfDPDKTestCase(unittest.TestCase):
result = p._is_dpdk_setup()
self.assertEqual(result, True)
- def test_vsperf_dpdk_dpdk_setup_first(self, mock_ssh, mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
+ def test_vsperf_dpdk_dpdk_setup_first(self, mock_time, mock_ssh, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -135,42 +136,43 @@ class VsperfDPDKTestCase(unittest.TestCase):
self.assertEqual(p._is_dpdk_setup(), False)
self.assertEqual(p.dpdk_setup_done, True)
- def test_vsperf_dpdk_dpdk_setup_next(self, mock_ssh, mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
+ def test_vsperf_dpdk_dpdk_setup_next(self, mock_time, mock_ssh, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
self.assertEqual(p.setup_done, True)
- # dpdk_setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
-
p.dpdk_setup()
self.assertEqual(p._is_dpdk_setup(), True)
self.assertEqual(p.dpdk_setup_done, True)
- def test_vsperf_dpdk_dpdk_setup_fail(self, mock_ssh, mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
+ def test_vsperf_dpdk_dpdk_setup_fail(self, mock_time, mock_ssh, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
-
- # dpdk_setup() specific mocks
mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ self.assertEqual(p.setup_done, True)
self.assertRaises(RuntimeError, p.dpdk_setup)
- def test_vsperf_dpdk_run_ok(self, mock_ssh, mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
+ def test_vsperf_dpdk_run_ok(self, mock_time, mock_ssh, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
@@ -179,7 +181,6 @@ class VsperfDPDKTestCase(unittest.TestCase):
# run() specific mocks
mock_subprocess.call().execute.return_value = None
- mock_subprocess.call().execute.return_value = None
mock_ssh.SSH.from_node().execute.return_value = (
0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
@@ -193,6 +194,7 @@ class VsperfDPDKTestCase(unittest.TestCase):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
@@ -211,6 +213,7 @@ class VsperfDPDKTestCase(unittest.TestCase):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()