diff options
Diffstat (limited to 'tests/unit/benchmark')
4 files changed, 27 insertions, 18 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/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_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index fe7b6a57f..58244b8f5 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -387,7 +387,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): result = {'flow': {'dst_ip0': '152.16.40.2-152.16.40.254', 'src_ip0': '152.16.100.2-152.16.100.254'}} - self.assertEqual(result, self.s._get_traffic_flow()) + self.assertEqual({'flow': {}}, self.s._get_traffic_flow()) def test___get_traffic_flow_error(self): self.scenario_cfg["traffic_options"]["flow"] = \ 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() |