X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Funit%2Fnetwork_services%2Fvnf_generic%2Fvnf%2Ftest_vpe_vnf.py;h=c074dfb4ca246083de619618cc7e2e90646927f8;hb=d08a8d477fd7b9fb88855b12ee53eafa07e79afa;hp=3813aaa21dc446722d913f5de3a0057ed07ed58a;hpb=dd57115618caa299f6dd1eb350b55ecf062ca92e;p=yardstick.git diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 3813aaa21..c074dfb4c 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -15,15 +15,17 @@ # limitations under the License. # -from __future__ import absolute_import -import six.moves.configparser as configparser - +from multiprocessing import Process, Queue import os -import unittest +import time + import mock -from multiprocessing import Process, Queue +import six.moves.configparser as configparser +import unittest from tests.unit import STL_MOCKS +from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath +from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper @@ -40,9 +42,6 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.vpe_vnf import \ VpeApproxVnf, VpeApproxSetupEnvHelper -from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath -from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh - TEST_FILE_YAML = 'nsb_test_case.yaml' @@ -164,6 +163,11 @@ class TestConfigCreate(unittest.TestCase): self.assertEqual(config_create.downlink_ports, ['xe1']) self.assertEqual(config_create.socket, 2) + def test_dpdk_port_to_link_id(self): + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 2) + self.assertEqual(config_create.dpdk_port_to_link_id_map, {'xe0': 0, 'xe1': 1}) + def test_vpe_initialize(self): vnfd_helper = VnfdHelper(self.VNFD_0) config_create = ConfigCreate(vnfd_helper, 2) @@ -227,28 +231,6 @@ class TestConfigCreate(unittest.TestCase): self.assertNotEqual(result, '') def test_create_vpe_config(self): - uplink_ports = [ - { - 'index': 0, - 'dpdk_port_num': 1, - 'peer_intf': { - 'dpdk_port_num': 2, - 'index': 3, - }, - }, - ] - - downlink_ports = [ - { - 'index': 2, - 'dpdk_port_num': 3, - 'peer_intf': { - 'dpdk_port_num': 0, - 'index': 1, - }, - }, - ] - vnfd_helper = VnfdHelper(self.VNFD_0) config_create = ConfigCreate(vnfd_helper, 23) config_create.downlink_ports = ['xe1'] @@ -260,7 +242,6 @@ class TestConfigCreate(unittest.TestCase): os.system("git checkout -- %s" % vnf_cfg) -@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') class TestVpeApproxVnf(unittest.TestCase): VNFD_0 = { @@ -556,17 +537,21 @@ class TestVpeApproxVnf(unittest.TestCase): }, } - def test___init__(self, _): + def setUp(self): + self.mock_sleep = mock.patch.object(time, 'sleep').start() + + def test___init__(self): vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) self.assertIsNone(vpe_approx_vnf._vnf_process) @mock.patch(SSH_HELPER) - def test_collect_kpi_sa_not_running(self, ssh, _): + def test_collect_kpi_sa_not_running(self, ssh): mock_ssh(ssh) resource = mock.Mock(autospec=ResourceProfile) - resource.check_if_sa_running.return_value = False, 'error' + resource.check_if_system_agent_running.return_value = 1, '' resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234} + resource.check_if_system_agent_running.return_value = (1, None) vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf.q_in = mock.MagicMock() @@ -584,11 +569,11 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(vpe_approx_vnf.collect_kpi(), expected) @mock.patch(SSH_HELPER) - def test_collect_kpi_sa_running(self, ssh, _): + def test_collect_kpi_sa_running(self, ssh): mock_ssh(ssh) resource = mock.Mock(autospec=ResourceProfile) - resource.check_if_sa_running.return_value = True, 'good' + resource.check_if_system_agent_running.return_value = 0, '1234' resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234} vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) @@ -607,7 +592,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(vpe_approx_vnf.collect_kpi(), expected) @mock.patch(SSH_HELPER) - def test_vnf_execute(self, ssh, _): + def test_vnf_execute(self, ssh): mock_ssh(ssh) vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf.q_in = mock.MagicMock() @@ -616,7 +601,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(vpe_approx_vnf.vnf_execute("quit", 0), '') @mock.patch(SSH_HELPER) - def test_run_vpe(self, ssh, _): + def test_run_vpe(self, ssh): mock_ssh(ssh) vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) @@ -650,10 +635,10 @@ class TestVpeApproxVnf(unittest.TestCase): @mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.ConfigCreate") @mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.open") @mock.patch(SSH_HELPER) - def test_build_config(self, mock_mul, mock_context, mock_config, mock_open, ssh, _): + def test_build_config(self, ssh, *args): mock_ssh(ssh) vpe_approx_vnf = VpeApproxSetupEnvHelper(mock.MagicMock(), - mock.MagicMock, mock.MagicMock) + mock.MagicMock(), mock.MagicMock()) vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML) vpe_approx_vnf.generate_port_pairs = mock.Mock() vpe_approx_vnf.vnf_cfg = { @@ -683,7 +668,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertIsNotNone(vpe_approx_vnf.build_config()) @mock.patch(SSH_HELPER) - def test_wait_for_instantiate(self, ssh, _): + def test_wait_for_instantiate(self, ssh): mock_ssh(ssh) mock_process = mock.Mock(autospec=Process) @@ -706,7 +691,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432) @mock.patch(SSH_HELPER) - def test_wait_for_instantiate_fragmented(self, ssh, _): + def test_wait_for_instantiate_fragmented(self, ssh): mock_ssh(ssh) mock_process = mock.Mock(autospec=Process) @@ -729,7 +714,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432) @mock.patch(SSH_HELPER) - def test_wait_for_instantiate_crash(self, ssh, _): + def test_wait_for_instantiate_crash(self, ssh): mock_ssh(ssh, exec_result=(1, "", "")) mock_process = mock.Mock(autospec=Process) @@ -748,7 +733,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertIn('VNF process died', str(raised.exception)) @mock.patch(SSH_HELPER) - def test_wait_for_instantiate_panic(self, ssh, _): + def test_wait_for_instantiate_panic(self, ssh): mock_ssh(ssh, exec_result=(1, "", "")) mock_process = mock.Mock(autospec=Process) @@ -768,7 +753,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertIn('Error starting', str(raised.exception)) @mock.patch(SSH_HELPER) - def test_wait_for_instantiate_panic_fragmented(self, ssh, _): + def test_wait_for_instantiate_panic_fragmented(self, ssh): mock_ssh(ssh, exec_result=(1, "", "")) mock_process = mock.Mock(autospec=Process) @@ -792,13 +777,8 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertIn('Error starting', str(raised.exception)) - def test_scale(self, _): - vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) - with self.assertRaises(NotImplementedError): - vpe_approx_vnf.scale('') - @mock.patch(SSH_HELPER) - def test_terminate(self, ssh, _): + def test_terminate(self, ssh): mock_ssh(ssh) vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) @@ -807,7 +787,3 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf.resource_helper = mock.MagicMock() self.assertIsNone(vpe_approx_vnf.terminate()) - - -if __name__ == '__main__': - unittest.main()