diff options
Diffstat (limited to 'tests/unit/network_services')
12 files changed, 792 insertions, 433 deletions
diff --git a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py index 0c82d74a8..3f374fb50 100644 --- a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py +++ b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py @@ -82,10 +82,8 @@ class TestIxNextgen(unittest.TestCase): config = { 'chassis': '1.1.1.1', - 'card1': '1', - 'card2': '2', - 'port1': '2', - 'port2': '2', + 'cards': ['1', '2'], + 'ports': ['2', '2'], } ixnet_gen = IxNextgen(ixnet) @@ -673,10 +671,8 @@ class TestIxNextgen(unittest.TestCase): 'machine': 'test1', 'port': 'test5', 'chassis': 'test4', - 'card1': '0000', - 'port1': '07', - 'card2': '0001', - 'port2': '08', + 'cards': ['0000', '0001'], + 'ports': ['07', '08'], 'output_dir': 'test2', 'version': 'test3', 'bidir': True, diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index 1c2c1f3e2..eba38c688 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -14,7 +14,6 @@ from __future__ import absolute_import import unittest -import multiprocessing import mock from yardstick.network_services.nfvi.resource import ResourceProfile @@ -86,17 +85,20 @@ class TestResourceProfile(unittest.TestCase): 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} def setUp(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ + with mock.patch("yardstick.ssh.AutoConnectSSH") as ssh: + self.ssh_mock = mock.Mock(autospec=ssh.SSH) + self.ssh_mock.execute = \ mock.Mock(return_value=(0, {}, "")) - ssh.from_node.return_value = ssh_mock + ssh.from_node.return_value = self.ssh_mock mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ + # interfaces = \ + # self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] + port_names = \ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] self.resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) + ResourceProfile(mgmt, port_names, [1, 2, 3]) + self.resource_profile.connection = self.ssh_mock def test___init__(self): self.assertEqual(True, self.resource_profile.enable) @@ -118,133 +120,33 @@ class TestResourceProfile(unittest.TestCase): self.assertEqual(val, ('error', 'Invalid', '', '')) def test__start_collectd(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._prepare_collectd_conf = mock.Mock() - self.assertIsNone( - resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin")) - - def test__prepare_collectd_conf_BM(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._provide_config_file = mock.Mock() - self.assertIsNone( - resource_profile._prepare_collectd_conf("/opt/nsb_bin")) - - def test__prepare_collectd_conf_managed_ovs_dpdk(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._provide_config_file = mock.Mock() - self.assertIsNone( - resource_profile._prepare_collectd_conf("/opt/nsb_bin")) - - def test__prepare_collectd_conf_ovs_dpdk(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._provide_config_file = mock.Mock() self.assertIsNone( - resource_profile._prepare_collectd_conf("/opt/nsb_bin")) + self.resource_profile._start_collectd(self.ssh_mock, "/opt/nsb_bin")) - def test__prepare_collectd_conf_managed_sriov(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._provide_config_file = mock.Mock() + def test__prepare_collectd_conf(self): self.assertIsNone( - resource_profile._prepare_collectd_conf("/opt/nsb_bin")) + self.resource_profile._prepare_collectd_conf("/opt/nsb_bin")) - def test__prepare_collectd_conf_sriov(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._provide_config_file = mock.Mock() - self.assertIsNone( - resource_profile._prepare_collectd_conf("/opt/nsb_bin")) @mock.patch("yardstick.network_services.nfvi.resource.open") - @mock.patch("yardstick.network_services.nfvi.resource.tempfile") @mock.patch("yardstick.network_services.nfvi.resource.os") - def test__provide_config_file(self, mock_open, mock_tempfile, mock_os): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._prepare_collectd_conf = mock.Mock() - resource_profile.connection = ssh_mock - resource_profile.connection.put = \ - mock.Mock(return_value=(0, "", "")) - mock_tempfile.mkstemp = mock.Mock(return_value=["test", ""]) - self.assertIsNone( - resource_profile._provide_config_file("/opt/nsb_bin", - "collectd.cfg", {})) + def test__provide_config_file(self, mock_open, mock_os): + loadplugin = range(5) + port_names = range(5) + kwargs = { + "interval": '25', + "loadplugin": loadplugin, + "port_names": port_names, + } + self.resource_profile._provide_config_file("/opt/nsb_bin", "collectd.conf", kwargs) + self.ssh_mock.execute.assert_called_once() + @mock.patch("yardstick.network_services.nfvi.resource.open") def test_initiate_systemagent(self, mock_open): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - mgmt = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['mgmt-interface'] - interfaces = \ - self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] - resource_profile = \ - ResourceProfile(mgmt, interfaces, [1, 2, 3]) - resource_profile._start_collectd = mock.Mock() - self.assertIsNone( - resource_profile.initiate_systemagent("/opt/nsb_bin")) + self.resource_profile._start_collectd = mock.Mock() + self.assertIsNone( + self.resource_profile.initiate_systemagent("/opt/nsb_bin")) def test__parse_hugepages(self): reskey = ["cpu", "cpuFreq"] @@ -301,21 +203,21 @@ class TestResourceProfile(unittest.TestCase): self.assertDictEqual(res, expected_result) def test_parse_collectd_result_hugepage(self): - metric = {"nsb_stats/hugepages/free": "101"} + # amqp returns bytes + metric = {b"nsb_stats/hugepages/free": b"101"} self.resource_profile.parse_hugepages = \ mock.Mock(return_value={"free": "101"}) res = self.resource_profile.parse_collectd_result(metric, [0, 1, 2]) - expected_result = {'cpu': {}, 'dpdkstat': {}, 'hugepages': {'free': - '101'}, + expected_result = {'cpu': {}, 'dpdkstat': {}, 'hugepages': {'free': '101'}, 'memory': {}, 'ovs_stats': {}, 'timestamp': '', 'intel_pmu': {}, 'virt': {}} self.assertDictEqual(res, expected_result) def test_parse_collectd_result_dpdk_virt_ovs(self): - metric = {"nsb_stats/dpdkstat/tx": "101", - "nsb_stats/ovs_stats/tx": "101", - "nsb_stats/virt/virt/memory": "101"} + metric = {b"nsb_stats/dpdkstat/tx": b"101", + b"nsb_stats/ovs_stats/tx": b"101", + b"nsb_stats/virt/virt/memory": b"101"} self.resource_profile.parse_dpdkstat = \ mock.Mock(return_value={"tx": "101"}) self.resource_profile.parse_virt = \ @@ -347,7 +249,6 @@ class TestResourceProfile(unittest.TestCase): self.assertIsNotNone(res) def test_run_collectd_amqp(self): - _queue = multiprocessing.Queue() resource.AmqpConsumer = mock.Mock(autospec=collectd) self.assertIsNone(self.resource_profile.run_collectd_amqp()) diff --git a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py index 6fffb9ede..616921e33 100644 --- a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -179,12 +179,12 @@ class TestIXIARFC2544Profile(unittest.TestCase): "dst_mac_0": "00:00:00:00:00:03", "dst_mac_1": "00:00:00:00:00:04", "dst_mac_2": "00:00:00:00:00:04"} - self.assertRaises(IOError, r_f_c2544_profile._get_ixia_traffic_profile, - self.PROFILE, mac, xfile="tmp", - static_traffic=STATIC_TRAFFIC) + result = r_f_c2544_profile._get_ixia_traffic_profile( + self.PROFILE, mac, xfile="tmp", + static_traffic=STATIC_TRAFFIC) + self.assertIsNotNone(result) - @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open") - def test_get_ixia_traffic_profile(self, mock_open): + def test_get_ixia_traffic_profile(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] traffic_generator.uplink_ports = [-1] diff --git a/tests/unit/network_services/traffic_profile/test_prox_acl.py b/tests/unit/network_services/traffic_profile/test_prox_acl.py index a0c60186c..ef5bac0d5 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_acl.py +++ b/tests/unit/network_services/traffic_profile/test_prox_acl.py @@ -59,18 +59,9 @@ class TestProxACLProfile(unittest.TestCase): fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_gen = mock.MagicMock() - traffic_gen.run_test = target - - traffic_gen.resource_helper.run_test.side_effect = [ - success_tuple, - success_tuple, - success_tuple, - fail_tuple, - success_tuple, - fail_tuple, - fail_tuple, - fail_tuple, - ] + + profile_helper = mock.MagicMock() + profile_helper.run_test = target profile = ProxACLProfile(tp_config) profile.init(mock.MagicMock()) @@ -82,5 +73,6 @@ class TestProxACLProfile(unittest.TestCase): profile.duration = 30 profile.test_value = 100.0 profile.tolerated_loss = 100.0 + profile._profile_helper = profile_helper profile.run_test_with_pkt_size(traffic_gen, profile.pkt_size, profile.duration) diff --git a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py index f56a7fba9..c1f1c825b 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py +++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py @@ -51,10 +51,13 @@ class TestProxBinSearchProfile(unittest.TestCase): fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_generator = mock.MagicMock() - traffic_generator.run_test = target + + profile_helper = mock.MagicMock() + profile_helper.run_test = target profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) + profile._profile_helper = profile_helper profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) @@ -82,10 +85,13 @@ class TestProxBinSearchProfile(unittest.TestCase): fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_generator = mock.MagicMock() - traffic_generator.run_test = target + + profile_helper = mock.MagicMock() + profile_helper.run_test = target profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) + profile._profile_helper = profile_helper profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 24.06) diff --git a/tests/unit/network_services/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py index 642fecc35..00a690d2a 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py +++ b/tests/unit/network_services/traffic_profile/test_prox_mpls.py @@ -51,10 +51,11 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_generator = mock.MagicMock() - traffic_generator.run_test = target profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) + profile._profile_helper = profile_helper = mock.MagicMock() + profile_helper.run_test = target profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) @@ -82,10 +83,11 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) traffic_generator = mock.MagicMock() - traffic_generator.run_test = target profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) + profile._profile_helper = profile_helper = mock.MagicMock() + profile_helper.run_test = target profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 24.06) diff --git a/tests/unit/network_services/traffic_profile/test_prox_profile.py b/tests/unit/network_services/traffic_profile/test_prox_profile.py index 9899d9909..078e72b8e 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -26,6 +26,7 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.prox_profile import ProxProfile + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper class TestProxProfile(unittest.TestCase): @@ -62,8 +63,9 @@ class TestProxProfile(unittest.TestCase): } profile = ProxProfile(tp_config) - profile.init(234) - self.assertEqual(profile.queue, 234) + queue = mock.Mock() + profile.init(queue) + self.assertIs(profile.queue, queue) def test_execute_traffic(self): packet_sizes = [ @@ -78,6 +80,13 @@ class TestProxProfile(unittest.TestCase): } traffic_generator = mock.MagicMock() + + setup_helper = traffic_generator.setup_helper + setup_helper.find_in_section.return_value = None + + prox_resource_helper = ProxResourceHelper(setup_helper) + traffic_generator.resource_helper = prox_resource_helper + profile = ProxProfile(tp_config) self.assertFalse(profile.done) @@ -86,6 +95,7 @@ class TestProxProfile(unittest.TestCase): profile.execute_traffic(traffic_generator) self.assertIsNone(profile.execute_traffic(traffic_generator)) + self.assertTrue(profile.done) def test_bounds_iterator(self): tp_config = { diff --git a/tests/unit/network_services/traffic_profile/test_prox_ramp.py b/tests/unit/network_services/traffic_profile/test_prox_ramp.py index 357298759..1acec2f68 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_ramp.py +++ b/tests/unit/network_services/traffic_profile/test_prox_ramp.py @@ -26,6 +26,7 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.prox_ramp import ProxRampProfile + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxProfileHelper from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple @@ -43,14 +44,18 @@ class TestProxRampProfile(unittest.TestCase): success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4) traffic_gen = mock.MagicMock() - traffic_gen.resource_helper.run_test.return_value = success_tuple + traffic_gen._test_type = 'Generic' + + profile_helper = ProxProfileHelper(traffic_gen.resource_helper) + profile_helper.run_test = run_test = mock.MagicMock(return_value=success_tuple) profile = ProxRampProfile(tp_config) profile.fill_samples = fill_samples = mock.MagicMock() profile.queue = mock.MagicMock() + profile._profile_helper = profile_helper profile.run_test_with_pkt_size(traffic_gen, 128, 30) - self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 10) + self.assertEqual(run_test.call_count, 10) self.assertEqual(fill_samples.call_count, 10) def test_run_test_with_pkt_size_with_fail(self): @@ -65,8 +70,7 @@ class TestProxRampProfile(unittest.TestCase): success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4) fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) - traffic_gen = mock.MagicMock() - traffic_gen.resource_helper.run_test.side_effect = [ + result_list = [ success_tuple, success_tuple, success_tuple, @@ -77,10 +81,17 @@ class TestProxRampProfile(unittest.TestCase): fail_tuple, ] + traffic_gen = mock.MagicMock() + traffic_gen._test_type = 'Generic' + + profile_helper = ProxProfileHelper(traffic_gen.resource_helper) + profile_helper.run_test = run_test = mock.MagicMock(side_effect=result_list) + profile = ProxRampProfile(tp_config) profile.fill_samples = fill_samples = mock.MagicMock() profile.queue = mock.MagicMock() + profile._profile_helper = profile_helper profile.run_test_with_pkt_size(traffic_gen, 128, 30) - self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 4) + self.assertEqual(run_test.call_count, 4) self.assertEqual(fill_samples.call_count, 3) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index 995b4a2cc..e4319d602 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -40,7 +40,11 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper from yardstick.network_services.vnf_generic.vnf.prox_helpers import TotStatsTuple + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDataHelper from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxProfileHelper + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxMplsProfileHelper + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxBngProfileHelper class TestCoreTuple(unittest.TestCase): @@ -741,6 +745,106 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): }, } + def test_global_section(self): + setup_helper = ProxDpdkVnfSetupEnvHelper(mock.MagicMock(), mock.MagicMock(), + mock.MagicMock()) + + setup_helper._prox_config_data = [('a', [])] + + with self.assertRaises(KeyError): + _ = setup_helper.global_section + + global_section = ( + 'global', [ + ('not_name', 'other data'), + ('name_not', 'more data'), + ('name', 'prox type'), + ], + ) + + setup_helper._prox_config_data = [ + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('core 1', []), + ('core 2', [ + ('index', 8), + ('mode', ''), + ]), + global_section, + ('core 3', [ + ('index', 5), + ('mode', 'gen'), + ('name', 'tagged'), + ]), + ('section3', [ + ('key1', 'value1'), + ('key2', 'value2'), + ('key3', 'value3'), + ]), + ('core 4', [ + ('index', 7), + ('mode', 'gen'), + ('name', 'udp'), + ]), + ] + + result = setup_helper.global_section + self.assertEqual(result, global_section[1]) + + def test_find_in_section(self): + setup_helper = ProxDpdkVnfSetupEnvHelper(mock.MagicMock(), mock.MagicMock(), + mock.MagicMock()) + + setup_helper._prox_config_data = [ + ('global', [ + ('not_name', 'other data'), + ('name_not', 'more data'), + ('name', 'prox type'), + ]), + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('core 1', []), + ('core 2', [ + ('index', 8), + ('mode', ''), + ]), + ('core 3', [ + ('index', 5), + ('mode', 'gen'), + ('name', 'tagged'), + ]), + ('section3', [ + ('key1', 'value1'), + ('key2', 'value2'), + ('key3', 'value3'), + ]), + ('core 4', [ + ('index', 7), + ('mode', 'gen'), + ('name', 'udp'), + ]), + ] + + expected = 'value3' + result = setup_helper.find_in_section('section3', 'key3') + self.assertEqual(result, expected) + + expected = 'default value' + result = setup_helper.find_in_section('section3', 'key4', 'default value') + self.assertEqual(result, expected) + + with self.assertRaises(KeyError): + setup_helper.find_in_section('section4', 'key1') + + with self.assertRaises(KeyError): + setup_helper.find_in_section('section1', 'key1') + def test__replace_quoted_with_value(self): # empty string input_str = '' @@ -858,6 +962,16 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): result = ProxDpdkVnfSetupEnvHelper.write_prox_config(input_data) self.assertEqual(result, expected) + def test_prox_config_data(self): + setup_helper = ProxDpdkVnfSetupEnvHelper(mock.MagicMock(), mock.MagicMock(), + mock.MagicMock()) + + setup_helper.config_queue = config_queue = mock.MagicMock() + config_queue.get.return_value = expected = [('s', [('a', 3), ('b', 45)])] + + result = setup_helper.prox_config_data + self.assertEqual(result, expected) + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') def test_build_config_file_no_additional_file(self, mock_find_path): vnf1 = { @@ -1344,11 +1458,6 @@ class TestProxResourceHelper(unittest.TestCase): }, } - def test_line_rate_to_pps(self): - expected = 0.25 * 1e8 - result = ProxResourceHelper.line_rate_to_pps(180, 4) - self.assertEqual(result, expected) - def test_find_pci(self): input_str_list = [ 'no target here', @@ -1377,14 +1486,255 @@ class TestProxResourceHelper(unittest.TestCase): self.assertIs(result, helper.client) self.assertIs(result, helper.sut) + def test_test_type(self): + setup_helper = mock.MagicMock() + setup_helper.find_in_section.return_value = expected = 'prox type' + + helper = ProxResourceHelper(setup_helper) + + self.assertIsNone(helper._test_type) + self.assertEqual(helper.test_type, expected) + self.assertEqual(helper._test_type, expected) + self.assertEqual(helper.test_type, expected) + + def test_collect_collectd_kpi(self): + helper = ProxResourceHelper(mock.MagicMock()) + helper.resource = resource = mock.MagicMock() + + resource.amqp_collect_nfvi_kpi.return_value = 543 + + expected = {'core': 543} + result = helper.collect_collectd_kpi() + self.assertDictEqual(result, expected) + + def test_collect_kpi(self): + helper = ProxResourceHelper(mock.MagicMock()) + helper._queue = queue = mock.MagicMock() + helper._result = {'z': 123} + helper.resource = resource = mock.MagicMock() + + resource.amqp_collect_nfvi_kpi.return_value = 543 + + queue.empty.return_value = False + queue.get.return_value = {'a': 789} + + expected = {'z': 123, 'a': 789, 'collect_stats': {'core': 543}} + result = helper.collect_kpi() + self.assertDictEqual(result, expected) + + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper') + def test__connect(self, mock_socket_helper_type, mock_time): + client = mock_socket_helper_type() + client.connect.side_effect = chain(repeat(socket.error, 5), [None]) + + setup_helper = mock.MagicMock() + setup_helper.vnfd_helper.interfaces = [] + + helper = ProxResourceHelper(setup_helper) + + result = helper._connect() + self.assertIs(result, client) + + client.connect.side_effect = chain(repeat(socket.error, 65), [None]) + + with self.assertRaises(Exception): + helper._connect() + + def test_run_traffic(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + traffic_profile = mock.MagicMock(**{"done": True}) + helper.run_traffic(traffic_profile) + self.assertEqual(helper._terminated.value, 1) + + def test__run_traffic_once(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + traffic_profile = mock.MagicMock(**{"done": True}) + helper._run_traffic_once(traffic_profile) + self.assertEqual(helper._terminated.value, 1) + + def test_start_collect(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + helper.resource = resource = mock.MagicMock() + self.assertIsNone(helper.start_collect()) + resource.start.assert_called_once() + + def test_terminate(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + with self.assertRaises(NotImplementedError): + helper.terminate() + + def test_up_post(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + helper.client = expected = mock.MagicMock() + result = helper.up_post() + self.assertEqual(result, expected) + + def test_execute(self): + setup_helper = mock.MagicMock() + helper = ProxResourceHelper(setup_helper) + helper.client = mock.MagicMock() + + expected = helper.client.my_command() + result = helper.execute('my_command') + self.assertEqual(result, expected) + + helper.client = object() + + result = helper.execute('my_command') + self.assertIsNone(result) + + +class TestProxDataHelper(unittest.TestCase): + + def test_totals_and_pps(self): + pkt_size = 180 + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.all_ports = list(range(4)) + + sut = mock.MagicMock() + sut.port_stats.return_value = list(range(10)) + + data_helper = ProxDataHelper(vnfd_helper, sut, pkt_size, 25, None) + + self.assertEqual(data_helper.rx_total, 6) + self.assertEqual(data_helper.tx_total, 7) + self.assertEqual(data_helper.pps, 6.25e6) + + def test_samples(self): + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.all_ports = list(range(4)) + vnfd_helper.ports_iter.return_value = [('xe1', 3), ('xe2', 7)] + + sut = mock.MagicMock() + sut.port_stats.return_value = list(range(10)) + + data_helper = ProxDataHelper(vnfd_helper, sut, None, None, None) + + expected = { + 'xe1': { + 'in_packets': 6, + 'out_packets': 7, + }, + 'xe2': { + 'in_packets': 6, + 'out_packets': 7, + }, + } + result = data_helper.samples + self.assertDictEqual(result, expected) + + def test___enter__(self): + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.all_ports = list(range(4)) + vnfd_helper.ports_iter.return_value = [('xe1', 3), ('xe2', 7)] + + sut = mock.MagicMock() + sut.port_stats.return_value = list(range(10)) + + data_helper = ProxDataHelper(vnfd_helper, sut, None, None, 5.4) + data_helper._totals_and_pps = 12, 32, 4.5 + data_helper.tsc_hz = 9.8 + data_helper.measured_stats = {'delta': TotStatsTuple(6.1, 6.2, 6.3, 6.4)} + data_helper.latency = 7 + + self.assertIsNone(data_helper.result_tuple) + + expected = ProxTestDataTuple(5.4, 9.8, 6.1, 6.2, 6.3, 7, 12, 32, 4.5) + with data_helper: + pass + + result = data_helper.result_tuple + self.assertEqual(result, expected) + + data_helper.make_tuple() + self.assertIs(data_helper.result_tuple, result) + + def test___enter___negative(self): + vnfd_helper = mock.MagicMock() + + data_helper = ProxDataHelper(vnfd_helper, None, None, None, None) + + vnfd_helper.port_pairs.all_ports = [] + with self.assertRaises(AssertionError): + with data_helper: + pass + + vnfd_helper.port_pairs.all_ports = [0, 1, 2] + with self.assertRaises(AssertionError): + with data_helper: + pass + + def test_measure_tot_stats(self): + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.all_ports = list(range(4)) + + start = (3, 4, 1, 2) + end = (9, 7, 6, 8) + + sut = ProxSocketHelper(mock.MagicMock()) + sut.get_all_tot_stats = mock.MagicMock(side_effect=[start, end]) + + data_helper = ProxDataHelper(vnfd_helper, sut, None, None, 5.4) + + self.assertIsNone(data_helper.measured_stats) + + expected = { + 'start_tot': start, + 'end_tot': end, + 'delta': TotStatsTuple(6, 3, 5, 6), + } + with data_helper.measure_tot_stats(): + pass + + self.assertEqual(data_helper.measured_stats, expected) + + def test_capture_tsc_hz(self): + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.all_ports = list(range(4)) + + sut = mock.MagicMock() + sut.hz.return_value = '54.6' + + data_helper = ProxDataHelper(vnfd_helper, sut, None, None, None) + + self.assertIsNone(data_helper.tsc_hz) + + expected = 54.6 + data_helper.capture_tsc_hz() + self.assertEqual(data_helper.tsc_hz, expected) + + +class TestProxProfileHelper(unittest.TestCase): + + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.utils') + def test_get_cls(self, mock_utils): + mock_type1 = mock.MagicMock() + mock_type1.__prox_profile_type__ = 'another_type' + mock_type2 = mock.MagicMock() + mock_type2.__prox_profile_type__ = 'my_type' + mock_utils.itersubclasses.return_value = [mock_type1, mock_type2] + + self.assertEqual(ProxProfileHelper.get_cls('my_type'), mock_type2) + + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.utils') + def test_get_cls_default(self, mock_utils): + mock_utils.itersubclasses.return_value = [] + ProxProfileHelper.get_cls('my_type') + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.SocketTopology') def test_cpu_topology(self, mock_socket_topology): mock_socket_topology.parse_cpuinfo.return_value = 432 - setup_helper = mock.MagicMock() - setup_helper.ssh_helper.execute.return_value = 0, 'output', '' + resource_helper = mock.MagicMock() + resource_helper.setup_helper.ssh_helper.execute.return_value = 0, 'output', '' - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(resource_helper) self.assertIsNone(helper._cpu_topology) result = helper.cpu_topology self.assertEqual(result, 432) @@ -1392,17 +1742,17 @@ class TestProxResourceHelper(unittest.TestCase): self.assertIs(result, helper.cpu_topology) def test_test_cores(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_data = [] + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [] - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(resource_helper) helper._cpu_topology = [] expected = [] result = helper.test_cores self.assertEqual(result, expected) - setup_helper.prox_config_data = [ + resource_helper.setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1423,7 +1773,7 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(resource_helper) helper._cpu_topology = { 1: { 3: { @@ -1448,83 +1798,74 @@ class TestProxResourceHelper(unittest.TestCase): self.assertIs(result, helper._test_cores) self.assertIs(result, helper.test_cores) - def test_get_test_type(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) + def test_latency_cores(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data= [] - setup_helper.prox_config_data = [ - ('global', [ - ('name', helper.PROX_CORE_MPLS_TEST) - ]), - ('section2', [ - ('a', 'b'), - ('c', 'd'), - ]), - ('core 1', []), - ('core 2', [ - ('index', 8), - ('mode', ''), - ]), - ('core 3', [ - ('index', 5), - ('mode', 'gen'), - ]), - ('core 4', [ - ('index', 7), - ('mode', 'gen'), - ]), - ] - test_type = helper.get_test_type() - self.assertEqual(test_type, helper.PROX_CORE_MPLS_TEST) + helper = ProxProfileHelper(resource_helper) + helper._cpu_topology = [] - def test_get_cores(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_data = [ + expected = [] + result = helper.latency_cores + self.assertEqual(result, expected) + + resource_helper.setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), ('c', 'd'), ]), - ('core 1', []), - ('core 2', [ + ('core 1s3', []), + ('core 2s5', [ ('index', 8), ('mode', ''), ]), - ('core 3', [ + ('core 3s1', [ ('index', 5), - ('mode', 'gen'), + ('mode', 'lat'), ]), - ('core 4', [ + ('core 4s9h', [ ('index', 7), - ('mode', 'gen'), + ('mode', 'lat'), ]), ] - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(resource_helper) helper._cpu_topology = { - 0: { - 1: { - 5: (5, 1, 0) - }, - 2: { - 6: (6, 2, 0) - }, + 1: { 3: { - 7: (7, 3, 0) + 'key1': (23, 32), + 'key2': (12, 21), + 'key3': (44, 33), }, + }, + 9: { 4: { - 8: (8, 3, 0) + 'key1': (44, 32), + 'key2': (23, 21), + 'key3': (12, 33), }, - } + }, } - expected = [7, 8] - result = helper.get_cores(helper.PROX_CORE_GEN_MODE) + self.assertIsNone(helper._latency_cores) + expected = [12, 23] + result = helper.latency_cores self.assertEqual(result, expected) + self.assertIs(result, helper._latency_cores) + self.assertIs(result, helper.latency_cores) - def test_get_cores_mpls(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_data = [ + def test_all_rx_cores(self): + helper = ProxBngProfileHelper(mock.MagicMock()) + helper._latency_cores = expected = [3, 4, 6] + helper._test_cores = [5, 2, 1] + + result = helper.all_rx_cores + self.assertEqual(result, expected) + + def test_get_cores(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1538,16 +1879,14 @@ class TestProxResourceHelper(unittest.TestCase): ('core 3', [ ('index', 5), ('mode', 'gen'), - ('name', 'tagged'), ]), ('core 4', [ ('index', 7), ('mode', 'gen'), - ('name', 'udp'), ]), ] - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(resource_helper) helper._cpu_topology = { 0: { 1: { @@ -1565,123 +1904,34 @@ class TestProxResourceHelper(unittest.TestCase): } } - expected_tagged = [7] - expected_plain = [8] - result_tagged, result_plain = helper.get_cores_mpls(helper.PROX_CORE_GEN_MODE) - self.assertEqual(result_tagged, expected_tagged) - self.assertEqual(result_plain, expected_plain) - - def test_latency_cores(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_data= [] - - helper = ProxResourceHelper(setup_helper) - helper._cpu_topology = [] - - expected = [] - result = helper.latency_cores - self.assertEqual(result, expected) - - setup_helper.prox_config_data = [ - ('section1', []), - ('section2', [ - ('a', 'b'), - ('c', 'd'), - ]), - ('core 1s3', []), - ('core 2s5', [ - ('index', 8), - ('mode', ''), - ]), - ('core 3s1', [ - ('index', 5), - ('mode', 'lat'), - ]), - ('core 4s9h', [ - ('index', 7), - ('mode', 'lat'), - ]), - ] - - helper = ProxResourceHelper(setup_helper) - helper._cpu_topology = { - 1: { - 3: { - 'key1': (23, 32), - 'key2': (12, 21), - 'key3': (44, 33), - }, - }, - 9: { - 4: { - 'key1': (44, 32), - 'key2': (23, 21), - 'key3': (12, 33), - }, - }, - } - - self.assertIsNone(helper._latency_cores) - expected = [12, 23] - result = helper.latency_cores + expected = [7, 8] + result = helper.get_cores(helper.PROX_CORE_GEN_MODE) self.assertEqual(result, expected) - self.assertIs(result, helper._latency_cores) - self.assertIs(result, helper.latency_cores) - - def test_run_traffic(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) - traffic_proifle = mock.MagicMock(**{"done": True}) - helper.run_traffic(traffic_proifle) - self.assertEqual(helper._terminated.value, 1) - def test__run_traffic_once(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) - traffic_proifle = mock.MagicMock(**{"done": True}) - helper._run_traffic_once(traffic_proifle) - self.assertEqual(helper._terminated.value, 1) - - def test_start_collect(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) - helper.resource = resource = mock.MagicMock() - self.assertIsNone(helper.start_collect()) - resource.start.assert_called_once() + def test_get_latency(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.vnfd_helper.interfaces = [] - def test_terminate(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) - with self.assertRaises(NotImplementedError): - helper.terminate() + helper = ProxProfileHelper(resource_helper) + helper._latency_cores = [] - def test_up_post(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) - helper.client = expected = mock.MagicMock() - result = helper.up_post() + expected = [] + result = helper.get_latency() self.assertEqual(result, expected) - def test_execute(self): - setup_helper = mock.MagicMock() - helper = ProxResourceHelper(setup_helper) + helper._latency_cores = [1, 2] helper.client = mock.MagicMock() - expected = helper.client.my_command() - result = helper.execute('my_command') - self.assertEqual(result, expected) - - helper.client = object() - - result = helper.execute('my_command') - self.assertIsNone(result) + expected = helper.sut.lat_stats() + result = helper.get_latency() + self.assertIs(result, expected) @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') def test_traffic_context(self, mock_time): setup_helper = mock.MagicMock() setup_helper.vnfd_helper.interfaces = [] - helper = ProxResourceHelper(setup_helper) + helper = ProxProfileHelper(setup_helper) helper._cpu_topology = { 0: { 1: { @@ -1701,7 +1951,9 @@ class TestProxResourceHelper(unittest.TestCase): setup_helper.prox_config_data = [ ('global', [ - ('name', helper.PROX_CORE_MPLS_TEST) + ('not_name', 'other data'), + ('name_not', 'more data'), + ('name', helper.__prox_profile_type__), ]), ('section1', []), ('section2', [ @@ -1739,101 +1991,159 @@ class TestProxResourceHelper(unittest.TestCase): pass @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') - def test_run_test(self, mock_time): - @contextmanager - def measure(*args, **kwargs): - yield stats - - bad_vnfd = copy.deepcopy(self.VNFD0) - bad_vnfd['vdu'][0]['external-interface'].append({ - 'virtual-interface': { - 'dst_mac': '00:00:00:00:00:05', - 'vpci': '0000:06:00.0', - 'local_ip': '152.16.100.20', - 'type': 'PCI-PASSTHROUGH', - 'vld_id': 'uplink_1', - 'netmask': '255.255.255.0', - 'dpdk_port_num': 0, - 'bandwidth': '10 Gbps', - 'driver': "i40e", - 'dst_ip': '152.16.100.20', - 'local_iface_name': 'xe2', - 'local_mac': '00:00:00:00:00:07', - 'ifname': 'xe2', - }, - 'vnfd-connection-point-ref': 'xe2', - 'name': 'xe2', - }) + def test_run_test(self, _): + resource_helper = mock.MagicMock() + resource_helper.step_delta = 0.4 + resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2)) + resource_helper.sut.port_stats.return_value = list(range(10)) - bad_vnfd_helper = VnfdHelper(bad_vnfd) - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper = bad_vnfd_helper + helper = ProxProfileHelper(resource_helper) - stats = { - 'delta': TotStatsTuple(6, 7, 8, 9), - } + helper.run_test(120, 5, 6.5) - client = mock.MagicMock() - client.hz.return_value = 2 - client.measure_tot_stats = measure - client.port_stats.return_value = tuple(range(12)) - helper = ProxResourceHelper(setup_helper) - helper.client = client - helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8]) +class TestProxMplsProfileHelper(unittest.TestCase): - with self.assertRaises(AssertionError): - helper.run_test(980, 15, 45) - - vnfd_helper = VnfdHelper(self.VNFD0) - setup_helper.vnfd_helper = vnfd_helper - helper = ProxResourceHelper(setup_helper) - helper.client = client - helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8]) - helper._test_cores = [3, 4] + def test_mpls_cores(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [ + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('core 1', []), + ('core 2', [ + ('index', 8), + ('mode', ''), + ]), + ('core 3', [ + ('index', 5), + ('mode', 'gen'), + ('name', 'tagged'), + ]), + ('core 4', [ + ('index', 7), + ('mode', 'gen'), + ('name', 'udp'), + ]), + ] - expected_test_data = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7, 6.5e6) - expected_port_samples = { - 'xe0': {'in_packets': 6, 'out_packets': 7}, - 'xe1': {'in_packets': 6, 'out_packets': 7}, + helper = ProxMplsProfileHelper(resource_helper) + helper._cpu_topology = { + 0: { + 1: { + 5: (5, 1, 0) + }, + 2: { + 6: (6, 2, 0) + }, + 3: { + 7: (7, 3, 0) + }, + 4: { + 8: (8, 3, 0) + }, + } } - test_data, port_samples = helper.run_test(230, 60, 65) - self.assertTupleEqual(test_data, expected_test_data) - self.assertDictEqual(port_samples, expected_port_samples) - def test_get_latency(self): + expected_tagged = [7] + expected_plain = [8] + self.assertIsNone(helper._cores_tuple) + self.assertEqual(helper.tagged_cores, expected_tagged) + self.assertEqual(helper.plain_cores, expected_plain) + self.assertEqual(helper._cores_tuple, (expected_tagged, expected_plain)) + + def test_traffic_context(self): setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] + helper = ProxMplsProfileHelper(setup_helper) - helper = ProxResourceHelper(setup_helper) - helper._latency_cores = [] + with helper.traffic_context(120, 5.4): + pass - expected = [] - result = helper.get_latency() - self.assertEqual(result, expected) - helper._latency_cores = [1, 2] - helper.client = mock.MagicMock() +class TestProxBngProfileHelper(unittest.TestCase): - expected = helper.sut.lat_stats() - result = helper.get_latency() - self.assertIs(result, expected) + def test_bng_cores(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [ + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('core 1', []), + ('core 2', [ + ('index', 8), + ('mode', ''), + ]), + ('core 3', [ + ('index', 5), + ('mode', 'gen'), + ('name', 'cpe'), + ]), + ('core 4', [ + ('index', 7), + ('mode', 'gen'), + ('name', 'inet'), + ]), + ('core 6', [ + ('index', 3), + ('mode', 'gen'), + ('name', 'arp_task'), + ]), + ('core 9', [ + ('index', 2), + ('mode', 'gen'), + ('name', 'arp'), + ]), + ] - @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') - @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper') - def test__connect(self, mock_socket_helper_type, mock_time): - client = mock_socket_helper_type() - client.connect.side_effect = chain(repeat(socket.error, 5), [None]) + helper = ProxBngProfileHelper(resource_helper) + helper._cpu_topology = { + 0: { + 1: { + 5: (5, 1, 0) + }, + 2: { + 6: (6, 2, 0) + }, + 3: { + 7: (7, 3, 0) + }, + 4: { + 8: (8, 3, 0) + }, + 6: { + 1: (4, 8, 0) + }, + 9: { + 2: (3, 7, 0) + }, + } + } - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] + expected_cpe = [7] + expected_inet = [8] + expected_arp = [4, 3] + expected_arp_task = [0, 4] + expected_combined = (expected_cpe, expected_inet, expected_arp, expected_arp_task) - helper = ProxResourceHelper(setup_helper) + self.assertIsNone(helper._cores_tuple) + self.assertEqual(helper.cpe_cores, expected_cpe) + self.assertEqual(helper.inet_cores, expected_inet) + self.assertEqual(helper.arp_cores, expected_arp) + self.assertEqual(helper.arp_task_cores, expected_arp_task) + self.assertEqual(helper._cores_tuple, expected_combined) - result = helper._connect() - self.assertIs(result, client) + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') + def test_run_test(self, _): + resource_helper = mock.MagicMock() + resource_helper.step_delta = 0.4 + resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2)) + resource_helper.sut.port_stats.return_value = list(range(10)) - client.connect.side_effect = chain(repeat(socket.error, 65), [None]) + helper = ProxBngProfileHelper(resource_helper) - with self.assertRaises(Exception): - helper._connect() + helper.run_test(120, 5, 6.5) + helper.run_test(-1000, 5, 6.5) # negative pkt_size is the only way to make ratio > 1 diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index 4b9f4172e..d0c4b6f42 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -723,8 +723,9 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): result = dpdk_setup_helper._validate_cpu_cfg() self.assertEqual(result, expected) + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('yardstick.ssh.SSH') - def test_setup_vnf_environment(self, _): + def test_setup_vnf_environment(self, _, mock_time): def execute(cmd, *args, **kwargs): if cmd.startswith('which '): return exec_failure @@ -782,6 +783,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) dpdk_setup_helper._validate_cpu_cfg = mock.Mock() + dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in + vnfd_helper.interfaces] result = dpdk_setup_helper._setup_resources() self.assertIsInstance(result, ResourceProfile) self.assertEqual(dpdk_setup_helper.socket, 0) @@ -796,11 +799,14 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) dpdk_setup_helper._validate_cpu_cfg = mock.Mock() + dpdk_setup_helper.bound_pci = [v['virtual-interface']["vpci"] for v in + vnfd_helper.interfaces] result = dpdk_setup_helper._setup_resources() self.assertIsInstance(result, ResourceProfile) self.assertEqual(dpdk_setup_helper.socket, 1) - def test__detect_and_bind_drivers(self): + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') + def test__detect_and_bind_drivers(self, mock_time): vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) ssh_helper = mock.Mock() # ssh_helper.execute = mock.Mock(return_value = (0, 'text', '')) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index 0e303dc3b..f62a0fb3b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -252,6 +252,7 @@ class TestIXIATrafficGen(unittest.TestCase): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE + # traffic_profile.ports is standardized on port_num mock_traffic_profile.ports = [0, 1] mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH) @@ -346,8 +347,12 @@ class TestIXIATrafficGen(unittest.TestCase): 'task_path': '/path/to/task' } - with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', - create=True) as mock_open: - mock_open.return_value = mock.MagicMock() + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open', + mock.mock_open(), create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception') + def _traffic_runner(*args): result = sut._traffic_runner(mock_traffic_profile) self.assertIsNone(result) + + _traffic_runner() 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 757109d11..3813aaa21 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 @@ -25,6 +25,7 @@ from multiprocessing import Process, Queue from tests.unit import STL_MOCKS from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -55,14 +56,117 @@ get_file_abspath = MODULE_PATH.get_path class TestConfigCreate(unittest.TestCase): + VNFD_0 = { + 'short-name': 'VpeVnf', + 'vdu': [ + { + 'routing_table': [ + { + 'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0' + }, + { + 'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1' + }, + ], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': [ + { + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0' + }, + { + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1' + }, + ], + 'id': 'vpevnf-baremetal', + 'external-interface': [ + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.0', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.100.20', + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0' + }, + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:04', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1' + }, + ], + }, + ], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': { + 'vdu-id': 'vpevnf-baremetal', + 'host': '1.1.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.1.1.1' + }, + 'benchmark': { + 'kpi': [ + 'packets_in', + 'packets_fwd', + 'packets_dropped', + ], + }, + 'connection-point': [ + { + 'type': 'VPORT', + 'name': 'xe0', + }, + { + 'type': 'VPORT', + 'name': 'xe1', + }, + ], + 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh' + } + def test___init__(self): - config_create = ConfigCreate([0], [1], 2) - self.assertEqual(config_create.uplink_ports, [0]) - self.assertEqual(config_create.downlink_ports, [1]) + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 2) + self.assertEqual(config_create.uplink_ports, ['xe0']) + self.assertEqual(config_create.downlink_ports, ['xe1']) self.assertEqual(config_create.socket, 2) def test_vpe_initialize(self): - config_create = ConfigCreate([0], [1], 2) + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 2) config = configparser.ConfigParser() config_create.vpe_initialize(config) self.assertEqual(config.get('EAL', 'log_level'), '0') @@ -72,14 +176,16 @@ class TestConfigCreate(unittest.TestCase): self.assertEqual(config.get('MEMPOOL1', 'pool_size'), '2M') def test_vpe_rxq(self): - config_create = ConfigCreate([0], [1, 2], 3) + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 2) config = configparser.ConfigParser() + config_create.downlink_ports = ['xe0'] config_create.vpe_rxq(config) - self.assertEqual(config.get('RXQ1.0', 'mempool'), 'MEMPOOL1') - self.assertEqual(config.get('RXQ2.0', 'mempool'), 'MEMPOOL1') + self.assertEqual(config.get('RXQ0.0', 'mempool'), 'MEMPOOL1') def test_get_sink_swq(self): - config_create = ConfigCreate([0], [1], 2) + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 2) config = configparser.ConfigParser() config.add_section('PIPELINE0') config.set('PIPELINE0', 'key1', 'value1') @@ -96,15 +202,26 @@ class TestConfigCreate(unittest.TestCase): self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key5', 5), 'SWQ0 SINK1') def test_generate_vpe_script(self): - vpe_config_vnf = ConfigCreate([0], [0], 0) + vnfd_helper = VnfdHelper(self.VNFD_0) + vpe_config_vnf = ConfigCreate(vnfd_helper, 2) intf = [ { + "name": 'xe1', + "virtual-interface": { + "dst_ip": "1.1.1.1", + "dst_mac": "00:00:00:00:00:00:02", + }, + }, + { + "name": 'xe2', "virtual-interface": { "dst_ip": "1.1.1.1", "dst_mac": "00:00:00:00:00:00:02", }, }, ] + vpe_config_vnf.downlink_ports = ['xe1'] + vpe_config_vnf.uplink_ports = ['xe2'] result = vpe_config_vnf.generate_vpe_script(intf) self.assertIsInstance(result, str) self.assertNotEqual(result, '') @@ -132,7 +249,10 @@ class TestConfigCreate(unittest.TestCase): }, ] - config_create = ConfigCreate(uplink_ports, downlink_ports, 23) + vnfd_helper = VnfdHelper(self.VNFD_0) + config_create = ConfigCreate(vnfd_helper, 23) + config_create.downlink_ports = ['xe1'] + config_create.uplink_ports = ['xe1'] curr_path = os.path.dirname(os.path.abspath(__file__)) vpe_cfg = "samples/vnf_samples/nsut/vpe/vpe_config" vnf_cfg = os.path.join(curr_path, "../../../../..", vpe_cfg) |