From 94612c27db940251eb40018a48be73fc7507d1c4 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Tue, 19 Sep 2017 01:07:15 -0700 Subject: prox: pass prox_config_dict between Processes using queue we generate the prox_config_dict in the _run Process, but we also need it in the _traffic_runner Process to get core info. use a queue to pass the config list between the processes enable collect_kpi Change-Id: Ibaf41d606e559a87addf43d6ddaed206dbd2d20c Signed-off-by: Ross Brattain Signed-off-by: Edward MacGillivray --- .../traffic_profile/test_prox_binsearch.py | 4 +- .../traffic_profile/test_prox_mpls.py | 4 +- .../traffic_profile/test_prox_profile.py | 6 +- .../vnf_generic/vnf/test_prox_helpers.py | 104 +++++++++------------ .../vnf_generic/vnf/test_prox_vnf.py | 10 +- .../vnf_generic/vnf/test_tg_prox.py | 7 +- 6 files changed, 61 insertions(+), 74 deletions(-) (limited to 'tests') 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 0edce7a14..f56a7fba9 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py +++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py @@ -56,7 +56,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) self.assertEqual(round(profile.current_upper, 2), 75.39) self.assertEqual(len(runs), 8) @@ -87,7 +87,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 24.06) self.assertEqual(round(profile.current_upper, 2), 25.47) self.assertEqual(len(runs), 7) 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 77bca9cc0..642fecc35 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py +++ b/tests/unit/network_services/traffic_profile/test_prox_mpls.py @@ -56,7 +56,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 74.69) self.assertEqual(round(profile.current_upper, 2), 75.39) self.assertEqual(len(runs), 8) @@ -87,7 +87,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) self.assertEqual(round(profile.current_lower, 2), 24.06) self.assertEqual(round(profile.current_upper, 2), 25.47) self.assertEqual(len(runs), 7) 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 14223da0f..9899d9909 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -65,7 +65,7 @@ class TestProxProfile(unittest.TestCase): profile.init(234) self.assertEqual(profile.queue, 234) - def test_execute(self): + def test_execute_traffic(self): packet_sizes = [ 10, 100, @@ -83,9 +83,9 @@ class TestProxProfile(unittest.TestCase): self.assertFalse(profile.done) for _ in packet_sizes: with self.assertRaises(NotImplementedError): - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) - self.assertIsNone(profile.execute(traffic_generator)) + self.assertIsNone(profile.execute_traffic(traffic_generator)) def test_bounds_iterator(self): tp_config = { 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 8d21fbb28..2202c11a5 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 @@ -884,11 +884,11 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.upload_prox_config = mock.MagicMock(return_value='5') self.assertEqual(helper.additional_files, {}) - self.assertNotEqual(helper.prox_config_dict, '4') + self.assertNotEqual(helper._prox_config_data, '4') self.assertNotEqual(helper.remote_path, '5') helper.build_config_file() self.assertEqual(helper.additional_files, {}) - self.assertEqual(helper.prox_config_dict, '4') + self.assertEqual(helper._prox_config_data, '4') self.assertEqual(helper.remote_path, '5') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -951,12 +951,12 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.upload_prox_config = mock.MagicMock(return_value='55') self.assertEqual(helper.additional_files, {}) - self.assertNotEqual(helper.prox_config_dict, '44') + self.assertNotEqual(helper._prox_config_data, '44') self.assertNotEqual(helper.remote_path, '55') expected = {'h.i': '33', 'l': '34', 'm_n': '35'} helper.build_config_file() self.assertDictEqual(helper.additional_files, expected) - self.assertEqual(helper.prox_config_dict, '44') + self.assertEqual(helper._prox_config_data, '44') self.assertEqual(helper.remote_path, '55') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -986,9 +986,10 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) helper.remote_path = "/tmp/prox.cfg" - prox_cmd = helper.build_config() expected = "sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli -f -f /tmp/prox.cfg '" - self.assertEqual(prox_cmd, expected) + with mock.patch.object(helper, "build_config_file") as mock_build_config: + prox_cmd = helper.build_config() + self.assertEqual(prox_cmd, expected) def test__insert_additional_file(self): vnfd_helper = mock.MagicMock() @@ -1392,7 +1393,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_test_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.prox_config_data = [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = [] @@ -1401,7 +1402,7 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.test_cores self.assertEqual(result, expected) - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1449,10 +1450,9 @@ class TestProxResourceHelper(unittest.TestCase): def test_get_test_type(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - helper = ProxResourceHelper(setup_helper) - setup_helper.prox_config_dict = [ + + setup_helper.prox_config_data = [ ('global', [ ('name', helper.PROX_CORE_MPLS_TEST) ]), @@ -1479,27 +1479,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_get_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - - helper = ProxResourceHelper(setup_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) - }, - } - } - - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1520,14 +1500,6 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] - expected = [7, 8] - result = helper.get_cores(helper.PROX_CORE_GEN_MODE) - self.assertEqual(result, expected) - - def test_get_cores_mpls(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - helper = ProxResourceHelper(setup_helper) helper._cpu_topology = { 0: { @@ -1546,7 +1518,13 @@ class TestProxResourceHelper(unittest.TestCase): } } - setup_helper.prox_config_dict = [ + expected = [7, 8] + result = helper.get_cores(helper.PROX_CORE_GEN_MODE) + self.assertEqual(result, expected) + + def test_get_cores_mpls(self): + setup_helper = mock.MagicMock() + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1569,6 +1547,24 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] + helper = ProxResourceHelper(setup_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) + }, + } + } + expected_tagged = [7] expected_plain = [8] result_tagged, result_plain = helper.get_cores_mpls(helper.PROX_CORE_GEN_MODE) @@ -1577,7 +1573,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_latency_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.prox_config_data= [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = [] @@ -1586,7 +1582,7 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.latency_cores self.assertEqual(result, expected) - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1649,7 +1645,9 @@ class TestProxResourceHelper(unittest.TestCase): 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() @@ -1681,7 +1679,7 @@ class TestProxResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') def test_traffic_context(self, mock_time): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.vnfd_helper.interfaces = [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = { @@ -1701,7 +1699,7 @@ class TestProxResourceHelper(unittest.TestCase): } } - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('global', [ ('name', helper.PROX_CORE_MPLS_TEST) ]), @@ -1727,8 +1725,6 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] client = mock.MagicMock() client.hz.return_value = 2 @@ -1823,20 +1819,6 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.get_latency() self.assertIs(result, expected) - def test__get_logical_if_name(self): - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] - - helper = ProxResourceHelper(setup_helper) - helper._vpci_to_if_name_map = { - 'key1': 234, - 'key2': 432, - } - - expected = 234 - result = helper._get_logical_if_name('key1') - self.assertEqual(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): diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index d1f7f05d8..f8b592d8c 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -86,6 +86,7 @@ class TestProxApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'vld_id': '', + 'ifname': 'xe1', 'netmask': '255.255.255.0', 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', @@ -104,6 +105,7 @@ class TestProxApproxVnf(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'vld_id': '', + 'ifname': 'xe3', 'driver': "i40e", 'netmask': '255.255.255.0', 'dpdk_port_num': 1, @@ -372,8 +374,10 @@ class TestProxApproxVnf(unittest.TestCase): file_path = os.path.join(curr_path, filename) return file_path + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open', create=True) @mock.patch(SSH_HELPER) - def test_run_prox(self, ssh, mock_time): + def test_run_prox(self, ssh, *_): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) @@ -382,7 +386,7 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg' expected = "sudo bash -c 'cd /tool_path12; " \ - "/tool_path12/tool_file34 -o cli -t -f configs/file56.cfg '" + "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '" prox_approx_vnf._run() result = prox_approx_vnf.ssh_helper.run.call_args[0][0] @@ -395,7 +399,7 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.setup_helper = mock.MagicMock() # we can't mock super prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG) - prox_approx_vnf.setup_helper.build_config.assert_called_once + prox_approx_vnf.setup_helper.build_config.assert_called_once() @mock.patch(SSH_HELPER) def test_wait_for_instantiate_panic(self, ssh, mock_time): diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py index 73e1c723f..4e82c0d5e 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py @@ -331,9 +331,10 @@ class TestProxTrafficGen(unittest.TestCase): mock_ssh(ssh) prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0) - prox_traffic_gen._vnf_wrapper.resource = mock.Mock(autospec=ResourceProfile) + prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock( + **{"check_if_sa_running.return_value": [False]}) prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="") - self.assertEqual({}, prox_traffic_gen.collect_kpi()) + self.assertEqual({"core": {}}, prox_traffic_gen.collect_kpi()) @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -391,10 +392,10 @@ class TestProxTrafficGen(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sut = ProxTrafficGen(NAME, vnfd) - sut.prox_config_dict = {} sut._get_socket = mock.MagicMock() sut.ssh_helper = mock.Mock() sut.ssh_helper.run = mock.Mock() + sut.setup_helper.prox_config_dict = {} sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"] sut._connect_client = mock.Mock(autospec=STLClient) sut._connect_client.get_stats = mock.Mock(return_value="0") -- cgit 1.2.3-korg