X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Funit%2Fnetwork_services%2Fvnf_generic%2Fvnf%2Ftest_cgnapt_vnf.py;h=f2ce18fb3c3bdf3ca6c22b3f21568e80c6bd4372;hb=7f8f31cf68dbecaf521348fccf540cbe0e7c72bd;hp=e5503697a65e4cee66f012b7c365eef61ad35adb;hpb=3e29adbe7bf52519fbcc86012e2fdafc89d4bbe4;p=yardstick.git diff --git a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py index e5503697a..f2ce18fb3 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py @@ -15,8 +15,7 @@ # limitations under the License. # -from __future__ import absolute_import - +from copy import deepcopy import os import unittest import mock @@ -39,7 +38,7 @@ TEST_FILE_YAML = 'nsb_test_case.yaml' SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' -name = 'vnf__1' +name = 'vnf__0' class TestCgnaptApproxSetupEnvHelper(unittest.TestCase): @@ -66,15 +65,21 @@ link 1 up """ header = "This is a header" - out = CgnaptApproxSetupEnvHelper._update_cgnat_script_file(header, sample.splitlines(), "") + out = CgnaptApproxSetupEnvHelper._update_cgnat_script_file(header, sample.splitlines()) self.assertNotIn("This is a header", out) - def test__get_cgnapt_confgi(self): + def test__get_cgnapt_config(self): + vnfd_helper = mock.MagicMock() + vnfd_helper.port_pairs.uplink_ports = [{"name": 'a'}, {"name": "b"}, {"name": "c"}] + + helper = CgnaptApproxSetupEnvHelper(vnfd_helper, mock.Mock(), mock.Mock()) + result = helper._get_cgnapt_config() + self.assertIsNotNone(result) - c = CgnaptApproxSetupEnvHelper(mock.MagicMock(), mock.MagicMock(), mock.MagicMock()) - c._get_ports_gateway = mock.Mock(return_value=3) - ret = c._get_cgnapt_config([{"name": 'a'}, {}, {"name": "b"}, {}, {"name": "c"}]) - self.assertEqual(ret, [3, 3, 3]) + def test_scale(self): + helper = CgnaptApproxSetupEnvHelper(mock.Mock(), mock.Mock(), mock.Mock()) + with self.assertRaises(NotImplementedError): + helper.scale() @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process") @@ -111,7 +116,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -126,7 +131,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -146,31 +151,48 @@ class TestCgnaptApproxVnf(unittest.TestCase): {'type': 'VPORT', 'name': 'xe1'}], 'id': 'CgnaptApproxVnf', 'name': 'VPEVnfSsh'}]}} - scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4, - 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, - 'vnf__1': {'rules': 'acl_1rule.yaml', - 'vnf_config': {'lb_config': 'SW', - 'lb_count': 1, - 'worker_config': - '1C/1T', - 'worker_threads': 1}} - }, - 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', - 'task_path': '/tmp', - 'tc': 'tc_ipv4_1Mflow_64B_packetsize', - 'runner': {'object': 'NetworkServiceTestCase', - 'interval': 35, - 'output_filename': '/tmp/yardstick.out', - 'runner_id': 74476, 'duration': 400, - 'type': 'Duration'}, - 'traffic_profile': 'ipv4_throughput_acl.yaml', - 'traffic_options': {'flow': 'ipv4_Packets_acl.yaml', - 'imix': 'imix_voice.yaml'}, - 'type': 'ISB', - 'nodes': {'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick'}, - 'topology': 'vpe-tg-topology-baremetal.yaml'} + SCENARIO_CFG = { + 'options': { + 'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1', + }, + 'vnf__0': { + 'napt': 'dynamic', + 'vnf_config': { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': + '1C/1T', + 'worker_threads': 1, + }, + }, + 'flow': {'count': 1, + 'dst_ip': [{'tg__1': 'xe0'}], + 'public_ip': [''], + 'src_ip': [{'tg__0': 'xe0'}]}, + }, + 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', + 'task_path': '/tmp', + 'tc': 'tc_ipv4_1Mflow_64B_packetsize', + 'runner': { + 'object': 'NetworkServiceTestCase', + 'interval': 35, + 'output_filename': '/tmp/yardstick.out', + 'runner_id': 74476, + 'duration': 400, + 'type': 'Duration', + }, + 'traffic_profile': 'ipv4_throughput_acl.yaml', + 'type': 'NSPerf', + 'nodes': { + 'tg__1': 'trafficgen_1.yardstick', + 'tg__0': 'trafficgen_0.yardstick', + 'vnf__0': 'vnf.yardstick', + }, + 'topology': 'vpe-tg-topology-baremetal.yaml', + } context_cfg = {'nodes': {'tg__2': {'member-vnf-index': '3', @@ -180,7 +202,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': CgnaptApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -208,7 +230,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': CgnaptApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -227,13 +249,13 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'password': 'r00t', 'VNF model': 'tg_rfc2544_tpl.yaml', 'user': 'root'}, - 'vnf__1': + 'vnf__0': {'name': 'vnf.yardstick', - 'vnfd-id-ref': 'vnf__1', + 'vnfd-id-ref': 'vnf__0', 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': CgnaptApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -243,7 +265,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'dpdk_port_num': 0}, 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': CgnaptApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -277,18 +299,23 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'password': 'r00t', 'VNF model': 'cgnapt_vnf.yaml'}}} - def test___init__(self, mock_process): + def setUp(self): + self.scenario_cfg = deepcopy(self.SCENARIO_CFG) + + def test___init__(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) self.assertIsNone(cgnapt_approx_vnf._vnf_process) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) - def test_collect_kpi(self, ssh, mock_time, mock_process): + def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) + cgnapt_approx_vnf._vnf_process = mock.MagicMock( + **{"is_alive.return_value": True, "exitcode": None}) cgnapt_approx_vnf.q_in = mock.MagicMock() cgnapt_approx_vnf.q_out = mock.MagicMock() cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0) @@ -296,9 +323,9 @@ class TestCgnaptApproxVnf(unittest.TestCase): result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0} self.assertEqual(result, cgnapt_approx_vnf.collect_kpi()) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) - def test_vnf_execute_command(self, ssh, mock_time, mock_process): + def test_vnf_execute_command(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -310,7 +337,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): self.assertEqual("", cgnapt_approx_vnf.vnf_execute(cmd)) @mock.patch(SSH_HELPER) - def test_get_stats(self, ssh, mock_process): + def test_get_stats(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -332,7 +359,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.eval") @mock.patch('yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.open') @mock.patch(SSH_HELPER) - def test_run_vcgnapt(self, ssh, mock_hex, mock_eval, mock_open, mock_process): + def test_run_vcgnapt(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -347,7 +374,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") @mock.patch(SSH_HELPER) - def test_instantiate(self, ssh, mock_context, mock_process): + def test_instantiate(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -359,19 +386,13 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'rules': ""}} cgnapt_approx_vnf.q_out.put("pipeline>") cgnapt_vnf.WAIT_TIME = 3 - self.scenario_cfg.update({"nodes": {"vnf__1": ""}}) + self.scenario_cfg.update({"nodes": {"vnf__0": ""}}) self.assertIsNone(cgnapt_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg)) - def test_scale(self, mock_process): - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) - flavor = "" - self.assertRaises(NotImplementedError, cgnapt_approx_vnf.scale, flavor) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") @mock.patch(SSH_HELPER) - def test_terminate(self, ssh, mock_time, mock_process): + def test_terminate(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -386,12 +407,13 @@ class TestCgnaptApproxVnf(unittest.TestCase): self.assertEqual(None, cgnapt_approx_vnf.terminate()) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.time") @mock.patch(SSH_HELPER) - def test__vnf_up_post(self, ssh, mock_time, mock_cgnapt_time, mock_process): + def test__vnf_up_post(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + self.scenario_cfg['options'][name]['napt'] = 'static' + cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) cgnapt_approx_vnf._vnf_process = mock.MagicMock() cgnapt_approx_vnf._vnf_process.terminate = mock.Mock() @@ -399,8 +421,17 @@ class TestCgnaptApproxVnf(unittest.TestCase): cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg cgnapt_approx_vnf._resource_collect_stop = mock.Mock() cgnapt_approx_vnf._vnf_up_post() - cgnapt_approx_vnf.vnf_execute.assert_called_once() + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch(SSH_HELPER) + def test__vnf_up_post_short(self, ssh, *args): + mock_ssh(ssh) -if __name__ == '__main__': - unittest.main() + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) + cgnapt_approx_vnf._vnf_process = mock.MagicMock() + cgnapt_approx_vnf._vnf_process.terminate = mock.Mock() + cgnapt_approx_vnf.vnf_execute = mock.MagicMock() + cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg + cgnapt_approx_vnf._resource_collect_stop = mock.Mock() + cgnapt_approx_vnf._vnf_up_post()