diff options
8 files changed, 35 insertions, 24 deletions
diff --git a/tests/unit/network_services/helpers/__init__.py b/yardstick/tests/unit/network_services/helpers/__init__.py index e69de29bb..e69de29bb 100644 --- a/tests/unit/network_services/helpers/__init__.py +++ b/yardstick/tests/unit/network_services/helpers/__init__.py diff --git a/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml b/yardstick/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml index f60834fbd..f60834fbd 100644 --- a/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml +++ b/yardstick/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml diff --git a/tests/unit/network_services/helpers/test_cpu.py b/yardstick/tests/unit/network_services/helpers/test_cpu.py index 1f9d3f219..871fbf8c9 100644 --- a/tests/unit/network_services/helpers/test_cpu.py +++ b/yardstick/tests/unit/network_services/helpers/test_cpu.py @@ -13,7 +13,6 @@ # limitations under the License. # -from __future__ import absolute_import from __future__ import division import unittest import mock @@ -25,15 +24,20 @@ from yardstick.network_services.helpers.cpu import \ class TestCpuSysCores(unittest.TestCase): + def setUp(self): + self._mock_ssh = mock.patch("yardstick.ssh.SSH") + self.mock_ssh = self._mock_ssh.start() + + self.addCleanup(self._cleanup) + + def _cleanup(self): + self._mock_ssh.stop() + def test___init__(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "", "")) - ssh_mock.put = \ - mock.Mock(return_value=(1, "", "")) - cpu_topo = CpuSysCores(ssh_mock) - self.assertIsNotNone(cpu_topo.connection) + self.mock_ssh.execute.return_value = 1, "", "" + self.mock_ssh.put.return_value = 1, "", "" + cpu_topo = CpuSysCores(self.mock_ssh) + self.assertIsNotNone(cpu_topo.connection) def test__get_core_details(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -52,7 +56,7 @@ class TestCpuSysCores(unittest.TestCase): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ - mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) ssh_mock.put = \ mock.Mock(return_value=(1, "", "")) cpu_topo = CpuSysCores(ssh_mock) @@ -68,7 +72,7 @@ class TestCpuSysCores(unittest.TestCase): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ - mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) ssh_mock.put = \ mock.Mock(return_value=(1, "", "")) cpu_topo = CpuSysCores(ssh_mock) @@ -77,14 +81,14 @@ class TestCpuSysCores(unittest.TestCase): mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], [{'physical id': '2', 'processor': '1'}]]) cpu_topo.core_map = \ - {'thread_per_core': '1', '2':['1'], 'cores_per_socket': '2'} + {'thread_per_core': '1', '2': ['1'], 'cores_per_socket': '2'} self.assertEqual(-1, cpu_topo.validate_cpu_cfg()) def test_validate_cpu_cfg_2t(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ - mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) ssh_mock.put = \ mock.Mock(return_value=(1, "", "")) cpu_topo = CpuSysCores(ssh_mock) @@ -93,7 +97,7 @@ class TestCpuSysCores(unittest.TestCase): mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], [{'physical id': '2', 'processor': '1'}]]) cpu_topo.core_map = \ - {'thread_per_core': 1, '2':['1'], 'cores_per_socket': '2'} + {'thread_per_core': 1, '2': ['1'], 'cores_per_socket': '2'} vnf_cfg = {'lb_config': 'SW', 'lb_count': 1, 'worker_config': '1C/2T', 'worker_threads': 1} self.assertEqual(-1, cpu_topo.validate_cpu_cfg(vnf_cfg)) @@ -102,7 +106,7 @@ class TestCpuSysCores(unittest.TestCase): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ - mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) + mock.Mock(return_value=(1, "cpu:1\ntest:2\n \n", "")) ssh_mock.put = \ mock.Mock(return_value=(1, "", "")) cpu_topo = CpuSysCores(ssh_mock) @@ -111,7 +115,7 @@ class TestCpuSysCores(unittest.TestCase): mock.Mock(side_effect=[[{'Core(s) per socket': '2', 'Thread(s) per core': '1'}], [{'physical id': '2', 'processor': '1'}]]) cpu_topo.core_map = \ - {'thread_per_core': 1, '2':[1], 'cores_per_socket': 2} + {'thread_per_core': 1, '2': [1], 'cores_per_socket': 2} vnf_cfg = {'lb_config': 'SW', 'lb_count': 1, 'worker_config': '1C/1T', 'worker_threads': 1} self.assertEqual(-1, cpu_topo.validate_cpu_cfg(vnf_cfg)) diff --git a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py b/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py index 9d94e3d0b..9d94e3d0b 100644 --- a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py +++ b/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py diff --git a/tests/unit/network_services/helpers/test_iniparser.py b/yardstick/tests/unit/network_services/helpers/test_iniparser.py index bd27b497e..1a09f0761 100644 --- a/tests/unit/network_services/helpers/test_iniparser.py +++ b/yardstick/tests/unit/network_services/helpers/test_iniparser.py @@ -13,13 +13,11 @@ # limitations under the License. # -from __future__ import absolute_import - import unittest from contextlib import contextmanager import mock -from tests.unit import STL_MOCKS +from yardstick.tests import STL_MOCKS STLClient = mock.MagicMock() @@ -105,7 +103,7 @@ class TestBaseParser(unittest.TestCase): @staticmethod def make_open(text_blob): @contextmanager - def internal_open(*args, **kwargs): + def internal_open(*args): yield text_blob.split('\n') return internal_open @@ -136,7 +134,7 @@ class TestConfigParser(unittest.TestCase): @staticmethod def make_open(text_blob): @contextmanager - def internal_open(*args, **kwargs): + def internal_open(*args): yield text_blob.split('\n') return internal_open diff --git a/tests/unit/network_services/helpers/test_samplevnf_helper.py b/yardstick/tests/unit/network_services/helpers/test_samplevnf_helper.py index 4145b46d0..45efb829e 100644 --- a/tests/unit/network_services/helpers/test_samplevnf_helper.py +++ b/yardstick/tests/unit/network_services/helpers/test_samplevnf_helper.py @@ -700,7 +700,6 @@ class TestMultiPortConfig(unittest.TestCase): self.assertIsNone(result) def test_generate_arp_route_tbl(self): - # ELF: could n=do this in setup topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = "" diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index c0f09ed3a..0cb11933f 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -290,7 +290,12 @@ no data length value class TestProxSocketHelper(unittest.TestCase): def setUp(self): - self.mock_time_sleep = mock.patch.object(time, 'sleep').start() + self._mock_time_sleep = mock.patch.object(time, 'sleep') + self.mock_time_sleep = self._mock_time_sleep.start() + self.addCleanup(self._stop_mocks) + + def _stop_mocks(self): + self._mock_time_sleep.stop() @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket') def test___init__(self, mock_socket): diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 4fd51f0e3..73f91d1b1 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -536,7 +536,12 @@ class TestVpeApproxVnf(unittest.TestCase): } def setUp(self): - self.mock_sleep = mock.patch.object(time, 'sleep').start() + self._mock_time_sleep = mock.patch.object(time, 'sleep') + self.mock_time_sleep = self._mock_time_sleep.start() + self.addCleanup(self._stop_mocks) + + def _stop_mocks(self): + self._mock_time_sleep.stop() def test___init__(self): vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) |