summaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services/vnf_generic
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/network_services/vnf_generic')
-rw-r--r--tests/unit/network_services/vnf_generic/test_vnfdgen.py29
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py199
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_base.py54
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py337
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_iniparser.py192
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py1891
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py100
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py610
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py4
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py82
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py43
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py159
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py14
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py423
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py785
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py214
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py224
17 files changed, 3251 insertions, 2109 deletions
diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
index c2b923568..ee881c963 100644
--- a/tests/unit/network_services/vnf_generic/test_vnfdgen.py
+++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
@@ -24,6 +24,10 @@ from six.moves import range
from yardstick.common.yaml_loader import yaml_load
from yardstick.network_services.vnf_generic import vnfdgen
+
+UPLINK = "uplink"
+DOWNLINK = "downlink"
+
TREX_VNFD_TEMPLATE = """
vnfd:vnfd-catalog:
vnfd:
@@ -183,22 +187,23 @@ NODE_CFG = {'ip': '1.1.1.1',
}
+# need to template, but can't use {} so use %s
TRAFFIC_PROFILE_TPL = """
-private:
+%(0)s:
- ipv4:
outer_l2:
framesize:
- 64B: "{{ get(imix, 'private.imix_small', 10) }}"
- 128B: "{{ get(imix, 'private.imix_128B', 10) }}"
- 256B: "{{ get(imix, 'private.imix_256B', 10) }}"
- 373B: "{{ get(imix, 'private.imix_373B', 10) }}"
- 570B: "{{get(imix, 'private.imix_570B', 10) }}"
- 1400B: "{{get(imix, 'private.imix_1400B', 10) }}"
- 1518B: "{{get(imix, 'private.imix_1500B', 40) }}"
-"""
+ 64B: "{{ get(imix, '%(0)s.imix_small', 10) }}"
+ 128B: "{{ get(imix, '%(0)s.imix_128B', 10) }}"
+ 256B: "{{ get(imix, '%(0)s.imix_256B', 10) }}"
+ 373B: "{{ get(imix, '%(0)s.imix_373B', 10) }}"
+ 570B: "{{get(imix, '%(0)s.imix_570B', 10) }}"
+ 1400B: "{{get(imix, '%(0)s.imix_1400B', 10) }}"
+ 1518B: "{{get(imix, '%(0)s.imix_1500B', 40) }}"
+""" % {"0": UPLINK}
TRAFFIC_PROFILE = {
- "private": [{"ipv4": {"outer_l2":
+ UPLINK: [{"ipv4": {"outer_l2":
{"framesize": {"64B": '10', "128B": '10',
"256B": '10', "373B": '10',
"570B": '10', "1400B": '10',
@@ -269,8 +274,8 @@ class TestVnfdGen(unittest.TestCase):
generated_tp = \
vnfdgen.generate_vnfd(TRAFFIC_PROFILE_TPL,
- {"imix": {"private": {"imix_small": '20'}}})
+ {"imix": {UPLINK: {"imix_small": '20'}}})
self.maxDiff = None
tp2 = dict(TRAFFIC_PROFILE)
- tp2["private"][0]["ipv4"]["outer_l2"]["framesize"]["64B"] = '20'
+ tp2[UPLINK][0]["ipv4"]["outer_l2"]["framesize"]["64B"] = '20'
self.assertDictEqual(tp2, generated_tp)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
index 7570067b9..e9444b493 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
@@ -22,6 +22,7 @@ import mock
import os
from tests.unit import STL_MOCKS
+from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
STLClient = mock.MagicMock()
@@ -34,6 +35,7 @@ if stl_patch:
TEST_FILE_YAML = 'nsb_test_case.yaml'
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
name = 'vnf__1'
@@ -73,7 +75,7 @@ class TestAclApproxVnf(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',
@@ -88,7 +90,7 @@ class TestAclApproxVnf(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',
@@ -142,7 +144,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
+ 'vld_id': AclApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -170,7 +172,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
+ 'vld_id': AclApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -195,7 +197,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
+ 'vld_id': AclApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -205,7 +207,7 @@ class TestAclApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'dpdk_port_num': 0},
'xe1': {'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
+ 'vld_id': AclApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -245,52 +247,45 @@ class TestAclApproxVnf(unittest.TestCase):
self.assertIsNone(acl_approx_vnf._vnf_process)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_collect_kpi(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf.q_in = mock.MagicMock()
- acl_approx_vnf.q_out = mock.MagicMock()
- acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- acl_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
- acl_approx_vnf.vnf_execute = mock.Mock(return_value="")
- result = {'packets_dropped': 0, 'packets_fwd': 0,
- 'packets_in': 0}
- self.assertEqual(result, acl_approx_vnf.collect_kpi())
+ @mock.patch(SSH_HELPER)
+ def test_collect_kpi(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf.q_in = mock.MagicMock()
+ acl_approx_vnf.q_out = mock.MagicMock()
+ acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ acl_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
+ acl_approx_vnf.vnf_execute = mock.Mock(return_value="")
+ result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0}
+ self.assertEqual(result, acl_approx_vnf.collect_kpi())
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_vnf_execute_command(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf.q_in = mock.MagicMock()
- acl_approx_vnf.q_out = mock.MagicMock()
- acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- cmd = "quit"
- self.assertEqual("", acl_approx_vnf.vnf_execute(cmd))
+ @mock.patch(SSH_HELPER)
+ def test_vnf_execute_command(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
- def test_get_stats(self, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf.q_in = mock.MagicMock()
- acl_approx_vnf.q_out = mock.MagicMock()
- acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- mock_result = \
- "ACL TOTAL: pkts_processed: 100, pkts_drop: 0, spkts_received: 100"
- acl_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
- self.assertEqual(mock_result, acl_approx_vnf.get_stats())
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf.q_in = mock.MagicMock()
+ acl_approx_vnf.q_out = mock.MagicMock()
+ acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ cmd = "quit"
+ self.assertEqual("", acl_approx_vnf.vnf_execute(cmd))
+
+ @mock.patch(SSH_HELPER)
+ def test_get_stats(self, ssh, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf.q_in = mock.MagicMock()
+ acl_approx_vnf.q_out = mock.MagicMock()
+ acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ result = "ACL TOTAL: pkts_processed: 100, pkts_drop: 0, spkts_received: 100"
+ acl_approx_vnf.vnf_execute = mock.Mock(return_value=result)
+ self.assertEqual(result, acl_approx_vnf.get_stats())
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -300,76 +295,66 @@ class TestAclApproxVnf(unittest.TestCase):
@mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.hex")
@mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.eval")
@mock.patch('yardstick.network_services.vnf_generic.vnf.acl_vnf.open')
- def test_run_acl(self, mock_open, eval, hex, mock_process):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "", ""))
- ssh_mock.run = \
- mock.Mock(return_value=(0, "", ""))
- ssh.from_node.return_value = ssh_mock
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf._build_config = mock.MagicMock()
- acl_approx_vnf.queue_wrapper = mock.MagicMock()
- acl_approx_vnf.ssh_helper = mock.MagicMock()
- acl_approx_vnf.ssh_helper.run = mock.MagicMock()
- acl_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- acl_approx_vnf.vnf_cfg = {'lb_config': 'SW',
- 'lb_count': 1,
- 'worker_config': '1C/1T',
- 'worker_threads': 1}
- acl_approx_vnf.all_options = {'traffic_type': '4',
- 'topology': 'nsb_test_case.yaml'}
- acl_approx_vnf._run()
- acl_approx_vnf.ssh_helper.run.assert_called_once()
+ @mock.patch(SSH_HELPER)
+ def test_run_acl(self, ssh, mock_open, mock_eval, mock_hex, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf._build_config = mock.MagicMock()
+ acl_approx_vnf.queue_wrapper = mock.MagicMock()
+ acl_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
+ acl_approx_vnf.vnf_cfg = {'lb_config': 'SW',
+ 'lb_count': 1,
+ 'worker_config': '1C/1T',
+ 'worker_threads': 1}
+ acl_approx_vnf.all_options = {'traffic_type': '4',
+ 'topology': 'nsb_test_case.yaml'}
+ acl_approx_vnf._run()
+ acl_approx_vnf.ssh_helper.run.assert_called_once()
@mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.YangModel")
@mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.find_relative_file")
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
- def test_instantiate(self, mock_context, mock_yang, mock_find, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf.ssh_helper = ssh
- acl_approx_vnf.deploy_helper = mock.MagicMock()
- acl_approx_vnf.resource_helper = mock.MagicMock()
- acl_approx_vnf._build_config = mock.MagicMock()
- self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
+ @mock.patch(SSH_HELPER)
+ def test_instantiate(self, ssh, mock_context, mock_yang, mock_find, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf.deploy_helper = mock.MagicMock()
+ acl_approx_vnf.resource_helper = mock.MagicMock()
+ acl_approx_vnf._build_config = mock.MagicMock()
+ self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
'rules': ""}}
- acl_approx_vnf.q_out.put("pipeline>")
- acl_approx_vnf.WAIT_TIME = 0
- self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
- self.assertIsNone(acl_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
+ acl_approx_vnf.q_out.put("pipeline>")
+ acl_approx_vnf.WAIT_TIME = 0
+ self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
+ self.assertIsNone(acl_approx_vnf.instantiate(self.scenario_cfg,
+ self.context_cfg))
def test_scale(self, mock_process):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
acl_approx_vnf = AclApproxVnf(name, vnfd)
flavor = ""
- self.assertRaises(NotImplementedError, acl_approx_vnf.scale, flavor)
+ with self.assertRaises(NotImplementedError):
+ acl_approx_vnf.scale(flavor)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_terminate(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
- acl_approx_vnf._vnf_process = mock.MagicMock()
- acl_approx_vnf._vnf_process.terminate = mock.Mock()
- acl_approx_vnf.used_drivers = {"01:01.0": "i40e",
- "01:01.1": "i40e"}
- acl_approx_vnf.vnf_execute = mock.MagicMock()
- acl_approx_vnf.ssh_helper = ssh_mock
- acl_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
- acl_approx_vnf._resource_collect_stop = mock.Mock()
- self.assertEqual(None, acl_approx_vnf.terminate())
+ @mock.patch(SSH_HELPER)
+ def test_terminate(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf._vnf_process = mock.MagicMock()
+ acl_approx_vnf._vnf_process.terminate = mock.Mock()
+ acl_approx_vnf.used_drivers = {"01:01.0": "i40e",
+ "01:01.1": "i40e"}
+ acl_approx_vnf.vnf_execute = mock.MagicMock()
+ acl_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
+ acl_approx_vnf._resource_collect_stop = mock.Mock()
+ self.assertEqual(None, acl_approx_vnf.terminate())
if __name__ == '__main__':
unittest.main()
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_base.py b/tests/unit/network_services/vnf_generic/vnf/test_base.py
index 8a5d836e0..f812d67ef 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_base.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py
@@ -25,6 +25,7 @@ from multiprocessing import Queue
from yardstick.network_services.vnf_generic.vnf.base import \
QueueFileWrapper, GenericVNF, GenericTrafficGen
+from yardstick.ssh import SSH
IP_PIPELINE_CFG_FILE_TPL = """
arp_route_tbl = ({port0_local_ip_hex},{port0_netmask_hex},1,"""
@@ -48,9 +49,9 @@ class FileAbsPath(object):
return file_path
-def mock_ssh(ssh, spec=None, exec_result=_LOCAL_OBJECT, run_result=_LOCAL_OBJECT):
+def mock_ssh(mock_ssh_type, spec=None, exec_result=_LOCAL_OBJECT, run_result=_LOCAL_OBJECT):
if spec is None:
- spec = ssh.SSH
+ spec = SSH
if exec_result is _LOCAL_OBJECT:
exec_result = 0, "", ""
@@ -58,11 +59,12 @@ def mock_ssh(ssh, spec=None, exec_result=_LOCAL_OBJECT, run_result=_LOCAL_OBJECT
if run_result is _LOCAL_OBJECT:
run_result = 0, "", ""
- ssh_mock = mock.Mock(autospec=spec)
- ssh_mock._get_client.return_value = mock.Mock()
- ssh_mock.execute.return_value = exec_result
- ssh_mock.run.return_value = run_result
- ssh.from_node.return_value = ssh_mock
+ mock_ssh_instance = mock.Mock(autospec=spec)
+ mock_ssh_instance._get_client.return_value = mock.Mock()
+ mock_ssh_instance.execute.return_value = exec_result
+ mock_ssh_instance.run.return_value = run_result
+ mock_ssh_type.from_node.return_value = mock_ssh_instance
+ return mock_ssh_instance
class TestQueueFileWrapper(unittest.TestCase):
@@ -148,7 +150,7 @@ class TestGenericVNF(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',
'dst_ip': '152.16.100.20',
'local_mac': '00:00:00:00:00:01'
@@ -163,7 +165,7 @@ class TestGenericVNF(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
'local_mac': '00:00:00:00:00:02'
@@ -241,31 +243,13 @@ class TestGenericVNF(unittest.TestCase):
class TestGenericTrafficGen(unittest.TestCase):
- def test___init__(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- assert generic_traffic_gen.name == "vnf1"
-
- def test_listen_traffic(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertIsNone(generic_traffic_gen.listen_traffic(traffic_profile))
-
- def test_run_traffic(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertRaises(NotImplementedError,
- generic_traffic_gen.run_traffic, traffic_profile)
-
- def test_terminate(self):
- vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- self.assertRaises(NotImplementedError, generic_traffic_gen.terminate)
- def test_verify_traffic(self):
+ def test_definition(self):
+ """Make sure that the abstract class cannot be instantiated"""
vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- generic_traffic_gen = GenericTrafficGen('vnf1', vnfd)
- traffic_profile = {}
- self.assertIsNone(generic_traffic_gen.verify_traffic(traffic_profile))
+ name = 'vnf1'
+ with self.assertRaises(TypeError) as exc:
+ GenericTrafficGen(name, vnfd)
+ msg = ("Can't instantiate abstract class GenericTrafficGen with "
+ "abstract methods run_traffic, terminate")
+ self.assertEqual(msg, str(exc.exception))
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 f214d66f6..832509ea7 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
@@ -21,7 +21,10 @@ import os
import unittest
import mock
+from copy import deepcopy
+
from tests.unit import STL_MOCKS
+from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
STLClient = mock.MagicMock()
@@ -35,9 +38,10 @@ if stl_patch:
from yardstick.network_services.nfvi.resource import ResourceProfile
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):
@@ -64,15 +68,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")
@@ -109,7 +119,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',
@@ -124,7 +134,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',
@@ -144,31 +154,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',
@@ -178,7 +205,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',
@@ -206,7 +233,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',
@@ -225,13 +252,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',
@@ -241,7 +268,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',
@@ -275,57 +302,56 @@ class TestCgnaptApproxVnf(unittest.TestCase):
'password': 'r00t',
'VNF model': 'cgnapt_vnf.yaml'}}}
+ def setUp(self):
+ self.scenario_cfg = deepcopy(self.SCENARIO_CFG)
+
def test___init__(self, mock_process):
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")
- def test_collect_kpi(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- 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)
- cgnapt_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
- 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(SSH_HELPER)
+ def test_collect_kpi(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_vnf_execute_command(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- 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)
- cmd = "quit"
- self.assertEqual("", cgnapt_approx_vnf.vnf_execute(cmd))
-
- def test_get_stats(self, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- 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)
- mock_result = \
- "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
- cgnapt_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
- self.assertListEqual(list(mock_result), list(cgnapt_approx_vnf.get_stats()))
+ 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)
+ cgnapt_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
+ 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(SSH_HELPER)
+ def test_vnf_execute_command(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ 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)
+ cmd = "quit"
+ self.assertEqual("", cgnapt_approx_vnf.vnf_execute(cmd))
+
+ @mock.patch(SSH_HELPER)
+ def test_get_stats(self, ssh, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ 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)
+ result = \
+ "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
+ cgnapt_approx_vnf.vnf_execute = mock.Mock(return_value=result)
+ self.assertListEqual(list(result), list(cgnapt_approx_vnf.get_stats()))
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -335,44 +361,37 @@ class TestCgnaptApproxVnf(unittest.TestCase):
@mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.hex")
@mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.eval")
@mock.patch('yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.open')
- def test_run_vcgnapt(self, hex, eval, mock_open, mock_process):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "", ""))
- ssh_mock.run = \
- mock.Mock(return_value=(0, "", ""))
- ssh.from_node.return_value = ssh_mock
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf._build_config = mock.MagicMock()
- cgnapt_approx_vnf.queue_wrapper = mock.MagicMock()
- cgnapt_approx_vnf.ssh_helper = mock.MagicMock()
- cgnapt_approx_vnf.ssh_helper.run = mock.MagicMock()
- cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- cgnapt_approx_vnf._run()
- cgnapt_approx_vnf.ssh_helper.run.assert_called_once()
+ @mock.patch(SSH_HELPER)
+ def test_run_vcgnapt(self, ssh, mock_hex, mock_eval, mock_open, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf._build_config = mock.MagicMock()
+ cgnapt_approx_vnf.queue_wrapper = mock.MagicMock()
+ cgnapt_approx_vnf.ssh_helper = mock.MagicMock()
+ cgnapt_approx_vnf.ssh_helper.run = mock.MagicMock()
+ cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
+ cgnapt_approx_vnf._run()
+ cgnapt_approx_vnf.ssh_helper.run.assert_called_once()
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
- def test_instantiate(self, mock_context, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf.ssh_helper = ssh
- cgnapt_approx_vnf.deploy_helper = mock.MagicMock()
- cgnapt_approx_vnf.resource_helper = mock.MagicMock()
- cgnapt_approx_vnf._build_config = mock.MagicMock()
- self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
- 'rules': ""}}
- cgnapt_approx_vnf.q_out.put("pipeline>")
- cgnapt_vnf.WAIT_TIME = 3
- self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
- self.assertIsNone(cgnapt_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
+ @mock.patch(SSH_HELPER)
+ def test_instantiate(self, ssh, mock_context, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf.deploy_helper = mock.MagicMock()
+ cgnapt_approx_vnf.resource_helper = mock.MagicMock()
+ cgnapt_approx_vnf._build_config = mock.MagicMock()
+ self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
+ 'rules': ""}}
+ cgnapt_approx_vnf.q_out.put("pipeline>")
+ cgnapt_vnf.WAIT_TIME = 3
+ 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]
@@ -381,42 +400,50 @@ class TestCgnaptApproxVnf(unittest.TestCase):
self.assertRaises(NotImplementedError, cgnapt_approx_vnf.scale, flavor)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_terminate(self, mock_time, mock_process):
- 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
- 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.used_drivers = {"01:01.0": "i40e",
- "01:01.1": "i40e"}
- cgnapt_approx_vnf.vnf_execute = mock.MagicMock()
- cgnapt_approx_vnf.ssh_helper = ssh_mock
- cgnapt_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
- cgnapt_approx_vnf._resource_collect_stop = mock.Mock()
- self.assertEqual(None, cgnapt_approx_vnf.terminate())
+ @mock.patch(SSH_HELPER)
+ def test_terminate(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ 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.used_drivers = {"01:01.0": "i40e",
+ "01:01.1": "i40e"}
+ cgnapt_approx_vnf.vnf_execute = mock.MagicMock()
+ cgnapt_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
+ cgnapt_approx_vnf._resource_collect_stop = mock.Mock()
+ self.assertEqual(None, cgnapt_approx_vnf.terminate())
+
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
+ @mock.patch(SSH_HELPER)
+ def test__vnf_up_post(self, ssh, mock_time, mock_process):
+ 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()
+ 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()
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.time")
- def test__vnf_up_post(self, mock_time, mock_cgnapt_time, mock_process):
- 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
- 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.ssh_helper = ssh_mock
- 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(SSH_HELPER)
+ def test__vnf_up_post_short(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ 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()
if __name__ == '__main__':
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py b/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
deleted file mode 100644
index b74e5d9fd..000000000
--- a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
+++ /dev/null
@@ -1,192 +0,0 @@
-# Copyright (c) 2017 Intel Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-from __future__ import absolute_import
-
-import unittest
-from contextlib import contextmanager
-import mock
-
-from tests.unit import STL_MOCKS
-
-
-STLClient = mock.MagicMock()
-stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
-stl_patch.start()
-
-if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.iniparser import ParseError
- from yardstick.network_services.vnf_generic.vnf.iniparser import BaseParser
- from yardstick.network_services.vnf_generic.vnf.iniparser import ConfigParser
-
-PARSE_TEXT_1 = """\
-
-[section1]
-key1=value1
-list1: value2
- value3
- value4
-key2="double quote value"
-key3='single quote value' ; comment here
-key4=
-
-[section2]
-# here is a comment line
-list2: value5
-; another comment line
-key5=
-"""
-
-PARSE_TEXT_2 = """\
-[section1]
-list1 = item1
- item2
- ended by eof"""
-
-PARSE_TEXT_BAD_1 = """\
-key1=value1
-"""
-
-PARSE_TEXT_BAD_2 = """\
-[section1
-"""
-
-PARSE_TEXT_BAD_3 = """\
-[]
-"""
-
-PARSE_TEXT_BAD_4 = """\
-[section1]
-no list or key
-"""
-
-PARSE_TEXT_BAD_5 = """\
-[section1]
- bad continuation
-"""
-
-PARSE_TEXT_BAD_6 = """\
-[section1]
-=value with no key
-"""
-
-
-class TestParseError(unittest.TestCase):
-
- def test___str__(self):
- error = ParseError('a', 2, 'c')
- self.assertEqual(str(error), "at line 2, a: 'c'")
-
-
-class TestBaseParser(unittest.TestCase):
-
- @staticmethod
- def make_open(text_blob):
- @contextmanager
- def internal_open(*args, **kwargs):
- yield text_blob.split('\n')
-
- return internal_open
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
- def test_parse_none(self, mock_open):
- mock_open.side_effect = self.make_open('')
-
- parser = BaseParser()
-
- self.assertIsNone(parser.parse())
-
- def test_not_implemented_methods(self):
- parser = BaseParser()
-
- with self.assertRaises(NotImplementedError):
- parser.assignment('key', 'value')
-
- with self.assertRaises(NotImplementedError):
- parser.new_section('section')
-
-
-class TestConfigParser(unittest.TestCase):
-
- @staticmethod
- def make_open(text_blob):
- @contextmanager
- def internal_open(*args, **kwargs):
- yield text_blob.split('\n')
-
- return internal_open
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
- def test_parse(self, mock_open):
- mock_open.side_effect = self.make_open(PARSE_TEXT_1)
-
- config_parser = ConfigParser('my_file', {})
- config_parser.parse()
-
- expected = {
- 'section1': [
- ['key1', 'value1'],
- ['list1', 'value2\nvalue3\nvalue4'],
- ['key2', 'double quote value'],
- ['key3', 'single quote value'],
- ['key4', ''],
- ],
- 'section2': [
- ['list2', 'value5'],
- ['key5', ''],
- ],
- }
-
- self.assertDictEqual(config_parser.sections, expected)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
- def test_parse_2(self, mock_open):
- mock_open.side_effect = self.make_open(PARSE_TEXT_2)
-
- config_parser = ConfigParser('my_file', {})
- config_parser.parse()
-
- expected = {
- 'section1': [
- ['list1', 'item1\nitem2\nended by eof'],
- ],
- }
-
- self.assertDictEqual(config_parser.sections, expected)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
- def test_parse_negative(self, mock_open):
- bad_text_dict = {
- 'no section': PARSE_TEXT_BAD_1,
- 'incomplete section': PARSE_TEXT_BAD_2,
- 'empty section name': PARSE_TEXT_BAD_3,
- 'no list or key': PARSE_TEXT_BAD_4,
- 'bad_continuation': PARSE_TEXT_BAD_5,
- 'value with no key': PARSE_TEXT_BAD_6,
- }
-
- for bad_reason, bad_text in bad_text_dict.items():
- mock_open.side_effect = self.make_open(bad_text)
-
- config_parser = ConfigParser('my_file', {})
-
- try:
- # TODO: replace with assertRaises, when the UT framework supports
- # advanced messages when exceptions fail to occur
- config_parser.parse()
- except ParseError:
- pass
- else:
- self.fail('\n'.join([bad_reason, bad_text, str(config_parser.sections)]))
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 98eccae4f..84eb5dc0d 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
@@ -20,13 +20,11 @@ from __future__ import absolute_import
import os
import socket
import unittest
-from collections import OrderedDict
from itertools import repeat, chain
-from contextlib import contextmanager
import mock
from tests.unit import STL_MOCKS
-
+from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
@@ -40,11 +38,16 @@ 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
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxVpeProfileHelper
+ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxlwAFTRProfileHelper
class TestCoreTuple(unittest.TestCase):
-
def test___init__(self):
core_tuple = CoreSocketTuple('core 5s6')
self.assertEqual(core_tuple.core_id, 5)
@@ -65,7 +68,6 @@ class TestCoreTuple(unittest.TestCase):
'5s6',
'core',
'core h',
- 'core 5',
'core 5s',
'core 5 6',
'core 5 6h',
@@ -125,7 +127,6 @@ class TestCoreTuple(unittest.TestCase):
class TestTotStatsTuple(unittest.TestCase):
-
def test___new___negative(self):
with self.assertRaises(TypeError):
# no values
@@ -141,7 +142,6 @@ class TestTotStatsTuple(unittest.TestCase):
class TestProxTestDataTuple(unittest.TestCase):
-
def test___init__(self):
prox_test_data = ProxTestDataTuple(1, 2, 3, 4, 5, 6, 7, 8, 9)
self.assertEqual(prox_test_data.tolerated, 1)
@@ -179,11 +179,12 @@ class TestProxTestDataTuple(unittest.TestCase):
"TxThroughput": 9 / 1e6,
"RxThroughput": 1.6 / 1e6,
"PktSize": 64,
+ "PortSample": 1,
"LatencyMin": 6.1,
"LatencyMax": 6.9,
"LatencyAvg": 6.4,
}
- result = prox_test_data.get_samples(64)
+ result = prox_test_data.get_samples(64, port_samples={"PortSample": 1})
self.assertDictEqual(result, expected)
expected = {
@@ -215,7 +216,6 @@ class TestProxTestDataTuple(unittest.TestCase):
class TestPacketDump(unittest.TestCase):
-
PAYLOAD = "payload"
def test__init__(self):
@@ -290,7 +290,6 @@ no data length value
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
class TestProxSocketHelper(unittest.TestCase):
-
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
def test___init__(self, mock_socket, mock_time):
expected = mock_socket.socket()
@@ -375,6 +374,13 @@ class TestProxSocketHelper(unittest.TestCase):
prox.put_command("data")
mock_socket.sendall.assert_called_once()
+ def test_put_command_socket_error(self, mock_time):
+ mock_socket = mock.MagicMock()
+ mock_socket.sendall.side_effect = OSError
+ prox = ProxSocketHelper(mock_socket)
+ prox.put_command("data")
+ mock_socket.sendall.assert_called_once()
+
def test_get_packet_dump(self, mock_time):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
@@ -475,11 +481,11 @@ class TestProxSocketHelper(unittest.TestCase):
def test_lat_stats(self, mock_time):
latency_output = [
- '1, 2 , 3', # has white space
- '4,5', # too short
+ '1, 2 , 3', # has white space
+ '4,5', # too short
'7,8,9,10.5,11', # too long with float, but float is in unused portion
- 'twelve,13,14', # value as English word
- '15,16.2,17', # float in used portion
+ 'twelve,13,14', # value as English word
+ '15,16.2,17', # float in used portion
]
mock_socket = mock.MagicMock()
@@ -504,6 +510,14 @@ class TestProxSocketHelper(unittest.TestCase):
self.assertEqual(mock_socket.sendall.call_count, 5)
self.assertEqual(result, expected)
+ def test_get_all_tot_stats_error(self, mock_time):
+ mock_socket = mock.MagicMock()
+ prox = ProxSocketHelper(mock_socket)
+ prox.get_data = mock.MagicMock(return_value='3,4,5')
+ expected = [0, 0, 0, 0]
+ result = prox.get_all_tot_stats()
+ self.assertEqual(result, expected)
+
def test_get_all_tot_stats(self, mock_time):
mock_socket = mock.MagicMock()
prox = ProxSocketHelper(mock_socket)
@@ -520,20 +534,6 @@ class TestProxSocketHelper(unittest.TestCase):
result = prox.hz()
self.assertEqual(result, expected)
- def test_rx_stats(self, mock_time):
- core_stats = [
- '3,4,5,6',
- '7,8,9,10,NaN',
- '11,12,13,14,15',
- ]
-
- mock_socket = mock.MagicMock()
- prox = ProxSocketHelper(mock_socket)
- prox.get_data = mock.MagicMock(side_effect=core_stats)
- expected = 21, 24, 27, 14
- result = prox.rx_stats([3, 4, 5], 16)
- self.assertEqual(result, expected)
-
def test_core_stats(self, mock_time):
core_stats = [
'3,4,5,6',
@@ -627,78 +627,252 @@ class TestProxSocketHelper(unittest.TestCase):
class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
- def test_rebind_drivers(self):
- def find_drivers(*args, **kwargs):
- setup_helper.used_drivers = used_drivers
+ VNFD0 = {
+ 'short-name': 'ProxVnf',
+ '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': 'PROX approximation using DPDK',
+ 'name': 'proxvnf-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': 'proxvnf-baremetal',
+ 'external-interface': [
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:04',
+ 'vpci': '0000:05:00.0',
+ 'local_ip': '152.16.100.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'uplink_0',
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 0,
+ 'bandwidth': '10 Gbps',
+ 'driver': "i40e",
+ 'dst_ip': '152.16.100.19',
+ 'local_iface_name': 'xe0',
+ 'local_mac': '00:00:00:00:00:02',
+ 'ifname': 'xe0',
+ },
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0',
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:03',
+ 'vpci': '0000:05:00.1',
+ 'local_ip': '152.16.40.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'downlink_0',
+ 'driver': "i40e",
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 1,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_iface_name': 'xe1',
+ 'local_mac': '00:00:00:00:00:01',
+ 'ifname': 'xe1',
+ },
+ 'vnfd-connection-point-ref': 'xe1',
+ 'name': 'xe1',
+ },
+ ],
+ },
+ ],
+ 'description': 'PROX approximation using DPDK',
+ 'mgmt-interface': {
+ 'vdu-id': 'proxvnf-baremetal',
+ 'host': '1.2.1.1',
+ 'password': 'r00t',
+ 'user': 'root',
+ 'ip': '1.2.1.1',
+ },
+ 'benchmark': {
+ 'kpi': [
+ 'packets_in',
+ 'packets_fwd',
+ 'packets_dropped',
+ ],
+ },
+ 'id': 'ProxApproxVnf',
+ 'name': 'ProxVnf',
+ }
+
+ VNFD = {
+ 'vnfd:vnfd-catalog': {
+ 'vnfd': [
+ VNFD0,
+ ],
+ },
+ }
- used_drivers = {
- 'a': (1, 'b'),
- 'c': (2, 'd'),
- }
+ def test_global_section(self):
+ setup_helper = ProxDpdkVnfSetupEnvHelper(mock.MagicMock(), mock.MagicMock(),
+ mock.MagicMock())
- vnfd_helper = mock.MagicMock()
- ssh_helper = mock.MagicMock()
- scenario_helper = mock.MagicMock()
- setup_helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- setup_helper._find_used_drivers = mock_find = mock.MagicMock(side_effect=find_drivers)
+ setup_helper._prox_config_data = [('a', [])]
- setup_helper.rebind_drivers()
- self.assertEqual(mock_find.call_count, 1)
- self.assertEqual(ssh_helper.execute.call_count, 2)
- self.assertIn('--force', ssh_helper.execute.call_args[0][0])
+ with self.assertRaises(KeyError):
+ _ = setup_helper.global_section
- mock_find.reset_mock()
- ssh_helper.execute.reset_mock()
- setup_helper.rebind_drivers(False)
- self.assertEqual(mock_find.call_count, 0)
- self.assertEqual(ssh_helper.execute.call_count, 2)
- self.assertNotIn('--force', ssh_helper.execute.call_args[0][0])
+ 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])
-class TestProxResourceHelper(unittest.TestCase):
+ 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 = ''
expected = ''
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat')
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat')
self.assertEqual(result, expected)
# no quoted substring
input_str = 'lion tiger bear'
expected = 'lion tiger bear'
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat')
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat')
self.assertEqual(result, expected)
# partially quoted substring
input_str = 'lion "tiger bear'
expected = 'lion "tiger bear'
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat')
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat')
self.assertEqual(result, expected)
# one quoted substring
input_str = 'lion "tiger" bear'
expected = 'lion "cat" bear'
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat')
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat')
self.assertEqual(result, expected)
# two quoted substrings
input_str = 'lion "tiger" bear "shark" whale'
expected = 'lion "cat" bear "shark" whale'
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat')
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat')
self.assertEqual(result, expected)
# two quoted substrings, both replaced
input_str = 'lion "tiger" bear "shark" whale'
expected = 'lion "cat" bear "cat" whale'
- result = ProxResourceHelper._replace_quoted_with_value(input_str, 'cat', 2)
+ result = ProxDpdkVnfSetupEnvHelper._replace_quoted_with_value(input_str, 'cat', 2)
self.assertEqual(result, expected)
def test__get_tx_port(self):
# no data
input_data = {'section1': []}
expected = -1
- result = ProxResourceHelper._get_tx_port('section1', input_data)
+ result = ProxDpdkVnfSetupEnvHelper._get_tx_port('section1', input_data)
self.assertEqual(result, expected)
# data for other section
@@ -710,7 +884,7 @@ class TestProxResourceHelper(unittest.TestCase):
],
}
expected = -1
- result = ProxResourceHelper._get_tx_port('section1', input_data)
+ result = ProxDpdkVnfSetupEnvHelper._get_tx_port('section1', input_data)
self.assertEqual(result, expected)
# data for section
@@ -719,7 +893,7 @@ class TestProxResourceHelper(unittest.TestCase):
('tx port', '3'),
]
expected = 3
- result = ProxResourceHelper._get_tx_port('section1', input_data)
+ result = ProxDpdkVnfSetupEnvHelper._get_tx_port('section1', input_data)
self.assertEqual(result, expected)
# more data for section,
@@ -728,14 +902,500 @@ class TestProxResourceHelper(unittest.TestCase):
('tx port', '1', 'and more', 234),
])
expected = 1
- result = ProxResourceHelper._get_tx_port('section1', input_data)
+ result = ProxDpdkVnfSetupEnvHelper._get_tx_port('section1', input_data)
+ self.assertEqual(result, expected)
+
+ def test_write_prox_config(self):
+ input_data = {}
+ expected = ''
+ result = ProxDpdkVnfSetupEnvHelper.write_prox_config(input_data)
+ self.assertEqual(result, expected)
+
+ input_data = [
+ [
+ 'section1',
+ [],
+ ],
+ ]
+ expected = '[section1]'
+ result = ProxDpdkVnfSetupEnvHelper.write_prox_config(input_data)
+ self.assertEqual(result, expected)
+
+ input_data = [
+ [
+ 'section1',
+ [],
+ ],
+ [
+ 'section2',
+ [
+ ['key1', 'value1'],
+ ['__name__', 'not this one'],
+ ['key2', None],
+ ['key3', 234],
+ ['key4', 'multi-line\nvalue'],
+ ],
+ ],
+ ]
+ expected = os.linesep.join([
+ '[section1]',
+ '[section2]',
+ 'key1=value1',
+ 'key2',
+ 'key3=234',
+ 'key4=multi-line\n\tvalue',
+ ])
+ 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 = {
+ 'prox_args': {'-c': ""},
+ 'prox_path': 'd',
+ 'prox_config': 'e/f',
+ 'prox_generate_parameter': False,
+ }
+
+ mock_find_path.side_effect = ['1', '2']
+
+ vnfd_helper = mock.MagicMock()
+ ssh_helper = mock.MagicMock()
+ scenario_helper = ScenarioHelper('vnf1')
+ scenario_helper.scenario_cfg = {
+ 'task_path': 'a/b',
+ 'options': {
+ 'vnf1': vnf1,
+ },
+ }
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.copy_to_target = mock.MagicMock(return_value='3')
+ helper.generate_prox_config_file = mock.MagicMock(return_value='4')
+ helper.upload_prox_config = mock.MagicMock(return_value='5')
+
+ self.assertEqual(helper.additional_files, {})
+ 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_data, '4')
+ self.assertEqual(helper.remote_path, '5')
+
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
+ def test_build_config_file_additional_file_string(self, mock_find_path):
+ vnf1 = {
+ 'prox_args': {'-c': ""},
+ 'prox_path': 'd',
+ 'prox_config': 'e/f',
+ 'prox_files': 'g/h.i',
+ 'prox_generate_parameter': True,
+ }
+
+ mock_find_path.side_effect = ['1', '2']
+ vnfd_helper = mock.MagicMock()
+ ssh_helper = mock.MagicMock()
+ scenario_helper = ScenarioHelper('vnf1')
+ scenario_helper.scenario_cfg = {
+ 'task_path': 'a/b',
+ 'options': {
+ 'vnf1': vnf1,
+ },
+ }
+
+ vnfd_helper.port_pairs.all_ports = ['xe0', 'xe1', 'xe2', 'xe3']
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.copy_to_target = mock.MagicMock(side_effect=['33', '34', '35'])
+ helper.generate_prox_config_file = mock.MagicMock(return_value='44')
+ helper.upload_prox_config = mock.MagicMock(return_value='55')
+
+ self.assertEqual(helper.additional_files, {})
+ expected = {'h.i': '33'}
+ helper.build_config_file()
+ self.assertDictEqual(helper.additional_files, expected)
+
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
+ def test_build_config_file_additional_file(self, mock_find_path):
+ vnf1 = {
+ 'prox_args': {'-c': ""},
+ 'prox_path': 'd',
+ 'prox_config': 'e/f',
+ 'prox_files': [
+ 'g/h.i',
+ 'j/k/l',
+ 'm_n',
+ ],
+ }
+
+ mock_find_path.side_effect = ['1', '2'] + [str(i) for i in range(len(vnf1['prox_files']))]
+ vnfd_helper = mock.MagicMock()
+ ssh_helper = mock.MagicMock()
+ scenario_helper = ScenarioHelper('vnf1')
+ scenario_helper.scenario_cfg = {
+ 'task_path': 'a/b',
+ 'options': {
+ 'vnf1': vnf1,
+ },
+ }
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.copy_to_target = mock.MagicMock(side_effect=['33', '34', '35'])
+ helper.generate_prox_config_file = mock.MagicMock(return_value='44')
+ helper.upload_prox_config = mock.MagicMock(return_value='55')
+
+ self.assertEqual(helper.additional_files, {})
+ 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_data, '44')
+ self.assertEqual(helper.remote_path, '55')
+
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
+ def test_build_config(self, mock_find_path):
+ vnf1 = {
+ 'prox_args': {'-f': ""},
+ 'prox_path': '/opt/nsb_bin/prox',
+ 'prox_config': 'configs/gen_l2fwd-2.cfg',
+ 'prox_files': [
+ 'g/h.i',
+ 'j/k/l',
+ 'm_n',
+ ],
+ }
+
+ mock_find_path.side_effect = ['1', '2']
+ vnfd_helper = mock.MagicMock()
+ ssh_helper = mock.MagicMock()
+ ssh_helper.provision_tool.return_value = "/opt/nsb_bin/prox"
+ scenario_helper = ScenarioHelper('vnf1')
+ scenario_helper.scenario_cfg = {
+ 'task_path': 'a/b',
+ 'options': {
+ 'vnf1': vnf1,
+ },
+ }
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.remote_path = "/tmp/prox.cfg"
+ expected = "sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli -f -f /tmp/prox.cfg '"
+ 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()
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.additional_files = {"ipv4.lua": "/tmp/ipv4.lua"}
+ res = helper._insert_additional_file('dofile("ipv4.lua")')
+ self.assertEqual(res, 'dofile("/tmp/ipv4.lua")')
+
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
+ def test_generate_prox_config_file(self, mock_parser_type):
+ def init(*args):
+ if sections_data:
+ args[-1].extend(sections_data)
+ return mock.MagicMock()
+
+ sections_data = []
+
+ mock_parser_type.side_effect = init
+
+ vnfd_helper = VnfdHelper(self.VNFD0)
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.additional_files = {}
+
+ expected = []
+ result = helper.generate_prox_config_file('a/b')
+ self.assertEqual(result, expected)
+
+ helper.additional_files = {"ipv4.lua": "/tmp/ipv4.lua"}
+
+ helper.remote_prox_file_name = 'remote'
+ sections_data = [
+ [
+ 'lua',
+ [
+ ['dofile("ipv4.lua")', ''],
+ ],
+ ],
+ [
+ 'port 0',
+ [
+ ['ip', ''],
+ ['mac', 'foo'],
+ ['dst mac', '@@1'],
+ ['tx port', '1'],
+ ],
+ ],
+ [
+ 'port 2',
+ [
+ ['ip', ''],
+ ['$sut_mac0', '@@dst_mac0'],
+ ['tx port', '0'],
+ ['single', '@'],
+ ['user_table', 'dofile("ipv4.lua")'],
+ ['missing_addtional_file', 'dofile("nosuch")'],
+ ],
+ ],
+ ]
+
+ expected = [
+ [
+ 'lua',
+ [
+ ['dofile("/tmp/ipv4.lua")', ''],
+ ],
+ ],
+ [
+ 'port 0',
+ [
+ ['ip', ''],
+ ['mac', 'hardware'],
+ ['dst mac', '00:00:00:00:00:03'],
+ ['tx port', '1'],
+ ],
+ ],
+ [
+ 'port 2',
+ [
+ ['ip', ''],
+ ['$sut_mac0', '00 00 00 00 00 04'],
+ ['tx port', '0'],
+ ['single', '@'],
+ ['user_table', 'dofile("/tmp/ipv4.lua")'],
+ ['missing_addtional_file', 'dofile("nosuch")'],
+ ],
+ ],
+ ]
+ result = helper.generate_prox_config_file('/c/d/e')
+ self.assertEqual(result, expected, str(result))
+
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
+ def test_generate_prox_config_file_negative(self, mock_parser_type):
+ def init(*args):
+ args[-1].update(sections_data)
+ return mock.MagicMock()
+
+ sections_data = {}
+
+ mock_parser_type.side_effect = init
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.additional_files = {}
+ helper.remote_prox_file_name = 'remote'
+ vnfd_helper.interfaces = [
+ {
+ 'virtual-interface': {
+ 'dpdk_port_num': 3,
+ 'dst_mac': '00:00:00:de:ad:88',
+ },
+ },
+ {
+ 'virtual-interface': {
+ 'dpdk_port_num': 5,
+ 'dst_mac': '00:00:00:de:ad:ff',
+ },
+ },
+ {
+ 'virtual-interface': {
+ 'dpdk_port_num': 7,
+ 'dst_mac': '00:00:00:de:ad:ff',
+ },
+ },
+ ]
+ sections_data = {
+ 'port 3': [
+ ['ip', ''],
+ ['mac', 'foo'],
+ ['dst mac', ''],
+ ],
+ 'port 5': [
+ ['ip', ''],
+ ['dst mac', ''],
+ ['tx port', '0'],
+ ['???', 'dofile "here" 23'],
+ ],
+ }
+
+ with self.assertRaises(Exception):
+ helper.generate_prox_config_file('a/b')
+
+ def test_put_string_to_file(self):
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+
+ expected = 'a/b'
+ result = helper.put_string_to_file('my long string', 'a/b')
self.assertEqual(result, expected)
- def test_line_rate_to_pps(self):
- expected = 0.25 * 1e8
- result = ProxResourceHelper.line_rate_to_pps(180, 4)
+ def test__build_pipeline_kwarags(self):
+ vnfd_helper = mock.MagicMock()
+ ssh_helper = mock.MagicMock()
+ ssh_helper.provision_tool.return_value = "/tmp/nosuch"
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper._build_pipeline_kwargs()
+ self.assertEqual(helper.pipeline_kwargs, {'tool_path': '/tmp/nosuch', 'tool_dir': '/tmp'})
+
+ def test_copy_to_target(self):
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ expected = '/tmp/c'
+ result = helper.copy_to_target('a/b', 'c')
+ self.assertEqual(result, expected)
+
+ def test_upload_prox_config(self):
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.write_prox_config = mock.MagicMock(return_value='a long string')
+ expected = '/tmp/a'
+ result = helper.upload_prox_config('a', {})
self.assertEqual(result, expected)
+
+class TestProxResourceHelper(unittest.TestCase):
+
+ VNFD0 = {
+ 'short-name': 'ProxVnf',
+ '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': 'PROX approximation using DPDK',
+ 'name': 'proxvnf-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': 'proxvnf-baremetal',
+ 'external-interface': [
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:04',
+ 'vpci': '0000:05:00.0',
+ 'local_ip': '152.16.100.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'uplink_0',
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 0,
+ 'bandwidth': '10 Gbps',
+ 'driver': "i40e",
+ 'dst_ip': '152.16.100.19',
+ 'local_iface_name': 'xe0',
+ 'local_mac': '00:00:00:00:00:02',
+ 'ifname': 'xe0',
+ },
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0',
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:03',
+ 'vpci': '0000:05:00.1',
+ 'local_ip': '152.16.40.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'downlink_0',
+ 'driver': "i40e",
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 1,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_iface_name': 'xe1',
+ 'local_mac': '00:00:00:00:00:01',
+ 'ifname': 'xe1',
+ },
+ 'vnfd-connection-point-ref': 'xe1',
+ 'name': 'xe1',
+ },
+ ],
+ },
+ ],
+ 'description': 'PROX approximation using DPDK',
+ 'mgmt-interface': {
+ 'vdu-id': 'proxvnf-baremetal',
+ 'host': '1.2.1.1',
+ 'password': 'r00t',
+ 'user': 'root',
+ 'ip': '1.2.1.1',
+ },
+ 'benchmark': {
+ 'kpi': [
+ 'packets_in',
+ 'packets_fwd',
+ 'packets_dropped',
+ ],
+ },
+ 'id': 'ProxApproxVnf',
+ 'name': 'ProxVnf',
+ }
+
+ VNFD = {
+ 'vnfd:vnfd-catalog': {
+ 'vnfd': [
+ VNFD0,
+ ],
+ },
+ }
+
def test_find_pci(self):
input_str_list = [
'no target here',
@@ -754,43 +1414,9 @@ class TestProxResourceHelper(unittest.TestCase):
result = ProxResourceHelper.find_pci('target', input_str_list)
self.assertTrue(result)
- def test_write_prox_config(self):
- input_data = {}
- expected = ''
- result = ProxResourceHelper.write_prox_config(input_data)
- self.assertEqual(result, expected)
-
- input_data = {
- 'section1': [],
- }
- expected = '[section1]'
- result = ProxResourceHelper.write_prox_config(input_data)
- self.assertEqual(result, expected)
-
- input_data = OrderedDict([
- ('section1', []),
- (
- 'section2', [
- ('key1', 'value1'),
- ('__name__', 'not this one'),
- ('key2', None),
- ('key3', 234),
- ('key4', 'multi-line\nvalue'),
- ]
- )
- ])
- expected = os.linesep.join([
- '[section1]',
- '[section2]',
- 'key1=value1',
- 'key2',
- 'key3=234',
- 'key4=multi-line\n\tvalue',
- ])
- result = ProxResourceHelper.write_prox_config(input_data)
- self.assertEqual(result, expected)
-
- def test_sut(self):
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.RETRY_INTERVAL', 0)
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper')
+ def test_sut(self, mock_socket_helper):
helper = ProxResourceHelper(mock.MagicMock())
self.assertIsNone(helper.client)
result = helper.sut
@@ -798,68 +1424,277 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper.client)
self.assertIs(result, helper.sut)
- @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
-
+ def test_test_type(self):
setup_helper = mock.MagicMock()
- setup_helper.ssh_helper.execute.return_value = 0, 'output', ''
+ setup_helper.find_in_section.return_value = expected = 'prox type'
helper = ProxResourceHelper(setup_helper)
- self.assertIsNone(helper._cpu_topology)
- result = helper.cpu_topology
- self.assertEqual(result, 432)
- self.assertIs(result, helper._cpu_topology)
- self.assertIs(result, helper.cpu_topology)
- def test_vpci_to_if_name_map(self):
+ 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.check_if_sa_running.return_value = 0, '1234'
+ resource.amqp_collect_nfvi_kpi.return_value = 543
+ resource.check_if_sa_running.return_value = (0, None)
+
+ 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.check_if_sa_running.return_value = 0, '1234'
+ resource.amqp_collect_nfvi_kpi.return_value = 543
+ resource.check_if_sa_running.return_value = (0, None)
+
+ 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)
- self.assertIsNone(helper._vpci_to_if_name_map)
- result = helper.vpci_to_if_name_map
- self.assertEqual(result, {})
- self.assertIs(result, helper._vpci_to_if_name_map)
- self.assertIs(result, helper.vpci_to_if_name_map)
- setup_helper.vnfd_helper.interfaces = [
- {
- 'name': 'vnf1',
- 'virtual-interface': {
- 'vpci': '0000:01.02.03',
- },
+ 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,
},
- {
- 'name': 'vnf2',
- 'virtual-interface': {
- 'vpci': '0000:04.05.06',
- },
+ 'xe2': {
+ 'in_packets': 6,
+ 'out_packets': 7,
},
- ]
- expected = {
- '0000:01.02.03': 'vnf1',
- '0000:04.05.06': 'vnf2',
}
- helper = ProxResourceHelper(setup_helper)
- self.assertIsNone(helper._vpci_to_if_name_map)
- result = helper.vpci_to_if_name_map
+ result = data_helper.samples
self.assertDictEqual(result, expected)
- self.assertIs(result, helper._vpci_to_if_name_map)
- self.assertIs(result, helper.vpci_to_if_name_map)
+
+ 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
+
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.ssh_helper.execute.return_value = 0, 'output', ''
+
+ helper = ProxProfileHelper(resource_helper)
+ self.assertIsNone(helper._cpu_topology)
+ result = helper.cpu_topology
+ self.assertEqual(result, 432)
+ self.assertIs(result, helper._cpu_topology)
+ self.assertIs(result, helper.cpu_topology)
def test_test_cores(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = {}
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.prox_config_data = []
+
+ helper = ProxProfileHelper(resource_helper)
helper._cpu_topology = []
expected = []
result = helper.test_cores
self.assertEqual(result, expected)
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = OrderedDict([
+ resource_helper.setup_helper.prox_config_data = [
('section1', []),
('section2', [
('a', 'b'),
@@ -878,7 +1713,9 @@ class TestProxResourceHelper(unittest.TestCase):
('index', 7),
('mode', 'gen'),
]),
- ])
+ ]
+
+ helper = ProxProfileHelper(resource_helper)
helper._cpu_topology = {
1: {
3: {
@@ -904,17 +1741,17 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper.test_cores)
def test_latency_cores(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = {}
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.prox_config_data = []
+
+ helper = ProxProfileHelper(resource_helper)
helper._cpu_topology = []
expected = []
result = helper.latency_cores
self.assertEqual(result, expected)
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = OrderedDict([
+ resource_helper.setup_helper.prox_config_data = [
('section1', []),
('section2', [
('a', 'b'),
@@ -933,7 +1770,9 @@ class TestProxResourceHelper(unittest.TestCase):
('index', 7),
('mode', 'lat'),
]),
- ])
+ ]
+
+ helper = ProxProfileHelper(resource_helper)
helper._cpu_topology = {
1: {
3: {
@@ -958,398 +1797,522 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper._latency_cores)
self.assertIs(result, helper.latency_cores)
- def test_start_collect(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- self.assertIsNone(helper.start_collect())
-
- def test_terminate(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- self.assertIsNone(helper.terminate())
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
- def test_get_process_args_no_additional_file(self, mock_find_path):
- vnf1 = {
- 'prox_args': 'c',
- 'prox_path': 'd',
- 'prox_config': 'e/f',
- }
-
- mock_find_path.side_effect = ['1', '2']
- setup_helper = mock.MagicMock()
- setup_helper.scenario_helper = ScenarioHelper('vnf1')
- setup_helper.scenario_helper.scenario_cfg = {
- 'task_path': 'a/b',
- 'options': {
- 'vnf1': vnf1,
- },
- }
+ def test_all_rx_cores(self):
+ helper = ProxBngProfileHelper(mock.MagicMock())
+ helper._latency_cores = expected = [3, 4, 6]
+ helper._test_cores = [5, 2, 1]
- helper = ProxResourceHelper(setup_helper)
- helper.copy_to_target = mock.MagicMock(return_value='3')
- helper.generate_prox_config_file = mock.MagicMock(return_value='4')
- helper.upload_prox_config = mock.MagicMock(return_value='5')
-
- expected = 'c', 'd', '5'
- result = helper.get_process_args()
+ result = helper.all_rx_cores
self.assertEqual(result, expected)
- self.assertFalse(helper.additional_file)
- self.assertIsNone(helper.remote_prox_file_name)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
- def test_get_process_args_additional_file(self, mock_find_path):
- vnf1 = {
- 'prox_args': 'c',
- 'prox_path': 'd',
- 'prox_config': 'e/f',
- 'prox_files': 'g/h',
- }
+ def test_get_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'),
+ ]),
+ ('core 4', [
+ ('index', 7),
+ ('mode', 'gen'),
+ ]),
+ ]
- mock_find_path.side_effect = ['1', '2']
- setup_helper = mock.MagicMock()
- setup_helper.scenario_helper = ScenarioHelper('vnf1')
- setup_helper.scenario_helper.scenario_cfg = {
- 'task_path': 'a/b',
- 'options': {
- 'vnf1': vnf1,
- },
+ helper = ProxProfileHelper(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)
+ },
+ }
}
- helper = ProxResourceHelper(setup_helper)
- helper.copy_to_target = mock.MagicMock(return_value='33')
- helper.generate_prox_config_file = mock.MagicMock(return_value='44')
- helper.upload_prox_config = mock.MagicMock(return_value='55')
-
- expected = 'c', 'd', '55'
- result = helper.get_process_args()
+ expected = [7, 8]
+ result = helper.get_cores(helper.PROX_CORE_GEN_MODE)
self.assertEqual(result, expected)
- self.assertTrue(helper.additional_file)
- self.assertEqual(helper.remote_prox_file_name, '33')
- 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_get_latency(self):
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.vnfd_helper.interfaces = []
- def test_execute(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- helper.client = mock.MagicMock()
+ helper = ProxProfileHelper(resource_helper)
+ helper._latency_cores = []
- expected = helper.client.my_command()
- result = helper.execute('my_command')
+ expected = []
+ result = helper.get_latency()
self.assertEqual(result, expected)
- helper.client = object()
-
- result = helper.execute('my_command')
- self.assertIsNone(result)
-
- def test_copy_to_target(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- expected = '/tmp/c'
- result = helper.copy_to_target('a/b', 'c')
- self.assertEqual(result, expected)
+ helper._latency_cores = [1, 2]
+ helper.client = mock.MagicMock()
- def test_upload_prox_config(self):
- setup_helper = mock.MagicMock()
- helper = ProxResourceHelper(setup_helper)
- helper.write_prox_config = mock.MagicMock(return_value='a long string')
- expected = '/tmp/a'
- result = helper.upload_prox_config('a', {})
- self.assertEqual(result, expected)
+ 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_run_test(self, mock_time):
- @contextmanager
- def measure(*args, **kwargs):
- yield stats
-
+ def test_traffic_context(self, mock_time):
setup_helper = mock.MagicMock()
setup_helper.vnfd_helper.interfaces = []
- stats = {
- 'delta': TotStatsTuple(6, 7, 8, 9),
+ helper = ProxProfileHelper(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_data = [
+ ('global', [
+ ('not_name', 'other data'),
+ ('name_not', 'more data'),
+ ('name', helper.__prox_profile_type__),
+ ]),
+ ('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'),
+ ]),
+ ]
+
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])
- with self.assertRaises(AssertionError):
- helper.run_test(980, 15, 45)
-
- setup_helper.vnfd_helper.interfaces = ['a', 'b', 'c', 'd']
helper._test_cores = [3, 4]
- expected = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7, 1.3e7)
- result = helper.run_test(230, 60, 65)
- self.assertEqual(result, expected)
+ with helper.traffic_context(64, 1):
+ pass
- def test_generate_prox_lua_file(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+ @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))
- helper = ProxResourceHelper(setup_helper)
- helper.LUA_PARAMETER_NAME = 'sut'
+ helper = ProxProfileHelper(resource_helper)
- expected = ''
- result = helper.generate_prox_lua_file()
- self.assertEqual(result, expected)
+ helper.run_test(120, 5, 6.5)
- setup_helper.vnfd_helper.interfaces = [
- {
- 'local_ip': '10.20.30.40',
- 'dst_ip': '10.11.12.13',
- 'virtual-interface': {
- 'dpdk_port_num': 3,
- },
- },
- {
- 'local_ip': '10.20.30.45',
- 'dst_ip': '10.11.12.19',
- 'virtual-interface': {
- 'dpdk_port_num': 7,
- },
- },
+
+class TestProxMplsProfileHelper(unittest.TestCase):
+
+ 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 = os.linesep.join([
- 'sut_hex_ip_port_3:"0a 14 1e 28"',
- 'sut_ip_port_3:"10.20.30.40"',
- 'gen_hex_ip_port_3:"0a 0b 0c 0d"',
- 'gen_ip_port_3:"10.11.12.13"',
-
- 'sut_hex_ip_port_7:"0a 14 1e 2d"',
- 'sut_ip_port_7:"10.20.30.45"',
- 'gen_hex_ip_port_7:"0a 0b 0c 13"',
- 'gen_ip_port_7:"10.11.12.19"',
- ])
- result = helper.generate_prox_lua_file()
- self.assertEqual(result, expected)
+ 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)
+ },
+ }
+ }
- def test_upload_prox_lua(self):
- def identity(*args):
- return args
+ 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.generate_prox_lua_file = mock.MagicMock(return_value=234)
- helper.put_string_to_file = identity
+ with helper.traffic_context(120, 5.4):
+ pass
- expected = ''
- result = helper.upload_prox_lua('my_dir', {})
- self.assertEqual(result, expected)
- input_data = {
- 'lua': {
- 'key1': 'value1 ("inside") tail',
- 'key2': 'value2',
- 'key3 ("key_side") head': 'value3',
- },
- }
+class TestProxBngProfileHelper(unittest.TestCase):
- expected = 234, 'my_dir/key_side'
- result = helper.upload_prox_lua('my_dir', input_data)
- self.assertEqual(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'),
+ ]),
+ ]
- def test_put_string_to_file(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+ 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)
+ },
+ }
+ }
- helper = ProxResourceHelper(setup_helper)
+ 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)
- expected = 'a/b'
- result = helper.put_string_to_file('my long string', 'a/b')
- self.assertEqual(result, expected)
+ 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)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
- def test_generate_prox_config_file(self, mock_parser_type):
- def init(*args):
- args[-1].update(sections_data)
- return mock.MagicMock()
+ @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))
- sections_data = {}
+ helper = ProxBngProfileHelper(resource_helper)
- mock_parser_type.side_effect = init
+ 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
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
- helper = ProxResourceHelper(setup_helper)
- helper.additional_file = False
+class TestProxVpeProfileHelper(unittest.TestCase):
- expected = {}
- result = helper.generate_prox_config_file('a/b')
- self.assertEqual(result, expected)
+ def test_vpe_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'),
+ ]),
+ ]
- helper.additional_file = True
- helper.remote_prox_file_name = 'remote'
- setup_helper.vnfd_helper.interfaces = [
- {
- 'virtual-interface': {
- 'dpdk_port_num': 3,
- 'dst_mac': '00:00:00:de:ad:88',
+ helper = ProxVpeProfileHelper(resource_helper)
+ helper._cpu_topology = {
+ 0: {
+ 1: {
+ 5: (5, 1, 0)
},
- },
- {
- 'virtual-interface': {
- 'dpdk_port_num': 5,
- 'dst_mac': '00:00:00:de:ad:ff',
+ 2: {
+ 6: (6, 2, 0)
},
- },
- {
- 'virtual-interface': {
- 'dpdk_port_num': 7,
- 'dst_mac': '00:00:00:de:ad:ff',
+ 3: {
+ 7: (7, 3, 0)
},
- },
- ]
- sections_data = {
- 'port 3': [
- ['ip', ''],
- ['mac', 'foo'],
- ['dst mac', ''],
- ['tx port', '1'],
- ],
- 'port 5': [
- ['ip', ''],
- ['dst mac', ''],
- ['tx port', '0'],
- ['single'],
- ['???', 'dofile "here" 23'],
- ],
- }
-
- expected = {
- 'port 3': [
- ['ip', ''],
- ['mac', 'hardware'],
- ['dst mac', '00:00:00:de:ad:ff'],
- ['tx port', '1'],
- ],
- 'port 5': [
- ['ip', ''],
- ['dst mac', '00:00:00:de:ad:88'],
- ['tx port', '0'],
- ['single'],
- ['???', 'dofile "remote" 23'],
- ],
+ 4: {
+ 8: (8, 3, 0)
+ },
+ }
}
- result = helper.generate_prox_config_file('a/b')
- self.assertDictEqual(result, expected)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ConfigParser')
- def test_generate_prox_config_file_negative(self, mock_parser_type):
- def init(*args):
- args[-1].update(sections_data)
- return mock.MagicMock()
- sections_data = {}
+ expected_cpe = [7]
+ expected_inet = [8]
+ expected_combined = (expected_cpe, expected_inet)
- mock_parser_type.side_effect = init
+ self.assertIsNone(helper._cores_tuple)
+ self.assertEqual(helper.cpe_cores, expected_cpe)
+ self.assertEqual(helper.inet_cores, expected_inet)
+ self.assertEqual(helper._cores_tuple, expected_combined)
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+ def test_vpe_ports(self):
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.prox_config_data = [
+ ('section1', []),
+ ('section2', [
+ ('a', 'b'),
+ ('c', 'd'),
+ ]),
+ ('port 3', [
+ ('index', '5'),
+ ('name', 'cpe'),
+ ('mac', 'hardware'),
+ ]),
+ ('port 4', [
+ ('index', '7'),
+ ('name', 'inet'),
+ ('mac', 'hardware'),
+ ]),
+ ]
- helper = ProxResourceHelper(setup_helper)
- helper.additional_file = False
- helper.remote_prox_file_name = 'remote'
- setup_helper.vnfd_helper.interfaces = [
- {
- 'virtual-interface': {
- 'dpdk_port_num': 3,
- 'dst_mac': '00:00:00:de:ad:88',
+ helper = ProxVpeProfileHelper(resource_helper)
+ helper._port_list = {
+ 0: {
+ 1: {
+ 5: 'cpe'
},
- },
- {
- 'virtual-interface': {
- 'dpdk_port_num': 5,
- 'dst_mac': '00:00:00:de:ad:ff',
+ 2: {
+ 6: 'inet'
},
- },
- {
- 'virtual-interface': {
- 'dpdk_port_num': 7,
- 'dst_mac': '00:00:00:de:ad:ff',
+ 3: {
+ 7: 'cpe'
},
- },
- ]
- sections_data = {
- 'port 3': [
- ['ip', ''],
- ['mac', 'foo'],
- ['dst mac', ''],
- ],
- 'port 5': [
- ['ip', ''],
- ['dst mac', ''],
- ['tx port', '0'],
- ['???', 'dofile "here" 23'],
- ],
+ 4: {
+ 8: 'inet'
+ },
+ }
}
- with self.assertRaises(Exception):
- helper.generate_prox_config_file('a/b')
+ expected_cpe = [3]
+ expected_inet = [4]
+ expected_combined = (expected_cpe, expected_inet)
- def test_get_latency(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+ self.assertIsNone(helper._ports_tuple)
+ self.assertEqual(helper.cpe_ports, expected_cpe)
+ self.assertEqual(helper.inet_ports, expected_inet)
+ self.assertEqual(helper._ports_tuple, expected_combined)
- helper = ProxResourceHelper(setup_helper)
- helper._latency_cores = []
+ @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))
- expected = []
- result = helper.get_latency()
- self.assertEqual(result, expected)
+ helper = ProxVpeProfileHelper(resource_helper)
- helper._latency_cores = [1, 2]
- helper.client = mock.MagicMock()
+ 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
- expected = helper.sut.lat_stats()
- result = helper.get_latency()
- self.assertIs(result, expected)
- def test__get_logical_if_name(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+class TestProxlwAFTRProfileHelper(unittest.TestCase):
- helper = ProxResourceHelper(setup_helper)
- helper._vpci_to_if_name_map = {
- 'key1': 234,
- 'key2': 432,
+ def test_lwaftr_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', 'tun'),
+ ]),
+ ('core 4', [
+ ('index', 7),
+ ('mode', 'gen'),
+ ('name', 'inet'),
+ ]),
+ ]
+
+ helper = ProxlwAFTRProfileHelper(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)
+ },
+ }
}
- expected = 234
- result = helper._get_logical_if_name('key1')
- self.assertEqual(result, expected)
+ expected_tun = [7]
+ expected_inet = [8]
+ expected_combined = (expected_tun, expected_inet)
- @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])
+ self.assertIsNone(helper._cores_tuple)
+ self.assertEqual(helper.tun_cores, expected_tun)
+ self.assertEqual(helper.inet_cores, expected_inet)
+ self.assertEqual(helper._cores_tuple, expected_combined)
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
+ def test_tun_ports(self):
+ resource_helper = mock.MagicMock()
+ resource_helper.setup_helper.prox_config_data = [
+ ('section1', []),
+ ('section2', [
+ ('a', 'b'),
+ ('c', 'd'),
+ ]),
+ ('port 3', [
+ ('index', '5'),
+ ('name', 'lwB4'),
+ ('mac', 'hardware'),
+ ]),
+ ('port 4', [
+ ('index', '7'),
+ ('name', 'inet'),
+ ('mac', 'hardware'),
+ ]),
+ ]
- helper = ProxResourceHelper(setup_helper)
+ helper = ProxlwAFTRProfileHelper(resource_helper)
+ helper._port_list = {
+ 0: {
+ 1: {
+ 5: 'lwB4'
+ },
+ 2: {
+ 6: 'inet'
+ },
+ 3: {
+ 7: 'lwB4'
+ },
+ 4: {
+ 8: 'inet'
+ },
+ }
+ }
- result = helper._connect()
- self.assertIs(result, client)
+ expected_tun = [3]
+ expected_inet = [4]
+ expected_combined = (expected_tun, expected_inet)
- client.connect.side_effect = chain(repeat(socket.error, 65), [None])
+ self.assertIsNone(helper._ports_tuple)
+ self.assertEqual(helper.tun_ports, expected_tun)
+ self.assertEqual(helper.inet_ports, expected_inet)
+ self.assertEqual(helper._ports_tuple, expected_combined)
- with self.assertRaises(Exception):
- helper._connect()
+ @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))
+
+ helper = ProxlwAFTRProfileHelper(resource_helper)
+
+ 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_prox_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
index c727cb7fb..e29e8ddcd 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
@@ -17,6 +17,7 @@
from __future__ import absolute_import
+import errno
import os
import unittest
import mock
@@ -84,9 +85,10 @@ class TestProxApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'local_ip': '152.16.100.19',
'type': 'PCI-PASSTHROUGH',
- 'vld_id': '',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '0',
+ 'dpdk_port_num': 0,
'bandwidth': '10 Gbps',
'driver': "i40e",
'dst_ip': '152.16.100.20',
@@ -102,10 +104,11 @@ class TestProxApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.1',
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
- 'vld_id': '',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe1',
'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',
@@ -186,7 +189,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
+ 'vld_id': ProxApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -220,7 +223,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
+ 'vld_id': ProxApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -251,7 +254,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
+ 'vld_id': ProxApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -263,7 +266,7 @@ class TestProxApproxVnf(unittest.TestCase):
},
'xe1': {
'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
+ 'vld_id': ProxApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -339,15 +342,15 @@ class TestProxApproxVnf(unittest.TestCase):
resource_helper = mock.MagicMock()
resource_helper.execute.return_value = list(range(12))
- resource_helper.collect_kpi.return_value = {'core': {'result': 234}}
+ resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}}
prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf.resource_helper = resource_helper
expected = {
- 'packets_in': 7,
+ 'packets_in': 6,
'packets_dropped': 1,
- 'packets_fwd': 6,
+ 'packets_fwd': 7,
'collect_stats': {'core': {'result': 234}},
}
result = prox_approx_vnf.collect_kpi()
@@ -362,6 +365,7 @@ class TestProxApproxVnf(unittest.TestCase):
prox_approx_vnf = ProxApproxVnf(NAME, deepcopy(self.VNFD0))
prox_approx_vnf.resource_helper = resource_helper
prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = []
+ prox_approx_vnf.vnfd_helper.port_pairs.interfaces = []
with self.assertRaises(RuntimeError):
prox_approx_vnf.collect_kpi()
@@ -371,55 +375,32 @@ 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.helpers.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)
+ prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
+ prox_approx_vnf.ssh_helper.provision_tool.return_value = '/tool_path12/tool_file34'
+ prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg'
- filewrapper = mock.MagicMock()
- config_path = self.SCENARIO_CFG['options']["vnf__1"]["prox_config"]
- prox_path = self.SCENARIO_CFG['options']["vnf__1"]["prox_path"]
- prox_args = self.SCENARIO_CFG['options']["vnf__1"]["prox_args"]
- prox_approx_vnf.WAIT_TIME = 0
- prox_approx_vnf._run_prox(filewrapper, config_path, prox_path, prox_args)
+ expected = "sudo bash -c 'cd /tool_path12; " \
+ "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '"
- self.assertEqual(prox_approx_vnf.ssh_helper.run.call_args[0][0],
- "sudo bash -c 'cd /root/dppd-PROX-v035/build; "
- "/root/dppd-PROX-v035/build/prox -o cli -t -f configs/l3-swap-2.cfg '")
+ prox_approx_vnf._run()
+ result = prox_approx_vnf.ssh_helper.run.call_args[0][0]
+ self.assertEqual(result, expected)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
@mock.patch(SSH_HELPER)
- def test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
- mock_ssh(ssh)
-
- mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'}
-
+ def bad_test_instantiate(self, ssh, mock_time):
prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
- prox_approx_vnf.ssh_helper = mock.MagicMock(
- **{"execute.return_value": (0, "", ""), "bin_path": ""})
- prox_approx_vnf.setup_helper._setup_resources = mock.MagicMock()
- prox_approx_vnf.setup_helper._find_used_drivers = mock.MagicMock()
- prox_approx_vnf.setup_helper.used_drivers = {}
- prox_approx_vnf.setup_helper.bound_pci = []
- prox_approx_vnf._run_prox = mock.MagicMock(return_value=0)
- prox_approx_vnf.resource_helper = mock.MagicMock()
- prox_approx_vnf.resource_helper.get_process_args.return_value = {
- '-e': '',
- '-t': '',
- }, 'configs/l3-gen-2.cfg', '/root/dppd-PROX-v035/build/prox'
-
- prox_approx_vnf.copy_to_target = mock.MagicMock()
- prox_approx_vnf.upload_prox_config = mock.MagicMock()
- prox_approx_vnf.generate_prox_config_file = mock.MagicMock()
- prox_approx_vnf.q_out.put("PROX started")
- prox_approx_vnf.WAIT_TIME = 0
-
- # if process it still running exitcode will be None
- expected = 0, None
- result = prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
- self.assertIn(result, expected)
+ prox_approx_vnf.scenario_helper = mock.MagicMock()
+ 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()
@mock.patch(SSH_HELPER)
def test_wait_for_instantiate_panic(self, ssh, mock_time):
@@ -437,7 +418,7 @@ class TestProxApproxVnf(unittest.TestCase):
mock_ssh(ssh)
prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
with self.assertRaises(NotImplementedError):
- prox_approx_vnf.scale('')
+ prox_approx_vnf.scale()
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
@mock.patch(SSH_HELPER)
@@ -461,6 +442,21 @@ class TestProxApproxVnf(unittest.TestCase):
prox_approx_vnf._vnf_up_post()
self.assertEqual(resource_helper.up_post.call_count, 1)
+ @mock.patch(SSH_HELPER)
+ def test_vnf_execute_oserror(self, ssh, mock_time):
+ mock_ssh(ssh)
+ prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
+
+ resource_helper.execute.side_effect = OSError(errno.EPIPE, "")
+ prox_approx_vnf.vnf_execute("", _ignore_errors=True)
+
+ resource_helper.execute.side_effect = OSError(errno.ESHUTDOWN, "")
+ prox_approx_vnf.vnf_execute("", _ignore_errors=True)
+
+ resource_helper.execute.side_effect = OSError(errno.EADDRINUSE, "")
+ with self.assertRaises(OSError):
+ prox_approx_vnf.vnf_execute("", _ignore_errors=True)
if __name__ == '__main__':
unittest.main()
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 0264facf5..85b10c5a9 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
@@ -29,7 +29,6 @@ from yardstick.benchmark.contexts.base import Context
from yardstick.network_services.nfvi.resource import ResourceProfile
from yardstick.network_services.traffic_profile.base import TrafficProfile
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
-from yardstick.ssh import SSHError
class MockError(BaseException):
@@ -98,10 +97,12 @@ class TestVnfSshHelper(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',
'dst_ip': '152.16.100.20',
- 'local_mac': '00:00:00:00:00:01'
+ 'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'
@@ -113,10 +114,12 @@ class TestVnfSshHelper(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
- 'local_mac': '00:00:00:00:00:02'
+ 'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
@@ -186,6 +189,7 @@ class TestVnfSshHelper(unittest.TestCase):
@mock.patch('yardstick.ssh.paramiko')
def test_upload_config_file(self, mock_paramiko):
ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path')
+ ssh_helper._run = mock.MagicMock()
self.assertFalse(ssh_helper.is_connected)
cfg_file = ssh_helper.upload_config_file('my/prefix', 'my content')
@@ -227,6 +231,7 @@ class TestVnfSshHelper(unittest.TestCase):
@mock.patch('yardstick.ssh.provision_tool')
def test_provision_tool(self, mock_provision_tool, mock_paramiko):
ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path')
+ ssh_helper._run = mock.MagicMock()
self.assertFalse(ssh_helper.is_connected)
ssh_helper.provision_tool()
@@ -290,10 +295,12 @@ class TestSetupEnvHelper(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',
'dst_ip': '152.16.100.20',
- 'local_mac': '00:00:00:00:00:01'
+ 'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'
@@ -305,10 +312,12 @@ class TestSetupEnvHelper(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
- 'local_mac': '00:00:00:00:00:02'
+ 'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
@@ -350,15 +359,6 @@ class TestSetupEnvHelper(unittest.TestCase):
with self.assertRaises(NotImplementedError):
setup_env_helper.build_config()
- def test__get_ports_gateway(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- setup_env_helper = SetupEnvHelper(vnfd_helper, mock.Mock(), mock.Mock())
- result = setup_env_helper._get_ports_gateway("xe0")
- self.assertEqual(result, "152.16.100.20")
-
- result = setup_env_helper._get_ports_gateway("xe123")
- self.assertIsNone(result)
-
def test_setup_vnf_environment(self):
setup_env_helper = SetupEnvHelper(mock.Mock(), mock.Mock(), mock.Mock())
self.assertIsNone(setup_env_helper.setup_vnf_environment())
@@ -412,14 +412,16 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'virtual-interface': {
'dst_mac': '00:00:00:00:00:03',
'vpci': '0000:05:00.0',
+ 'dpdk_port_num': 0,
'driver': 'i40e',
'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'
+ 'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'
@@ -428,14 +430,16 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'virtual-interface': {
'dst_mac': '00:00:00:00:00:04',
'vpci': '0000:05:00.1',
+ 'dpdk_port_num': 1,
'driver': 'ixgbe',
'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'
+ 'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
@@ -541,7 +545,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
call_args_iter = (args[0][0] for args in ssh_helper.execute.call_args_list)
self.assertIsNone(result)
self.assertEqual(ssh_helper.execute.call_count, 3)
- for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, call_args_iter):
+ for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list,
+ call_args_iter):
self.assertTrue(arg0.startswith(expect_start))
self.assertIn(expect_in, arg0)
@@ -558,19 +563,11 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
call_args_iter = (args[0][0] for args in ssh_helper.execute.call_args_list)
self.assertIsNone(result)
self.assertEqual(ssh_helper.execute.call_count, 3)
- for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, call_args_iter):
+ for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list,
+ call_args_iter):
self.assertTrue(arg0.startswith(expect_start))
self.assertIn(expect_in, arg0)
- def test__get_dpdk_port_num(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- expected = '0'
- result = dpdk_setup_helper._get_dpdk_port_num('xe0')
- self.assertEqual(result, expected)
-
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open')
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.find_relative_file')
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig')
@@ -582,7 +579,6 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
scenario_helper.vnf_cfg = {}
scenario_helper.all_options = {}
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper.all_ports = []
dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command'
result = dpdk_setup_helper.build_config()
@@ -600,190 +596,37 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
dpdk_setup_helper.CFG_CONFIG = 'config'
dpdk_setup_helper.CFG_SCRIPT = 'script'
- dpdk_setup_helper.all_ports = [3, 4, 5]
dpdk_setup_helper.pipeline_kwargs = {}
+ dpdk_setup_helper.all_ports = [0, 1, 2]
expected = {
'cfg_file': 'config',
'script': 'script',
- 'ports_len_hex': '0xf',
+ 'port_mask_hex': '0x3',
'tool_path': 'tool_path',
}
dpdk_setup_helper._build_pipeline_kwargs()
self.assertDictEqual(dpdk_setup_helper.pipeline_kwargs, expected)
- def test__get_app_cpu(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.provision_tool.return_value = 'tool_path'
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- dpdk_setup_helper.CORES = expected = [5, 4, 3]
- result = dpdk_setup_helper._get_app_cpu()
- self.assertEqual(result, expected)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores')
- def test__get_app_cpu_no_cores_sw(self, mock_cpu_sys_cores_class):
- mock_cpu_sys_cores = mock_cpu_sys_cores_class()
- mock_cpu_sys_cores.get_core_socket.return_value = {
- 'socket': [2, 4, 8, 10, 12],
- }
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.provision_tool.return_value = 'tool_path'
- scenario_helper = mock.Mock()
- scenario_helper.vnf_cfg = {
- 'worker_threads': '2',
- }
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper.CORES = []
- dpdk_setup_helper.SW_DEFAULT_CORE = 1
- dpdk_setup_helper.HW_DEFAULT_CORE = 2
- dpdk_setup_helper.socket = 'socket'
-
- expected = [2, 4, 8]
- result = dpdk_setup_helper._get_app_cpu()
- self.assertEqual(result, expected)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores')
- def test__get_app_cpu_no_cores_hw(self, mock_cpu_sys_cores_class):
- mock_cpu_sys_cores = mock_cpu_sys_cores_class()
- mock_cpu_sys_cores.get_core_socket.return_value = {
- 'socket': [2, 4, 8, 10, 12],
- }
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- scenario_helper = mock.Mock()
- scenario_helper.vnf_cfg = {
- 'worker_threads': '2',
- 'lb_config': 'HW',
- }
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper.CORES = []
- dpdk_setup_helper.SW_DEFAULT_CORE = 1
- dpdk_setup_helper.HW_DEFAULT_CORE = 2
- dpdk_setup_helper.socket = 'socket'
-
- expected = [2, 4, 8, 10]
- result = dpdk_setup_helper._get_app_cpu()
- self.assertEqual(result, expected)
-
- def test__get_cpu_sibling_list(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')])
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[])
-
- expected = ['5', '3', '4', '10']
- result = dpdk_setup_helper._get_cpu_sibling_list([1, 3, 7])
- self.assertEqual(result, expected)
-
- def test__get_cpu_sibling_list_no_core_arg(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')])
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[1, 7])
-
- expected = ['5', '3', '4']
- result = dpdk_setup_helper._get_cpu_sibling_list()
- self.assertEqual(result, expected)
-
- def test__get_cpu_sibling_list_ssh_failure(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.side_effect = iter([(0, '5', ''), SSHError, (0, '10', '')])
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[])
-
- expected = []
- result = dpdk_setup_helper._get_cpu_sibling_list([1, 3, 7])
- self.assertEqual(result, expected)
-
- def test__validate_cpu_cfg(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')])
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[1, 3, 7])
-
- expected = ['5', '3', '4', '10']
- result = dpdk_setup_helper._validate_cpu_cfg()
- self.assertEqual(result, expected)
-
- def test__find_used_drivers(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- stdout = '''
-00:01.2 foo drv=name1
-00:01.4 drv foo=name2
-00:02.2 drv=name3
-00:02.3 drv=name4
-'''
- ssh_helper.execute.return_value = 0, stdout, ''
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper.used_drivers = None
- dpdk_setup_helper._dpdk_nic_bind = ''
- dpdk_setup_helper.bound_pci = [
- 'pci 00:01.2',
- 'pci 00:02.3',
- ]
-
- expected = {
- '00:01.2': (0, 'name1'),
- '00:02.3': (2, 'name4'),
- }
- dpdk_setup_helper._find_used_drivers()
- self.assertEqual(dpdk_setup_helper.used_drivers, expected)
-
- def test_dpdk_nic_bind(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.provision_tool.return_value = nic_bind = object()
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- self.assertIsNone(dpdk_setup_helper._dpdk_nic_bind)
- self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind)
- self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind)
- self.assertEqual(ssh_helper.provision_tool.call_count, 1)
-
- # ensure provision tool is not called a second time
- self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind)
- self.assertEqual(ssh_helper.provision_tool.call_count, 1)
-
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
@mock.patch('yardstick.ssh.SSH')
def test_setup_vnf_environment(self, _, mock_time):
- cores = ['3', '4']
+ def execute(cmd, *args, **kwargs):
+ if cmd.startswith('which '):
+ return exec_failure
+ return exec_success
- vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0))
+ exec_success = (0, 'good output', '')
+ exec_failure = (1, 'bad output', 'error output')
+
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
- ssh_helper.execute.return_value = 1, 'bad output', 'error output'
- ssh_helper.join_bin_path.return_value = 'joined_path'
- ssh_helper.provision_tool.return_value = 'provision string'
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._setup_hugepages = mock.Mock()
- dpdk_setup_helper._validate_cpu_cfg = mock.Mock(return_value=cores)
- dpdk_setup_helper._find_used_drivers = mock.Mock()
- dpdk_setup_helper.used_drivers = {
- '0000:05:00.0': (1, ''),
- '0000:05:01.0': (3, ''),
- }
+ ssh_helper.execute = execute
- result = dpdk_setup_helper.setup_vnf_environment()
- self.assertIsInstance(result, ResourceProfile)
- self.assertEqual(result.cores, cores)
- self.assertEqual(vnfd_helper.interfaces[0]['dpdk_port_num'], 1)
- self.assertNotIn('dpdk_port_num', vnfd_helper.interfaces[1])
+ dpdk_vnf_setup_env_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, mock.Mock())
+ dpdk_vnf_setup_env_helper._validate_cpu_cfg = mock.Mock(return_value=[])
+
+ self.assertIsInstance(dpdk_vnf_setup_env_helper.setup_vnf_environment(), ResourceProfile)
def test__setup_dpdk_early_success(self):
vnfd_helper = VnfdHelper(self.VNFD_0)
@@ -825,6 +668,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)
@@ -839,87 +684,153 @@ 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__bind_dpdk_unforced(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- dpdk_setup_helper._bind_dpdk('x', 'y', force=False)
- self.assertNotIn('--force', ssh_helper.execute.call_args_list[0][0][0])
-
- def test__detect_and_bind_dpdk_short(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.return_value = 0, 'output', ''
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- self.assertIsNone(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b'))
- self.assertEqual(ssh_helper.execute.call_count, 1)
-
- def test__detect_and_bind_dpdk_fail_to_bind(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
+ @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.return_value = 1, 'bad output', 'error output'
+ # ssh_helper.execute = mock.Mock(return_value = (0, 'text', ''))
+ # ssh_helper.execute.return_value = 0, 'output', ''
scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._bind_dpdk = mock.Mock()
-
- self.assertIsNone(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b'))
- self.assertEqual(ssh_helper.execute.call_count, 2)
+ rv = ['0000:05:00.1', '0000:05:00.0']
- def test__detect_and_bind_dpdk(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.side_effect = iter([
- (1, 'bad output', 'error output'),
- (0, 'output', ''),
- ])
- scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._bind_dpdk = mock.Mock()
-
- self.assertEqual(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b'), 'output')
- self.assertEqual(ssh_helper.execute.call_count, 2)
+ dpdk_setup_helper.dpdk_bind_helper._get_bound_pci_addresses = mock.Mock(return_value=rv)
+ dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock()
+ dpdk_setup_helper.dpdk_bind_helper.read_status = mock.Mock()
- def test__bind_kernel_devices(self):
- bind_iter = iter([
- None,
- 'output',
- ])
-
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._detect_and_bind_dpdk = mock.Mock(side_effect=bind_iter)
+ self.assertIsNone(dpdk_setup_helper._detect_and_bind_drivers())
- self.assertIsNone(dpdk_setup_helper._bind_kernel_devices())
+ intf_0 = vnfd_helper.vdu[0]['external-interface'][0]['virtual-interface']
+ intf_1 = vnfd_helper.vdu[0]['external-interface'][1]['virtual-interface']
+ self.assertEquals(0, intf_0['dpdk_port_num'])
+ self.assertEquals(1, intf_1['dpdk_port_num'])
def test_tear_down(self):
vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
- dpdk_setup_helper._dpdk_nic_bind = 'a'
- dpdk_setup_helper.used_drivers = {
- '0000:05:00.0': (1, 'd1'),
- '0000:05:01.0': (3, 'd3'),
+ dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock()
+ dpdk_setup_helper.dpdk_bind_helper.used_drivers = {
+ 'd1': ['0000:05:00.0'],
+ 'd3': ['0000:05:01.0'],
}
self.assertIsNone(dpdk_setup_helper.tear_down())
+ dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call(['0000:05:00.0'], 'd1', True)
+ dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call(['0000:05:01.0'], 'd3', True)
class TestResourceHelper(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',
+ 'driver': 'i40e',
+ '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'
+ },
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0'
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:04',
+ 'vpci': '0000:05:00.1',
+ 'driver': 'ixgbe',
+ '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'
+ },
+ '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_setup(self):
resource = object()
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -930,7 +841,7 @@ class TestResourceHelper(unittest.TestCase):
self.assertIs(resource_helper.resource, resource)
def test_generate_cfg(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -939,7 +850,7 @@ class TestResourceHelper(unittest.TestCase):
self.assertIsNone(resource_helper.generate_cfg())
def test_stop_collect(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -949,7 +860,7 @@ class TestResourceHelper(unittest.TestCase):
self.assertIsNone(resource_helper.stop_collect())
def test_stop_collect_none(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -958,6 +869,7 @@ class TestResourceHelper(unittest.TestCase):
self.assertIsNone(resource_helper.stop_collect())
+
class TestClientResourceHelper(unittest.TestCase):
VNFD_0 = {
@@ -1004,10 +916,12 @@ class TestClientResourceHelper(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',
'dst_ip': '152.16.100.20',
- 'local_mac': '00:00:00:00:00:01'
+ 'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'
@@ -1020,10 +934,12 @@ class TestClientResourceHelper(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
- 'local_mac': '00:00:00:00:00:02'
+ 'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
@@ -1036,7 +952,7 @@ class TestClientResourceHelper(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 2,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.30',
'local_mac': '00:00:00:00:00:11'
@@ -1087,7 +1003,7 @@ class TestClientResourceHelper(unittest.TestCase):
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError',
new_callable=lambda: MockError)
def test_get_stats_not_connected(self, mock_state_error, mock_logger):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1105,11 +1021,6 @@ class TestClientResourceHelper(unittest.TestCase):
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
client_resource_helper = ClientResourceHelper(dpdk_setup_helper)
client_resource_helper.client = mock.MagicMock()
- client_resource_helper._vpci_ascending = [
- '0000:05:00.0',
- '0000:05:00.1',
- '0000:05:00.2',
- ]
client_resource_helper.client.get_stats.return_value = {
0: {
'rx_pps': 5.5,
@@ -1143,16 +1054,9 @@ class TestClientResourceHelper(unittest.TestCase):
"in_packets": 0,
"out_packets": 48791,
},
- 'xe2': {
- "rx_throughput_fps": 0.0,
- "tx_throughput_fps": 0.0,
- "rx_throughput_mbps": 0.0,
- "tx_throughput_mbps": 0.0,
- "in_packets": 0,
- "out_packets": 0,
- },
}
- result = client_resource_helper.generate_samples()
+ ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports)
+ result = client_resource_helper.generate_samples(ports)
self.assertDictEqual(result, expected)
def test_generate_samples_with_key(self):
@@ -1162,10 +1066,6 @@ class TestClientResourceHelper(unittest.TestCase):
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
client_resource_helper = ClientResourceHelper(dpdk_setup_helper)
client_resource_helper.client = mock.MagicMock()
- client_resource_helper._vpci_ascending = [
- '0000:05:00.0',
- '0000:05:00.1',
- ]
client_resource_helper.client.get_stats.return_value = {
'key_name': 'key_value',
0: {
@@ -1203,7 +1103,8 @@ class TestClientResourceHelper(unittest.TestCase):
"out_packets": 48791,
},
}
- result = client_resource_helper.generate_samples('key_name')
+ ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports)
+ result = client_resource_helper.generate_samples(ports, 'key_name')
self.assertDictEqual(result, expected)
def test_generate_samples_with_key_and_default(self):
@@ -1213,10 +1114,6 @@ class TestClientResourceHelper(unittest.TestCase):
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
client_resource_helper = ClientResourceHelper(dpdk_setup_helper)
client_resource_helper.client = mock.MagicMock()
- client_resource_helper._vpci_ascending = [
- '0000:05:00.0',
- '0000:05:00.1',
- ]
client_resource_helper.client.get_stats.return_value = {
0: {
'rx_pps': 5.5,
@@ -1253,11 +1150,12 @@ class TestClientResourceHelper(unittest.TestCase):
"out_packets": 48791,
},
}
- result = client_resource_helper.generate_samples('key_name', 'default')
+ ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports)
+ result = client_resource_helper.generate_samples(ports, 'key_name', 'default')
self.assertDictEqual(result, expected)
def test_clear_stats(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1268,7 +1166,7 @@ class TestClientResourceHelper(unittest.TestCase):
self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1)
def test_clear_stats_of_ports(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1279,7 +1177,7 @@ class TestClientResourceHelper(unittest.TestCase):
self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1)
def test_start(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1290,7 +1188,7 @@ class TestClientResourceHelper(unittest.TestCase):
self.assertEqual(client_resource_helper.client.start.call_count, 1)
def test_start_ports(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1301,7 +1199,7 @@ class TestClientResourceHelper(unittest.TestCase):
self.assertEqual(client_resource_helper.client.start.call_count, 1)
def test_collect_kpi_with_queue(self):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1324,7 +1222,7 @@ class TestClientResourceHelper(unittest.TestCase):
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError',
new_callable=lambda: MockError)
def test__connect_with_failures(self, mock_error, mock_logger, mock_time):
- vnfd_helper = VnfdHelper({})
+ vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -1493,8 +1391,9 @@ class TestRfc2544ResourceHelper(unittest.TestCase):
class TestSampleVNFDeployHelper(unittest.TestCase):
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
@mock.patch('subprocess.check_output')
- def test_deploy_vnfs_disabled(self, mock_check_output):
+ def test_deploy_vnfs_disabled(self, mock_check_output, mock_time):
vnfd_helper = mock.Mock()
ssh_helper = mock.Mock()
ssh_helper.join_bin_path.return_value = 'joined_path'
@@ -1503,8 +1402,9 @@ class TestSampleVNFDeployHelper(unittest.TestCase):
sample_vnf_deploy_helper = SampleVNFDeployHelper(vnfd_helper, ssh_helper)
self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1'))
- self.assertEqual(ssh_helper.execute.call_count, 0)
- self.assertEqual(ssh_helper.put.call_count, 0)
+ sample_vnf_deploy_helper.DISABLE_DEPLOY = True
+ self.assertEqual(ssh_helper.execute.call_count, 5)
+ self.assertEqual(ssh_helper.put.call_count, 1)
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
@mock.patch('subprocess.check_output')
@@ -1659,7 +1559,7 @@ class TestSampleVnf(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',
'dst_ip': '152.16.100.20',
'local_mac': '00:00:00:00:00:01'
@@ -1674,7 +1574,7 @@ class TestSampleVnf(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
'local_mac': '00:00:00:00:00:02'
@@ -1749,7 +1649,6 @@ class TestSampleVnf(unittest.TestCase):
class MySetupEnvHelper(SetupEnvHelper):
pass
-
class MyResourceHelper(ResourceHelper):
pass
@@ -1873,6 +1772,7 @@ class TestSampleVnf(unittest.TestCase):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
sample_vnf = SampleVNF('vnf1', vnfd)
sample_vnf.APP_NAME = 'sample1'
+ sample_vnf.WAIT_TIME_FOR_SCRIPT = 0
sample_vnf._start_server = mock.Mock(return_value=0)
sample_vnf._vnf_process = mock.MagicMock()
sample_vnf._vnf_process.exitcode = 0
@@ -1887,6 +1787,16 @@ class TestSampleVnf(unittest.TestCase):
self.assertEqual(sample_vnf.wait_for_instantiate(), 0)
+ def test__build_ports(self):
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ sample_vnf = SampleVNF('vnf1', vnfd)
+
+ self.assertIsNone(sample_vnf._build_ports())
+ self.assertIsNotNone(sample_vnf.networks)
+ self.assertIsNotNone(sample_vnf.uplink_ports)
+ self.assertIsNotNone(sample_vnf.downlink_ports)
+ self.assertIsNotNone(sample_vnf.my_ports)
+
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
def test_vnf_execute_with_queue_data(self, mock_time):
queue_size_list = [
@@ -2014,7 +1924,7 @@ class TestSampleVNFTrafficGen(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',
'dst_ip': '152.16.100.20',
'local_mac': '00:00:00:00:00:01'
@@ -2030,7 +1940,7 @@ class TestSampleVNFTrafficGen(unittest.TestCase):
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
'local_mac': '00:00:00:00:00:02'
@@ -2038,22 +1948,6 @@ class TestSampleVNFTrafficGen(unittest.TestCase):
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
},
- {
- 'virtual-interface': {
- 'dst_mac': '00:00:00:00:00:13',
- 'vpci': '0000:05:00.2',
- 'driver': 'ixgbe',
- '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.30',
- 'local_mac': '00:00:00:00:00:11'
- },
- 'vnfd-connection-point-ref': 'xe2',
- 'name': 'xe2'
- },
],
},
],
@@ -2124,58 +2018,36 @@ class TestSampleVNFTrafficGen(unittest.TestCase):
def test_terminate(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
sample_vnf_tg._traffic_process = mock.Mock()
+ sample_vnf_tg._tg_process = mock.Mock()
sample_vnf_tg.terminate()
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- def test_wait_for_instantiate(self, mock_logger, mock_time):
+ def test__wait_for_process(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0]))
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.return_value = True
- sample_vnf_tg._tg_process.exitcode = 234
-
- self.assertEqual(sample_vnf_tg.wait_for_instantiate(), 234)
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- def test_wait_for_instantiate_not_alive(self, mock_logger, mock_time):
+ with mock.patch.object(sample_vnf_tg, '_check_status',
+ return_value=0) as mock_status, \
+ mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = True
+ mock_proc.exitcode = 234
+ self.assertEqual(sample_vnf_tg._wait_for_process(), 234)
+ mock_proc.is_alive.assert_called_once()
+ mock_status.assert_called_once()
+
+ def test__wait_for_process_not_alive(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(return_value=1)
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.side_effect = iter([True, False])
- sample_vnf_tg._tg_process.exitcode = 234
-
- with self.assertRaises(RuntimeError):
- sample_vnf_tg.wait_for_instantiate()
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.Process')
- def test_wait_for_instantiate_delayed(self, mock_process, mock_logger, mock_time):
- class MockClientStarted(mock.Mock):
-
- def __init__(self, *args, **kwargs):
- super(MockClientStarted, self).__init__(*args, **kwargs)
- self.iter = iter([0, 0, 1])
-
- @property
- def value(self):
- return next(self.iter)
-
- mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
- mock_traffic_profile.get_traffic_definition.return_value = "64"
- mock_traffic_profile.execute.return_value = "64"
- mock_traffic_profile.params = self.TRAFFIC_PROFILE
+ with mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = False
+ self.assertRaises(RuntimeError, sample_vnf_tg._wait_for_process)
+ mock_proc.is_alive.assert_called_once()
+ def test__wait_for_process_delayed(self):
sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0)
- sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0]))
- sample_vnf_tg._tg_process = mock.Mock()
- sample_vnf_tg._tg_process.is_alive.return_value = True
- sample_vnf_tg._tg_process.exitcode = 234
- sample_vnf_tg.resource_helper = mock.Mock()
- sample_vnf_tg.resource_helper.client_started = MockClientStarted()
-
- self.assertTrue(sample_vnf_tg.run_traffic(mock_traffic_profile))
- self.assertEqual(mock_time.sleep.call_count, 2)
+ with mock.patch.object(sample_vnf_tg, '_check_status',
+ side_effect=[1, 0]) as mock_status, \
+ mock.patch.object(sample_vnf_tg,
+ '_tg_process') as mock_proc:
+ mock_proc.is_alive.return_value = True
+ mock_proc.exitcode = 234
+ self.assertEqual(sample_vnf_tg._wait_for_process(), 234)
+ mock_proc.is_alive.assert_has_calls([mock.call(), mock.call()])
+ mock_status.assert_has_calls([mock.call(), mock.call()])
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
index c65c0ab0a..e6e4b882e 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
@@ -70,7 +70,7 @@ class TestIxLoadTrafficGen(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',
@@ -85,7 +85,7 @@ class TestIxLoadTrafficGen(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',
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
index 45bbfaea3..c1b2d27eb 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
@@ -20,6 +20,7 @@ from __future__ import absolute_import
import unittest
import mock
from multiprocessing import Queue
+import multiprocessing
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from tests.unit import STL_MOCKS
@@ -31,11 +32,40 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.tg_ping import PingParser, PingTrafficGen
- from yardstick.network_services.traffic_profile.base import TrafficProfile
+ from yardstick.network_services.vnf_generic.vnf.tg_ping import PingParser
+ from yardstick.network_services.vnf_generic.vnf.tg_ping import PingTrafficGen
+ from yardstick.network_services.vnf_generic.vnf.tg_ping import PingResourceHelper
+ from yardstick.network_services.vnf_generic.vnf.tg_ping import PingSetupEnvHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import VnfSshHelper
+class TestPingResourceHelper(unittest.TestCase):
+ def test___init__(self):
+ setup_helper = mock.Mock()
+ helper = PingResourceHelper(setup_helper)
+
+ self.assertIsInstance(helper._queue, multiprocessing.queues.Queue)
+ self.assertIsInstance(helper._parser, PingParser)
+
+ def test_run_traffic(self):
+ setup_helper = mock.Mock()
+ traffic_profile = mock.Mock()
+ traffic_profile.params = {
+ 'traffic_profile': {
+ 'frame_size': 64,
+ },
+ }
+
+ helper = PingResourceHelper(setup_helper)
+ helper.cmd_kwargs = {'target_ip': '10.0.0.2',
+ 'local_ip': '10.0.0.1',
+ 'local_if_name': 'eth0',
+ }
+ helper.ssh_helper = mock.Mock()
+ helper.run_traffic(traffic_profile)
+ helper.ssh_helper.run.called_with('ping-s 64 10.0.0.2')
+
+
class TestPingParser(unittest.TestCase):
def test___init__(self):
q_out = Queue()
@@ -69,7 +99,6 @@ class TestPingParser(unittest.TestCase):
class TestPingTrafficGen(unittest.TestCase):
-
VNFD_0_EXT_IF_0 = {
'virtual-interface': {
'dst_mac': '00:00:00:00:00:04',
@@ -77,7 +106,6 @@ class TestPingTrafficGen(unittest.TestCase):
'local_ip': u'152.16.100.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '0',
'bandwidth': '10 Gbps',
'driver': "i40e",
'dst_ip': u'152.16.100.20',
@@ -96,14 +124,13 @@ class TestPingTrafficGen(unittest.TestCase):
'type': 'PCI-PASSTHROUGH',
'driver': "i40e",
'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
'bandwidth': '10 Gbps',
'dst_ip': u'152.16.40.20',
'local_iface_name': 'xe1',
'local_mac': '00:00:00:00:00:01',
},
- 'vnfd-connection-point-ref': 'xe1',
- 'name': 'xe1',
+ 'vnfd-connection-point-ref': 'xe1',
+ 'name': 'xe1',
}
VNFD_0_EXT_IF_LIST = [
@@ -151,7 +178,7 @@ class TestPingTrafficGen(unittest.TestCase):
],
'description': 'Vpe approximation using DPDK',
'mgmt-interface': {
- 'vdu-id': 'vpevnf-baremetal',
+ 'vdu-id': 'vpevnf-baremetal',
'host': '1.1.1.1',
'password': 'r00t',
'user': 'root',
@@ -198,11 +225,20 @@ class TestPingTrafficGen(unittest.TestCase):
},
}
+ CMD_KWARGS = {
+ 'target_ip': u'152.16.100.20',
+ 'local_ip': u'152.16.100.19',
+ 'local_if_name': u'xe0',
+ }
+
@mock.patch("yardstick.ssh.SSH")
def test___init__(self, ssh):
ssh.from_node.return_value.execute.return_value = 0, "success", ""
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
- self.assertIsNotNone(ping_traffic_gen._queue)
+
+ self.assertIsInstance(ping_traffic_gen.setup_helper, PingSetupEnvHelper)
+ self.assertIsInstance(ping_traffic_gen.resource_helper, PingResourceHelper)
+ self.assertEquals(ping_traffic_gen._result, {})
@mock.patch("yardstick.ssh.SSH")
def test__bind_device_kernel_with_failure(self, ssh):
@@ -234,35 +270,23 @@ class TestPingTrafficGen(unittest.TestCase):
mock_ssh(ssh, spec=VnfSshHelper, exec_result=(0, "success", ""))
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
ping_traffic_gen.setup_helper.ssh_helper = mock.MagicMock(
- **{"execute.return_value": (0, "", "")})
+ **{"execute.return_value": (0, "success", "")})
self.assertIsInstance(ping_traffic_gen.ssh_helper, mock.Mock)
self.assertEqual(ping_traffic_gen._result, {})
+
self.assertIsNone(ping_traffic_gen.instantiate({}, {}))
+
+ self.assertEqual(
+ ping_traffic_gen.vnfd_helper.interfaces[0]['virtual-interface']['local_iface_name'],
+ 'success')
+ self.assertEqual(self.CMD_KWARGS, ping_traffic_gen.resource_helper.cmd_kwargs)
self.assertIsNotNone(ping_traffic_gen._result)
@mock.patch("yardstick.ssh.SSH")
def test_listen_traffic(self, ssh):
- ssh.from_node.return_value.execute.return_value = 0, "success", ""
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
self.assertIsNone(ping_traffic_gen.listen_traffic({}))
- @mock.patch(SSH_HELPER)
- def test_run_traffic_process(self, ssh):
- mock_ssh(ssh)
-
- mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
- mock_traffic_profile.get_traffic_definition.return_value = "64"
- mock_traffic_profile.params = self.TRAFFIC_PROFILE
-
- ssh.from_node.return_value.execute.return_value = 0, "success", ""
- ssh.from_node.return_value.run.return_value = 0, "success", ""
-
- sut = PingTrafficGen('vnf1', self.VNFD_0)
- sut._traffic_runner(mock_traffic_profile)
- sut.ssh_helper.run.assert_called_with(
- "ping -s 64 152.16.100.20",
- stdout=sut._parser, keep_stdin_open=True, pty=True)
-
@mock.patch("yardstick.ssh.SSH")
def test_scale_negative(self, ssh):
ssh.from_node.return_value.execute.return_value = 0, "success", ""
@@ -277,4 +301,4 @@ class TestPingTrafficGen(unittest.TestCase):
ssh.from_node.return_value.run.return_value = 0, "success", ""
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
- self.assertIsNone(ping_traffic_gen.terminate()) \ No newline at end of file
+ self.assertIsNone(ping_traffic_gen.terminate())
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 12abadf98..23d448c5e 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
@@ -21,7 +21,6 @@ import mock
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from tests.unit import STL_MOCKS
-
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
NAME = 'vnf__1'
@@ -80,7 +79,7 @@ class TestProxTrafficGen(unittest.TestCase):
'type': 'PCI-PASSTHROUGH',
'vld_id': '',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '0',
+ 'dpdk_port_num': 0,
'bandwidth': '10 Gbps',
'driver': "i40e",
'dst_ip': '152.16.100.20',
@@ -99,7 +98,7 @@ class TestProxTrafficGen(unittest.TestCase):
'vld_id': '',
'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',
@@ -180,7 +179,7 @@ class TestProxTrafficGen(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
+ 'vld_id': ProxTrafficGen.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -214,7 +213,7 @@ class TestProxTrafficGen(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
+ 'vld_id': ProxTrafficGen.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -245,7 +244,7 @@ class TestProxTrafficGen(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
+ 'vld_id': ProxTrafficGen.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -257,7 +256,7 @@ class TestProxTrafficGen(unittest.TestCase):
},
'xe1': {
'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
+ 'vld_id': ProxTrafficGen.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -331,13 +330,15 @@ class TestProxTrafficGen(unittest.TestCase):
mock_ssh(ssh)
prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
- prox_traffic_gen._queue = mock.MagicMock()
+ 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())
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores')
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
@mock.patch(SSH_HELPER)
- def test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
+ def bad_test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
mock_ssh(ssh)
mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'}
@@ -348,8 +349,10 @@ class TestProxTrafficGen(unittest.TestCase):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
prox_traffic_gen = ProxTrafficGen(NAME, vnfd)
- prox_traffic_gen.ssh_helper = mock.MagicMock(
+ ssh_helper = mock.MagicMock(
**{"execute.return_value": (0, "", ""), "bin_path": ""})
+ prox_traffic_gen.ssh_helper = ssh_helper
+ prox_traffic_gen.setup_helper.dpdk_bind_helper.ssh_helper = ssh_helper
prox_traffic_gen.setup_helper._setup_resources = mock.MagicMock()
prox_traffic_gen.setup_hugepages = mock.MagicMock()
prox_traffic_gen.generate_prox_config_file = mock.MagicMock()
@@ -368,12 +371,12 @@ class TestProxTrafficGen(unittest.TestCase):
'task_path': '',
'options': {'tg__1': {'prox_args': {'-e': '',
'-t': ''},
- 'prox_config': 'configs/l3-gen-2.cfg',
- 'prox_path': '/root/dppd-PROX-v035/build/prox'},
- 'vnf__1': {'prox_args': {'-t': ''},
- 'prox_config': 'configs/l3-swap-2.cfg',
- 'prox_path': '/root/dppd-PROX-v035/build/prox'}
- }
+ 'prox_config': 'configs/l3-gen-2.cfg',
+ 'prox_path': '/root/dppd-PROX-v035/build/prox'},
+ 'vnf__1': {'prox_args': {'-t': ''},
+ 'prox_config': 'configs/l3-swap-2.cfg',
+ 'prox_path': '/root/dppd-PROX-v035/build/prox'}
+ }
}
prox_traffic_gen.instantiate(scenario_cfg, {})
@@ -383,16 +386,15 @@ class TestProxTrafficGen(unittest.TestCase):
mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
- mock_traffic_profile.execute.return_value = "64"
+ mock_traffic_profile.execute_traffic.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
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._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"]
+ sut.setup_helper.prox_config_dict = {}
sut._connect_client = mock.Mock(autospec=STLClient)
sut._connect_client.get_stats = mock.Mock(return_value="0")
sut._traffic_runner(mock_traffic_profile)
@@ -425,4 +427,7 @@ class TestProxTrafficGen(unittest.TestCase):
prox_traffic_gen.ssh_helper = mock.MagicMock()
prox_traffic_gen.setup_helper = mock.MagicMock()
prox_traffic_gen.resource_helper = mock.MagicMock()
+ prox_traffic_gen._vnf_wrapper.setup_helper = mock.MagicMock()
+ prox_traffic_gen._vnf_wrapper._vnf_process = mock.MagicMock()
+ prox_traffic_gen._vnf_wrapper.resource_helper = mock.MagicMock()
self.assertEqual(None, prox_traffic_gen.terminate())
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 661e885ca..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
@@ -23,7 +23,6 @@ import mock
from tests.unit import STL_MOCKS
-
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
@@ -36,13 +35,11 @@ if stl_patch:
TEST_FILE_YAML = 'nsb_test_case.yaml'
-
NAME = "tg__1"
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
class TestIxiaResourceHelper(unittest.TestCase):
-
def test___init___with_custom_rfc_helper(self, mock_ix_nextgen):
class MyRfcHelper(IxiaRfc2544Helper):
pass
@@ -63,71 +60,71 @@ class TestIxiaResourceHelper(unittest.TestCase):
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen")
class TestIXIATrafficGen(unittest.TestCase):
VNFD = {'vnfd:vnfd-catalog':
- {'vnfd':
- [{'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:04',
- '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',
- 'driver': "i40e",
- 'dst_ip': '152.16.100.20',
- 'local_iface_name': 'xe0',
- 'local_mac': '00:00:00:00:00:02'},
- 'vnfd-connection-point-ref': 'xe0',
- 'name': 'xe0'},
- {'virtual-interface':
- {'dst_mac': '00:00:00:00:00:03',
- 'vpci': '0000:05:00.1',
- 'local_ip': '152.16.40.19',
- 'type': 'PCI-PASSTHROUGH',
- 'driver': "i40e",
- 'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
- 'bandwidth': '10 Gbps',
- 'dst_ip': '152.16.40.20',
- 'local_iface_name': 'xe1',
- 'local_mac': '00:00:00:00:00:01'},
- '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'}]}}
+ {'vnfd':
+ [{'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:04',
+ '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',
+ 'driver': "i40e",
+ 'dst_ip': '152.16.100.20',
+ 'local_iface_name': 'xe0',
+ 'local_mac': '00:00:00:00:00:02'},
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0'},
+ {'virtual-interface':
+ {'dst_mac': '00:00:00:00:00:03',
+ 'vpci': '0000:05:00.1',
+ 'local_ip': '152.16.40.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'driver': "i40e",
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 1,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_iface_name': 'xe1',
+ 'local_mac': '00:00:00:00:00:01'},
+ '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'}]}}
TRAFFIC_PROFILE = {
"schema": "isb:traffic_profile:0.1",
@@ -140,12 +137,12 @@ class TestIXIATrafficGen(unittest.TestCase):
"frame_size": 64}}
TC_YAML = {'scenarios': [{'tc_options':
- {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
+ {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
'runner': {'duration': 400,
'interval': 35, 'type': 'Duration'},
'traffic_options':
- {'flow': 'ipv4_1flow_Packets_vpe.yaml',
- 'imix': 'imix_voice.yaml'},
+ {'flow': 'ipv4_1flow_Packets_vpe.yaml',
+ 'imix': 'imix_voice.yaml'},
'vnf_options': {'vpe': {'cfg': 'vpe_config'}},
'traffic_profile': 'ipv4_throughput_vpe.yaml',
'type': 'NSPerf',
@@ -195,7 +192,7 @@ class TestIXIATrafficGen(unittest.TestCase):
'vnf_config': {'lb_config': 'SW',
'lb_count': 1,
'worker_config':
- '1C/1T',
+ '1C/1T',
'worker_threads': 1}}
}})
ixnet_traffic_gen.topology = ""
@@ -255,6 +252,8 @@ 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)
mock_ssh_instance.execute.return_value = 0, "", ""
@@ -306,11 +305,10 @@ class TestIXIATrafficGen(unittest.TestCase):
},
]
- mock_traffic_profile.execute.return_value = ['Completed', samples]
+ mock_traffic_profile.execute_traffic.return_value = ['Completed', samples]
mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples]
sut = IxiaTrafficGen(name, vnfd)
- sut.tg_port_pairs = [[[0], [1]]]
sut.vnf_port_pairs = [[[0], [1]]]
sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
sut.topology = ""
@@ -325,13 +323,15 @@ class TestIXIATrafficGen(unittest.TestCase):
sut.resource_helper.client = mock.MagicMock()
sut.resource_helper.client_started = mock.MagicMock()
sut.resource_helper.client_started.value = 1
+ sut.resource_helper.rfc_helper.iteration.value = 11
sut.scenario_helper.scenario_cfg = {
'options': {
'packetsize': 64,
'traffic_type': 4,
'rfc2544': {
- 'allowed_drop_rate': '0.8 - 1'
+ 'allowed_drop_rate': '0.8 - 1',
+ 'latency': True
},
'vnf__1': {
'rules': 'acl_1rule.yaml',
@@ -347,7 +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_tg_rfc2544_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
index ad8c6494e..637706fb4 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
@@ -21,10 +21,9 @@ import unittest
import mock
from tests.unit import STL_MOCKS
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
-SSH_HELPER = "yardstick.ssh.SSH"
-
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
@@ -101,8 +100,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
'local_ip': '152.16.100.19',
'type': 'PCI-PASSTHROUGH',
'netmask': '255.255.255.0',
- 'vld_id': 'private_1',
- 'dpdk_port_num': '0',
+ 'vld_id': 'uplink_0',
+ 'dpdk_port_num': 0,
'bandwidth': '10 Gbps',
'driver': "i40e",
'dst_ip': '152.16.100.20',
@@ -121,8 +120,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
'type': 'PCI-PASSTHROUGH',
'driver': "i40e",
'netmask': '255.255.255.0',
- 'vld_id': 'public_1',
- 'dpdk_port_num': '1',
+ 'vld_id': 'downlink_0',
+ 'dpdk_port_num': 1,
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
'local_iface_name': 'xe1',
@@ -252,6 +251,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
trex_traffic_gen._start_server = mock.Mock(return_value=0)
trex_traffic_gen.resource_helper = mock.MagicMock()
+ trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
+
scenario_cfg = {
"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
"topology": 'nsb_test_case.yaml',
@@ -286,6 +287,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
trex_traffic_gen.resource_helper = mock.MagicMock()
+ trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
scenario_cfg = {
"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
"nodes": [
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
index 65370dfa5..a2a5058fc 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
@@ -18,12 +18,15 @@
from __future__ import absolute_import
import unittest
+
+import copy
import mock
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
+
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from tests.unit import STL_MOCKS
-
NAME = 'vnf_1'
STLClient = mock.MagicMock()
@@ -32,77 +35,81 @@ stl_patch.start()
if stl_patch:
from yardstick.network_services.vnf_generic.vnf.tg_trex import \
- TrexTrafficGen, TrexResourceHelper
+ TrexTrafficGen, TrexResourceHelper
from yardstick.network_services.traffic_profile.base import TrafficProfile
class TestTrexTrafficGen(unittest.TestCase):
VNFD = {'vnfd:vnfd-catalog':
- {'vnfd':
- [{'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:04',
- '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',
- 'driver': "i40e",
- 'dst_ip': '152.16.100.20',
- 'local_iface_name': 'xe0',
- 'local_mac': '00:00:00:00:00:02'},
- 'vnfd-connection-point-ref': 'xe0',
- 'name': 'xe0'},
- {'virtual-interface':
- {'dst_mac': '00:00:00:00:00:03',
- 'vpci': '0000:05:00.1',
- 'local_ip': '152.16.40.19',
- 'type': 'PCI-PASSTHROUGH',
- 'driver': "i40e",
- 'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
- 'bandwidth': '10 Gbps',
- 'dst_ip': '152.16.40.20',
- 'local_iface_name': 'xe1',
- 'local_mac': '00:00:00:00:00:01'},
- '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'}]}}
+ {'vnfd':
+ [{'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:04',
+ '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',
+ 'driver': "i40e",
+ 'dst_ip': '152.16.100.20',
+ 'local_iface_name': 'xe0',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe0',
+ 'local_mac': '00:00:00:00:00:02'},
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0'},
+ {'virtual-interface':
+ {'dst_mac': '00:00:00:00:00:03',
+ 'vpci': '0000:05:00.1',
+ 'local_ip': '152.16.40.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'driver': "i40e",
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 1,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_iface_name': 'xe1',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe1',
+ 'local_mac': '00:00:00:00:00:01'},
+ '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'}]}}
TRAFFIC_PROFILE = {
"schema": "isb:traffic_profile:0.1",
@@ -112,16 +119,195 @@ class TestTrexTrafficGen(unittest.TestCase):
"traffic_type": "FixedTraffic",
"frame_rate": 100, # pps
"flow_number": 10,
- "frame_size": 64}}
+ "frame_size": 64
+ },
+ }
- @mock.patch("yardstick.ssh.SSH")
+ 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",
+ "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": "udpreplay-tg-topology-baremetal.yaml"
+ }
+
+ CONTEXT_CFG = {
+ "nodes": {
+ "vnf__1": {
+ "vnfd-id-ref": "vnf__1",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens786f0",
+ "vld_id": TrafficProfile.UPLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.0",
+ "local_ip": "152.16.100.19",
+ "driver": "i40e",
+ "dst_ip": "152.16.100.20",
+ "local_mac": "00:00:00:00:00:02",
+ "dst_mac": "00:00:00:00:00:04",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_iface_name": "ens786f1",
+ "vld_id": TrafficProfile.DOWNLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.1",
+ "local_ip": "152.16.40.19",
+ "driver": "i40e",
+ "dst_ip": "152.16.40.20",
+ "local_mac": "00:00:00:00:00:01",
+ "dst_mac": "00:00:00:00:00:03",
+ "dpdk_port_num": 1
+ }
+ },
+ "host": "1.2.1.1",
+ "user": "root",
+ "nd_route_tbl": [
+ {
+ "netmask": "112",
+ "if": "xe0",
+ "gateway": "0064:ff9b:0:0:0:0:9810:6414",
+ "network": "0064:ff9b:0:0:0:0:9810:6414"
+ },
+ {
+ "netmask": "112",
+ "if": "xe1",
+ "gateway": "0064:ff9b:0:0:0:0:9810:2814",
+ "network": "0064:ff9b:0:0:0:0:9810:2814"
+ }
+ ],
+ "password": "r00t",
+ "VNF model": "udp_replay.yaml",
+ "name": "vnf.yardstick",
+ "member-vnf-index": "2",
+ "routing_table": [
+ {
+ "netmask": "255.255.255.0",
+ "if": "xe0",
+ "gateway": "152.16.100.20",
+ "network": "152.16.100.20"
+ },
+ {
+ "netmask": "255.255.255.0",
+ "if": "xe1",
+ "gateway": "152.16.40.20",
+ "network": "152.16.40.20"
+ }
+ ],
+ "role": "vnf"
+ },
+ "trafficgen_2.yardstick": {
+ "member-vnf-index": "3",
+ "role": "TrafficGen",
+ "name": "trafficgen_2.yardstick",
+ "vnfd-id-ref": "tg__2",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens513f0",
+ "vld_id": TrafficProfile.DOWNLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:02:00.0",
+ "local_ip": "152.16.40.20",
+ "driver": "ixgbe",
+ "dst_ip": "152.16.40.19",
+ "local_mac": "00:00:00:00:00:03",
+ "dst_mac": "00:00:00:00:00:01",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_iface_name": "ens513f1",
+ "netmask": "255.255.255.0",
+ "network": "202.16.100.0",
+ "local_ip": "202.16.100.20",
+ "driver": "ixgbe",
+ "local_mac": "00:1e:67:d0:60:5d",
+ "vpci": "0000:02:00.1",
+ "dpdk_port_num": 1
+ }
+ },
+ "password": "r00t",
+ "VNF model": "l3fwd_vnf.yaml",
+ "user": "root"
+ },
+ "trafficgen_1.yardstick": {
+ "member-vnf-index": "1",
+ "role": "TrafficGen",
+ "name": "trafficgen_1.yardstick",
+ "vnfd-id-ref": "tg__1",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens785f0",
+ "vld_id": TrafficProfile.UPLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.0",
+ "local_ip": "152.16.100.20",
+ "driver": "i40e",
+ "dst_ip": "152.16.100.19",
+ "local_mac": "00:00:00:00:00:04",
+ "dst_mac": "00:00:00:00:00:02",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_ip": "152.16.100.21",
+ "driver": "i40e",
+ "vpci": "0000:05:00.1",
+ "dpdk_port_num": 1,
+ "local_iface_name": "ens785f1",
+ "netmask": "255.255.255.0",
+ "local_mac": "00:00:00:00:00:01"
+ }
+ },
+ "password": "r00t",
+ "VNF model": "tg_rfc2544_tpl.yaml",
+ "user": "root"
+ }
+ }
+ }
+
+ @mock.patch(SSH_HELPER)
def test___init__(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
self.assertIsInstance(trex_traffic_gen.resource_helper, TrexResourceHelper)
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -130,14 +316,14 @@ class TestTrexTrafficGen(unittest.TestCase):
result = trex_traffic_gen.collect_kpi()
self.assertEqual({}, result)
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_listen_traffic(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
self.assertIsNone(trex_traffic_gen.listen_traffic({}))
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_instantiate(self, ssh):
mock_ssh(ssh)
@@ -150,9 +336,11 @@ class TestTrexTrafficGen(unittest.TestCase):
trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=1)
trex_traffic_gen.ssh_helper = mock.MagicMock()
trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
- self.assertIsNone(trex_traffic_gen.instantiate({}, {}))
+ trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
+
+ self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_instantiate_error(self, ssh):
mock_ssh(ssh, exec_result=(1, "", ""))
@@ -164,38 +352,51 @@ class TestTrexTrafficGen(unittest.TestCase):
trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=0)
trex_traffic_gen.ssh_helper = mock.MagicMock()
trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
- self.assertIsNone(trex_traffic_gen.instantiate({}, {}))
+ trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
+ self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test__start_server(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
trex_traffic_gen.ssh_helper = mock.MagicMock()
trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
+ trex_traffic_gen.scenario_helper.scenario_cfg = {}
+ self.assertIsNone(trex_traffic_gen._start_server())
+
+ @mock.patch(SSH_HELPER)
+ def test__start_server_multiple_queues(self, ssh):
+ mock_ssh(ssh)
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
+ trex_traffic_gen.ssh_helper = mock.MagicMock()
+ trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
+ trex_traffic_gen.scenario_helper.scenario_cfg = {"options": {NAME: {"queues_per_port": 2}}}
self.assertIsNone(trex_traffic_gen._start_server())
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test__traffic_runner(self, ssh):
mock_ssh(ssh)
mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
- mock_traffic_profile.execute.return_value = "64"
+ mock_traffic_profile.execute_traffic.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.sut = TrexTrafficGen(NAME, vnfd)
self.sut.ssh_helper = mock.Mock()
self.sut.ssh_helper.run = mock.Mock()
- self.sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"]
self.sut._connect_client = mock.Mock(autospec=STLClient)
self.sut._connect_client.get_stats = mock.Mock(return_value="0")
self.sut.resource_helper.RUN_DURATION = 0
self.sut.resource_helper.QUEUE_WAIT_TIME = 0
+ # must generate cfg before we can run traffic so Trex port mapping is created
+ self.sut.resource_helper.generate_cfg()
self.sut._traffic_runner(mock_traffic_profile)
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test__generate_trex_cfg(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -203,7 +404,53 @@ class TestTrexTrafficGen(unittest.TestCase):
trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
+ def test_build_ports_reversed_pci_ordering(self, ssh):
+ mock_ssh(ssh)
+ vnfd = copy.deepcopy(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0])
+ vnfd['vdu'][0]['external-interface'] = [
+ {'virtual-interface':
+ {'dst_mac': '00:00:00:00:00:04',
+ 'vpci': '0000:05:00.0',
+ 'local_ip': '152.16.100.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 2,
+ 'bandwidth': '10 Gbps',
+ 'driver': "i40e",
+ 'dst_ip': '152.16.100.20',
+ 'local_iface_name': 'xe0',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe0',
+ 'local_mac': '00:00:00:00:00:02'},
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0'},
+ {'virtual-interface':
+ {'dst_mac': '00:00:00:00:00:03',
+ 'vpci': '0000:04:00.0',
+ 'local_ip': '152.16.40.19',
+ 'type': 'PCI-PASSTHROUGH',
+ 'driver': "i40e",
+ 'netmask': '255.255.255.0',
+ 'dpdk_port_num': 0,
+ 'bandwidth': '10 Gbps',
+ 'dst_ip': '152.16.40.20',
+ 'local_iface_name': 'xe1',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe1',
+ 'local_mac': '00:00:00:00:00:01'},
+ 'vnfd-connection-point-ref': 'xe1',
+ 'name': 'xe1'}]
+ trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
+ trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
+ trex_traffic_gen.resource_helper.generate_cfg()
+ trex_traffic_gen.resource_helper._build_ports()
+ self.assertEqual(sorted(trex_traffic_gen.resource_helper.all_ports), [0, 1])
+ # there is a gap in ordering
+ self.assertEqual(dict(trex_traffic_gen.resource_helper.dpdk_to_trex_port_map),
+ {0: 0, 2: 1})
+
+ @mock.patch(SSH_HELPER)
def test_run_traffic(self, ssh):
mock_ssh(ssh)
@@ -221,21 +468,14 @@ class TestTrexTrafficGen(unittest.TestCase):
self.sut._traffic_process.terminate()
self.assertIsNotNone(result)
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_scale(self, ssh):
mock_ssh(ssh, exec_result=(1, "", ""))
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
trex_traffic_gen.scale('')
- @mock.patch("yardstick.ssh.SSH")
- def test_setup_vnf_environment(self, ssh):
- mock_ssh(ssh, exec_result=(1, "", ""))
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
- self.assertIsNone(trex_traffic_gen.setup_helper.setup_vnf_environment())
-
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test_terminate(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -244,7 +484,7 @@ class TestTrexTrafficGen(unittest.TestCase):
trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
self.assertIsNone(trex_traffic_gen.terminate())
- @mock.patch("yardstick.ssh.SSH")
+ @mock.patch(SSH_HELPER)
def test__connect_client(self, ssh):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -253,5 +493,6 @@ class TestTrexTrafficGen(unittest.TestCase):
client.connect = mock.Mock(return_value=0)
self.assertIsNotNone(trex_traffic_gen.resource_helper._connect(client))
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
index f0d75d57b..d4d3439f3 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
@@ -22,6 +22,7 @@ import mock
import os
from tests.unit import STL_MOCKS
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
STLClient = mock.MagicMock()
@@ -30,381 +31,459 @@ stl_patch.start()
if stl_patch:
from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
- from yardstick.network_services.vnf_generic.vnf import udp_replay
+ from yardstick.network_services.nfvi.resource import ResourceProfile
+ from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
+
+from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
TEST_FILE_YAML = 'nsb_test_case.yaml'
-NAME = "tg__1"
+NAME = "vnf__1"
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
-class TestAclApproxVnf(unittest.TestCase):
- VNFD = {'vnfd:vnfd-catalog':
- {'vnfd':
- [{'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:04',
- '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',
- 'driver': "i40e",
- 'dst_ip': '152.16.100.20',
- 'local_iface_name': 'xe0',
- 'local_mac': '00:00:00:00:00:02'},
- 'vnfd-connection-point-ref': 'xe0',
- 'name': 'xe0'},
- {'virtual-interface':
- {'dst_mac': '00:00:00:00:00:03',
- 'vpci': '0000:05:00.1',
- 'local_ip': '152.16.40.19',
- 'type': 'PCI-PASSTHROUGH',
- 'driver': "i40e",
- 'netmask': '255.255.255.0',
- 'dpdk_port_num': '1',
- 'bandwidth': '10 Gbps',
- 'dst_ip': '152.16.40.20',
- 'local_iface_name': 'xe1',
- 'local_mac': '00:00:00:00:00:01'},
- 'vnfd-connection-point-ref': 'xe1',
- 'name': 'xe1'}]}],
- 'description': 'Vpe approximation using DPDK',
- 'mgmt-interface':
- {'vdu-id': 'vpevnf-baremetal',
- 'host': '1.2.1.1',
- 'password': 'r00t',
- 'user': 'root',
- 'ip': '1.2.1.1'},
- 'benchmark':
- {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
- 'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
- {'type': 'VPORT', 'name': 'xe1'}],
- 'id': 'UdpReplayApproxVnf', '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',
- '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'}
-
- context_cfg = {'nodes': {'trafficgen_2.yardstick':
- {'member-vnf-index': '3',
- 'role': 'TrafficGen',
- 'name': 'trafficgen_2.yardstick',
- 'vnfd-id-ref': 'tg__2',
- 'ip': '1.2.1.1',
- 'interfaces':
- {'xe0': {'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
- 'netmask': '255.255.255.0',
- 'local_ip': '152.16.40.20',
- 'dst_mac': '00:00:00:00:00:01',
- 'local_mac': '00:00:00:00:00:03',
- 'dst_ip': '152.16.40.19',
- 'driver': 'ixgbe',
- 'vpci': '0000:02:00.0',
- 'dpdk_port_num': 0},
- 'xe1': {'local_iface_name': 'ens513f1',
- 'netmask': '255.255.255.0',
- 'network': '202.16.100.0',
- 'local_ip': '202.16.100.20',
- 'local_mac': '00:1e:67:d0:60:5d',
- 'driver': 'ixgbe',
- 'vpci': '0000:02:00.1',
- 'dpdk_port_num': 1}},
- 'password': 'r00t',
- 'VNF model': 'l3fwd_vnf.yaml',
- 'user': 'root'},
- 'trafficgen_1.yardstick':
- {'member-vnf-index': '1',
- 'role': 'TrafficGen',
- 'name': 'trafficgen_1.yardstick',
- 'vnfd-id-ref': 'tg__1',
- 'ip': '1.2.1.1',
- 'interfaces':
- {'xe0': {'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
- 'netmask': '255.255.255.0',
- 'local_ip': '152.16.100.20',
- 'dst_mac': '00:00:00:00:00:02',
- 'local_mac': '00:00:00:00:00:04',
- 'dst_ip': '152.16.100.19',
- 'driver': 'i40e',
- 'vpci': '0000:05:00.0',
- 'dpdk_port_num': 0},
- 'xe1': {'local_iface_name': 'ens785f1',
- 'netmask': '255.255.255.0',
- 'local_ip': '152.16.100.21',
- 'local_mac': '00:00:00:00:00:01',
- 'driver': 'i40e',
- 'vpci': '0000:05:00.1',
- 'dpdk_port_num': 1}},
- 'password': 'r00t',
- 'VNF model': 'tg_rfc2544_tpl.yaml',
- 'user': 'root'},
- 'vnf__1':
- {'name': 'vnf.yardstick',
- 'vnfd-id-ref': 'vnf__1',
- 'ip': '1.2.1.1',
- 'interfaces':
- {'xe0': {'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
- 'netmask': '255.255.255.0',
- 'local_ip': '152.16.100.19',
- 'dst_mac': '00:00:00:00:00:04',
- 'local_mac': '00:00:00:00:00:02',
- 'dst_ip': '152.16.100.20',
- 'driver': 'i40e',
- 'vpci': '0000:05:00.0',
- 'dpdk_port_num': 0},
- 'xe1': {'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
- 'netmask': '255.255.255.0',
- 'local_ip': '152.16.40.19',
- 'dst_mac': '00:00:00:00:00:03',
- 'local_mac': '00:00:00:00:00:01',
- 'dst_ip': '152.16.40.20',
- 'driver': 'i40e',
- 'vpci': '0000:05:00.1',
- 'dpdk_port_num': 1}},
- 'routing_table':
- [{'netmask': '255.255.255.0',
- 'gateway': '152.16.100.20',
- 'network': '152.16.100.20',
- 'if': 'xe0'},
- {'netmask': '255.255.255.0',
- 'gateway': '152.16.40.20',
- 'network': '152.16.40.20',
- 'if': 'xe1'}],
- 'member-vnf-index': '2',
- 'host': '1.2.1.1',
- 'role': 'vnf',
- 'user': 'root',
- 'nd_route_tbl':
- [{'netmask': '112',
- 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
- 'network': '0064:ff9b:0:0:0:0:9810:6414',
- 'if': 'xe0'},
- {'netmask': '112',
- 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
- 'network': '0064:ff9b:0:0:0:0:9810:2814',
- 'if': 'xe1'}],
- 'password': 'r00t',
- 'VNF model': 'udp_replay.yaml'}}}
-
- def test___init__(self, mock_process):
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- self.assertIsNone(udp_approx_vnf._vnf_process)
+class TestUdpReplayApproxVnf(unittest.TestCase):
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_collect_kpi(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
- "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
- "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
- "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- udp_approx_vnf.q_in = mock.MagicMock()
- udp_approx_vnf.q_out = mock.MagicMock()
- udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- udp_approx_vnf.all_ports = [0, 1]
- udp_approx_vnf.interfaces = vnfd["vdu"][0]['external-interface']
- udp_approx_vnf.get_stats = mock.Mock(return_value=result)
- result = {'collect_stats': {}, 'packets_dropped': 0,
- 'packets_fwd': 14748451, 'packets_in': 14748472}
- self.assertEqual(result, udp_approx_vnf.collect_kpi())
+ VNFD_0 = {
+ 'short-name': 'UdpReplayVnf',
+ 'vdu': [
+ {
+ 'description': 'UDPReplay approximation using DPDK',
+ 'routing_table': [
+ {
+ 'netmask': '255.255.255.0',
+ 'if': 'xe0',
+ 'network': '152.16.100.20',
+ 'gateway': '152.16.100.20',
+ },
+ {
+ 'netmask': '255.255.255.0',
+ 'if': 'xe1',
+ 'network': '152.16.40.20',
+ 'gateway': '152.16.40.20',
+ }
+ ],
+ 'external-interface': [
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:04',
+ 'driver': 'i40e',
+ 'local_iface_name': 'xe0',
+ 'bandwidth': '10 Gbps',
+ 'local_ip': '152.16.100.19',
+ 'local_mac': '00:00:00:00:00:02',
+ 'vpci': '0000:05:00.0',
+ 'dpdk_port_num': 0,
+ 'netmask': '255.255.255.0',
+ 'dst_ip': '152.16.100.20',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
+ },
+ 'vnfd-connection-point-ref': 'xe0',
+ 'name': 'xe0',
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:00:00:03',
+ 'driver': 'i40e',
+ 'local_iface_name': 'xe1',
+ 'bandwidth': '10 Gbps',
+ 'local_ip': '152.16.40.19',
+ 'local_mac': '00:00:00:00:00:01',
+ 'vpci': '0000:05:00.1',
+ 'dpdk_port_num': 1,
+ 'netmask': '255.255.255.0',
+ 'dst_ip': '152.16.40.20',
+ 'type': 'PCI-PASSTHROUGH',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
+ },
+ 'vnfd-connection-point-ref': 'xe1',
+ 'name': 'xe1',
+ }
+ ],
+ 'nd_route_tbl': [
+ {
+ 'netmask': '112',
+ 'if': 'xe0',
+ 'network': '0064:ff9b:0:0:0:0:9810:6414',
+ 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
+ },
+ {
+ 'netmask': '112',
+ 'if': 'xe1',
+ 'network': '0064:ff9b:0:0:0:0:9810:2814',
+ 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
+ }
+ ],
+ 'id': 'udpreplayvnf-baremetal',
+ 'name': 'udpreplayvnf-baremetal',
+ }
+ ],
+ 'description': 'UDPReplay approximation using DPDK',
+ 'name': 'VPEVnfSsh',
+ 'mgmt-interface': {
+ 'vdu-id': 'udpreplay-baremetal',
+ 'host': '1.2.1.1',
+ 'password': 'r00t',
+ 'user': 'root',
+ 'ip': '1.2.1.1',
+ },
+ 'benchmark': {
+ 'kpi': [
+ 'packets_in',
+ 'packets_fwd',
+ 'packets_dropped',
+ ]
+ },
+ 'connection-point': [
+ {
+ 'type': 'VPORT',
+ 'name': 'xe0',
+ },
+ {
+ 'type': 'VPORT',
+ 'name': 'xe1',
+ }
+ ],
+ 'id': 'UdpReplayApproxVnf',
+ }
+
+ 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,
+ },
+ "hw_csum": "false",
+ }
+ },
+ "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
+ "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": "udpreplay-tg-topology-baremetal.yaml"
+ }
+
+ CONTEXT_CFG = {
+ "nodes": {
+ "vnf__1": {
+ "vnfd-id-ref": "vnf__1",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens786f0",
+ "vld_id": UdpReplayApproxVnf.UPLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.0",
+ "local_ip": "152.16.100.19",
+ "driver": "i40e",
+ "dst_ip": "152.16.100.20",
+ "local_mac": "00:00:00:00:00:02",
+ "dst_mac": "00:00:00:00:00:04",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_iface_name": "ens786f1",
+ "vld_id": UdpReplayApproxVnf.DOWNLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.1",
+ "local_ip": "152.16.40.19",
+ "driver": "i40e",
+ "dst_ip": "152.16.40.20",
+ "local_mac": "00:00:00:00:00:01",
+ "dst_mac": "00:00:00:00:00:03",
+ "dpdk_port_num": 1
+ }
+ },
+ "host": "1.2.1.1",
+ "user": "root",
+ "nd_route_tbl": [
+ {
+ "netmask": "112",
+ "if": "xe0",
+ "gateway": "0064:ff9b:0:0:0:0:9810:6414",
+ "network": "0064:ff9b:0:0:0:0:9810:6414"
+ },
+ {
+ "netmask": "112",
+ "if": "xe1",
+ "gateway": "0064:ff9b:0:0:0:0:9810:2814",
+ "network": "0064:ff9b:0:0:0:0:9810:2814"
+ }
+ ],
+ "password": "r00t",
+ "VNF model": "udp_replay.yaml",
+ "name": "vnf.yardstick",
+ "member-vnf-index": "2",
+ "routing_table": [
+ {
+ "netmask": "255.255.255.0",
+ "if": "xe0",
+ "gateway": "152.16.100.20",
+ "network": "152.16.100.20"
+ },
+ {
+ "netmask": "255.255.255.0",
+ "if": "xe1",
+ "gateway": "152.16.40.20",
+ "network": "152.16.40.20"
+ }
+ ],
+ "role": "vnf"
+ },
+ "trafficgen_2.yardstick": {
+ "member-vnf-index": "3",
+ "role": "TrafficGen",
+ "name": "trafficgen_2.yardstick",
+ "vnfd-id-ref": "tg__2",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens513f0",
+ "vld_id": UdpReplayApproxVnf.DOWNLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:02:00.0",
+ "local_ip": "152.16.40.20",
+ "driver": "ixgbe",
+ "dst_ip": "152.16.40.19",
+ "local_mac": "00:00:00:00:00:03",
+ "dst_mac": "00:00:00:00:00:01",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_iface_name": "ens513f1",
+ "netmask": "255.255.255.0",
+ "network": "202.16.100.0",
+ "local_ip": "202.16.100.20",
+ "driver": "ixgbe",
+ "local_mac": "00:1e:67:d0:60:5d",
+ "vpci": "0000:02:00.1",
+ "dpdk_port_num": 1
+ }
+ },
+ "password": "r00t",
+ "VNF model": "l3fwd_vnf.yaml",
+ "user": "root"
+ },
+ "trafficgen_1.yardstick": {
+ "member-vnf-index": "1",
+ "role": "TrafficGen",
+ "name": "trafficgen_1.yardstick",
+ "vnfd-id-ref": "tg__1",
+ "ip": "1.2.1.1",
+ "interfaces": {
+ "xe0": {
+ "local_iface_name": "ens785f0",
+ "vld_id": UdpReplayApproxVnf.UPLINK,
+ "netmask": "255.255.255.0",
+ "vpci": "0000:05:00.0",
+ "local_ip": "152.16.100.20",
+ "driver": "i40e",
+ "dst_ip": "152.16.100.19",
+ "local_mac": "00:00:00:00:00:04",
+ "dst_mac": "00:00:00:00:00:02",
+ "dpdk_port_num": 0
+ },
+ "xe1": {
+ "local_ip": "152.16.100.21",
+ "driver": "i40e",
+ "vpci": "0000:05:00.1",
+ "dpdk_port_num": 1,
+ "local_iface_name": "ens785f1",
+ "netmask": "255.255.255.0",
+ "local_mac": "00:00:00:00:00:01"
+ }
+ },
+ "password": "r00t",
+ "VNF model": "tg_rfc2544_tpl.yaml",
+ "user": "root"
+ }
+ }
+ }
+
+ def test___init__(self, _):
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ self.assertIsNone(udp_replay_approx_vnf._vnf_process)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_vnf_execute_command(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- cmd = "quit"
- self.assertEqual("", udp_approx_vnf.vnf_execute(cmd))
-
- def test_get_stats(self, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- udp_approx_vnf.q_in = mock.MagicMock()
- udp_approx_vnf.q_out = mock.MagicMock()
- udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- mock_result = \
- "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
- udp_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
- self.assertEqual(mock_result,
- udp_approx_vnf.get_stats())
+ @mock.patch(SSH_HELPER)
+ def test_collect_kpi(self, ssh, mock_time, _):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD_0
+ result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \
+ "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
+ "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
+ "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
+ udp_replay_approx_vnf.q_in = mock.MagicMock()
+ udp_replay_approx_vnf.q_out = mock.MagicMock()
+ udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
+ udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result)
+ result = {'collect_stats': {}, 'packets_dropped': 0,
+ 'packets_fwd': 14748451, 'packets_in': 14748472}
+ self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
+
+ @mock.patch(SSH_HELPER)
+ def test_get_stats(self, ssh, _):
+ mock_ssh(ssh)
+
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf.q_in = mock.MagicMock()
+ udp_replay_approx_vnf.q_out = mock.MagicMock()
+ udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ mock_result = \
+ "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
+
+ udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result)
+
+ self.assertEqual(mock_result,
+ udp_replay_approx_vnf.get_stats())
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(curr_path, filename)
return file_path
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch(SSH_HELPER)
+ def test__build_config(self, ssh, mock_context, *_):
+ mock_ssh(ssh)
+
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
+ udp_replay_approx_vnf.nfvi_context = mock_context
+ udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
+ udp_replay_approx_vnf.setup_helper.bound_pci = []
+ udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
+ udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
+ udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
+
+ cmd_line = udp_replay_approx_vnf._build_config()
+
+ expected = \
+ "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'"
+ self.assertEqual(cmd_line, expected)
+
@mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
- def test__build_pipeline_kwargs(self, mock_open, mock_process):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh.from_node.return_value = ssh_mock
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- udp_approx_vnf._build_config = mock.MagicMock()
- udp_approx_vnf.queue_wrapper = mock.MagicMock()
- udp_approx_vnf.nfvi_type = "baremetal"
- udp_approx_vnf.bound_pci = []
- udp_approx_vnf.all_ports = [0, 1]
- udp_approx_vnf.ssh_helper = mock.MagicMock(
- **{"provision_tool.return_value": "tool_path"})
- udp_approx_vnf.vnf_cfg = {'lb_config': 'SW',
- 'lb_count': 1,
- 'worker_config': '1C/1T',
- 'worker_threads': 1}
- udp_approx_vnf.options = {'traffic_type': '4',
- 'topology': 'nsb_test_case.yaml'}
-
- udp_approx_vnf._build_pipeline_kwargs()
- self.assertEqual(udp_approx_vnf.pipeline_kwargs, {
- 'config': '(0, 0, 1)(1, 0, 2)',
- 'cpu_mask_hex': '0x6',
- 'hw_csum': '',
- 'ports_len_hex': '0x3',
- 'tool_path': 'tool_path',
- 'whitelist': ''
- })
-
- @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.hex")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.eval")
- @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
- def test_run_udp_replay(self, mock_open, eval, hex, mock_process):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "", ""))
- ssh_mock.run = \
- mock.Mock(return_value=(0, "", ""))
- ssh.from_node.return_value = ssh_mock
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- udp_approx_vnf._build_config = mock.MagicMock()
- udp_approx_vnf.queue_wrapper = mock.MagicMock()
- udp_approx_vnf.ssh_helper = mock.MagicMock()
- udp_approx_vnf.ssh_helper.run = mock.MagicMock()
- udp_approx_vnf.vnf_cfg = {'lb_config': 'SW',
- 'lb_count': 1,
- 'worker_config': '1C/1T',
- 'worker_threads': 1}
- udp_approx_vnf.options = {'traffic_type': '4',
- 'topology': 'nsb_test_case.yaml'}
-
- udp_approx_vnf._run()
- udp_approx_vnf.ssh_helper.run.assert_called_once()
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch(SSH_HELPER)
+ def test__build_pipeline_kwargs(self, ssh, mock_context, *_):
+ mock_ssh(ssh)
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf.nfvi_context = mock_context
+ udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
+ udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
+ udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
+ udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
+ udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
+ udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
+
+ udp_replay_approx_vnf._build_pipeline_kwargs()
+
+ self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, {
+ 'config': '(0,0,1),(1,0,2)',
+ 'cpu_mask_hex': '0x7',
+ 'hw_csum': '',
+ 'port_mask_hex': '0x3',
+ 'tool_path': 'tool_path',
+ 'whitelist': '0000:00:0.1 -w 0000:00:0.3'
+ })
+
+ @mock.patch(SSH_HELPER)
+ def test_run_udp_replay(self, ssh, _):
+ mock_ssh(ssh)
+
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf._build_config = mock.MagicMock()
+ udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
+ udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
+
+ udp_replay_approx_vnf._run()
+
+ udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
- def test_instantiate(self, Context, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- self.scenario_cfg['vnf_options'] = {'cgnapt': {'cfg': "",
- 'rules': ""}}
- udp_approx_vnf._run_udp_replay = mock.Mock(return_value=0)
- udp_approx_vnf._parse_rule_file = mock.Mock(return_value={})
- udp_approx_vnf.deploy_udp_replay_vnf = mock.Mock(return_value=1)
- udp_approx_vnf.q_out.put("Replay>")
- udp_approx_vnf.get_my_ports = mock.Mock(return_value=[0, 1])
- udp_replay.WAIT_TIME = 3
- udp_approx_vnf.get_nfvi_type = mock.Mock(return_value="baremetal")
-
- udp_approx_vnf._vnf_process = mock.MagicMock()
- udp_approx_vnf._vnf_process.is_alive = \
- mock.Mock(return_value=1)
- self.assertIsNone(udp_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
-
- def test_scale(self, mock_process):
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
+ @mock.patch(SSH_HELPER)
+ def test_instantiate(self, ssh, *_):
+ mock_ssh(ssh)
+
+ resource = mock.Mock(autospec=ResourceProfile)
+
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf.q_out.put("Replay>")
+ udp_replay_approx_vnf.WAIT_TIME = 0
+ udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
+
+ udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
+ udp_replay_approx_vnf.deploy_vnfs = mock.MagicMock()
+ self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
+
+ udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
+ udp_replay_approx_vnf._vnf_process.exitcode = 0
+
+ self.assertEquals(udp_replay_approx_vnf.wait_for_instantiate(), 0)
+
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch('yardstick.ssh.SSH')
+ @mock.patch(SSH_HELPER)
+ def test_instantiate_panic(self, ssh, resource_ssh, *_):
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf.WAIT_TIME = 0
+ udp_replay_approx_vnf.q_out.put("some text PANIC some text")
+ udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
+
+ udp_replay_approx_vnf.deploy_helper = mock.MagicMock()
+ self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
+ with self.assertRaises(RuntimeError):
+ udp_replay_approx_vnf.wait_for_instantiate()
+
+ def test_scale(self, _):
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
flavor = ""
- self.assertRaises(NotImplementedError, udp_approx_vnf.scale, flavor)
+
+ self.assertRaises(NotImplementedError, udp_replay_approx_vnf.scale, flavor)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_terminate(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
- udp_approx_vnf._vnf_process = mock.MagicMock()
- udp_approx_vnf._vnf_process.terminate = mock.Mock()
- udp_approx_vnf.used_drivers = {"01:01.0": "i40e",
- "01:01.1": "i40e"}
- udp_approx_vnf.execute_command = mock.Mock()
- udp_approx_vnf.ssh_helper = ssh_mock
- udp_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
- self.assertEqual(None, udp_approx_vnf.terminate())
+ @mock.patch(SSH_HELPER)
+ def test_terminate(self, ssh, mock_time, _):
+ mock_ssh(ssh)
+
+ udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+ udp_replay_approx_vnf._vnf_process = mock.MagicMock()
+ udp_replay_approx_vnf._vnf_process.terminate = mock.Mock()
+ udp_replay_approx_vnf.used_drivers = {"01:01.0": "i40e", "01:01.1": "i40e"}
+ udp_replay_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
+ self.assertEqual(None, udp_replay_approx_vnf.terminate())
if __name__ == '__main__':
unittest.main()
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
index 7dae89f40..958099a03 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
@@ -22,7 +22,7 @@ import mock
import os
from tests.unit import STL_MOCKS
-
+from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
@@ -33,6 +33,7 @@ if stl_patch:
from yardstick.network_services.nfvi.resource import ResourceProfile
TEST_FILE_YAML = 'nsb_test_case.yaml'
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
name = 'vnf__1'
@@ -72,7 +73,7 @@ class TestFWApproxVnf(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',
@@ -87,7 +88,7 @@ class TestFWApproxVnf(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',
@@ -141,7 +142,7 @@ class TestFWApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
+ 'vld_id': FWApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -169,7 +170,7 @@ class TestFWApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
+ 'vld_id': FWApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -194,7 +195,7 @@ class TestFWApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
+ 'vld_id': FWApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -204,7 +205,7 @@ class TestFWApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'dpdk_port_num': 0},
'xe1': {'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
+ 'vld_id': FWApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -258,57 +259,51 @@ pipeline>
""" # noqa
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_collect_kpi(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf.q_in = mock.MagicMock()
- vfw_approx_vnf.q_out = mock.MagicMock()
- vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- vfw_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
- vfw_approx_vnf.resource_helper = mock.MagicMock(
- **{'collect_kpi.return_value': {"core": {}}})
- vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
- result = {
- 'packets_dropped': 0,
- 'packets_fwd': 6007180,
- 'packets_in': 6007180,
- 'collect_stats': {'core': {}},
- }
- self.assertEqual(result, vfw_approx_vnf.collect_kpi())
+ @mock.patch(SSH_HELPER)
+ def test_collect_kpi(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf.q_in = mock.MagicMock()
+ vfw_approx_vnf.q_out = mock.MagicMock()
+ vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ vfw_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
+ vfw_approx_vnf.resource_helper = mock.MagicMock(
+ **{'collect_kpi.return_value': {"core": {}}})
+ vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
+ result = {
+ 'packets_dropped': 0,
+ 'packets_fwd': 6007180,
+ 'packets_in': 6007180,
+ 'collect_stats': {'core': {}},
+ }
+ self.assertEqual(result, vfw_approx_vnf.collect_kpi())
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_vnf_execute_command(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf.q_in = mock.MagicMock()
- vfw_approx_vnf.q_out = mock.MagicMock()
- vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- cmd = "quit"
- self.assertEqual("", vfw_approx_vnf.vnf_execute(cmd))
-
- def test_get_stats(self, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf.q_in = mock.MagicMock()
- vfw_approx_vnf.q_out = mock.MagicMock()
- vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
- self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
+ @mock.patch(SSH_HELPER)
+ def test_vnf_execute_command(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf.q_in = mock.MagicMock()
+ vfw_approx_vnf.q_out = mock.MagicMock()
+ vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ cmd = "quit"
+ self.assertEqual(vfw_approx_vnf.vnf_execute(cmd), "")
+
+ @mock.patch(SSH_HELPER)
+ def test_get_stats(self, ssh, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf.q_in = mock.MagicMock()
+ vfw_approx_vnf.q_out = mock.MagicMock()
+ vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
+ vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
+ self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -318,74 +313,65 @@ pipeline>
@mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.hex")
@mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.eval")
@mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.open")
- def test_run_vfw(self, mock_open, eval, hex, mock_process):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "", ""))
- ssh_mock.run = \
- mock.Mock(return_value=(0, "", ""))
- ssh.from_node.return_value = ssh_mock
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf._build_config = mock.MagicMock()
- vfw_approx_vnf.queue_wrapper = mock.MagicMock()
- vfw_approx_vnf.ssh_helper = mock.MagicMock()
- vfw_approx_vnf.ssh_helper.run = mock.MagicMock()
- vfw_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- vfw_approx_vnf.vnf_cfg = {'lb_config': 'SW',
- 'lb_count': 1,
- 'worker_config': '1C/1T',
- 'worker_threads': 1}
- vfw_approx_vnf.all_options = {'traffic_type': '4',
- 'topology': 'nsb_test_case.yaml'}
- vfw_approx_vnf._run()
- vfw_approx_vnf.ssh_helper.run.assert_called_once()
+ @mock.patch(SSH_HELPER)
+ def test_run_vfw(self, ssh, mock_open, mock_eval, mock_hex, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf._build_config = mock.MagicMock()
+ vfw_approx_vnf.queue_wrapper = mock.MagicMock()
+ vfw_approx_vnf.ssh_helper = mock.MagicMock()
+ vfw_approx_vnf.ssh_helper.run = mock.MagicMock()
+ vfw_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
+ vfw_approx_vnf.vnf_cfg = {'lb_config': 'SW',
+ 'lb_count': 1,
+ 'worker_config': '1C/1T',
+ 'worker_threads': 1}
+ vfw_approx_vnf.all_options = {'traffic_type': '4',
+ 'topology': 'nsb_test_case.yaml'}
+ vfw_approx_vnf._run()
+ vfw_approx_vnf.ssh_helper.run.assert_called_once()
- @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.YangModel")
@mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.find_relative_file")
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.YangModel")
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
- def test_instantiate(self, Context, mock_yang, mock_find, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf.ssh_helper = ssh
- vfw_approx_vnf.deploy_helper = mock.MagicMock()
- vfw_approx_vnf.resource_helper = mock.MagicMock()
- vfw_approx_vnf._build_config = mock.MagicMock()
- self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
- 'rules': ""}}
- self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
- self.assertIsNone(vfw_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
+ @mock.patch(SSH_HELPER)
+ def test_instantiate(self, ssh, mock_context, mock_yang, mock_find, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf.ssh_helper = ssh
+ vfw_approx_vnf.deploy_helper = mock.MagicMock()
+ vfw_approx_vnf.resource_helper = mock.MagicMock()
+ vfw_approx_vnf._build_config = mock.MagicMock()
+ self.scenario_cfg['vnf_options'] = {'acl': {'cfg': "",
+ 'rules': ""}}
+ self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
+ self.assertIsNone(vfw_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg))
def test_scale(self, mock_process):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
vfw_approx_vnf = FWApproxVnf(name, vnfd)
flavor = ""
- self.assertRaises(NotImplementedError, vfw_approx_vnf.scale, flavor)
+ with self.assertRaises(NotImplementedError):
+ vfw_approx_vnf.scale(flavor)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- def test_terminate(self, mock_time, mock_process):
- 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
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- vfw_approx_vnf = FWApproxVnf(name, vnfd)
- vfw_approx_vnf._vnf_process = mock.MagicMock()
- vfw_approx_vnf._vnf_process.terminate = mock.Mock()
- vfw_approx_vnf.used_drivers = {"01:01.0": "i40e",
- "01:01.1": "i40e"}
- vfw_approx_vnf.vnf_execute = mock.Mock()
- vfw_approx_vnf.ssh_helper = ssh_mock
- vfw_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
- vfw_approx_vnf._resource_collect_stop = mock.Mock()
- self.assertEqual(None, vfw_approx_vnf.terminate())
+ @mock.patch(SSH_HELPER)
+ def test_terminate(self, ssh, mock_time, mock_process):
+ mock_ssh(ssh)
+
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf._vnf_process = mock.MagicMock()
+ vfw_approx_vnf.used_drivers = {"01:01.0": "i40e",
+ "01:01.1": "i40e"}
+ vfw_approx_vnf.vnf_execute = mock.Mock()
+ vfw_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
+ vfw_approx_vnf._resource_collect_stop = mock.Mock()
+ self.assertIsNone(vfw_approx_vnf.terminate())
if __name__ == '__main__':
unittest.main()
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 5e66390e3..4103d7825 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'
@@ -36,8 +37,8 @@ stl_patch.start()
if stl_patch:
from yardstick.network_services.vnf_generic.vnf.vpe_vnf import ConfigCreate
from yardstick.network_services.nfvi.resource import ResourceProfile
- from yardstick.network_services.vnf_generic.vnf import vpe_vnf
- from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf
+ 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
@@ -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.priv_ports, [0])
- self.assertEqual(config_create.pub_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,21 +202,32 @@ 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, '')
def test_create_vpe_config(self):
- priv_ports = [
+ uplink_ports = [
{
'index': 0,
'dpdk_port_num': 1,
@@ -121,7 +238,7 @@ class TestConfigCreate(unittest.TestCase):
},
]
- pub_ports = [
+ downlink_ports = [
{
'index': 2,
'dpdk_port_num': 3,
@@ -132,7 +249,10 @@ class TestConfigCreate(unittest.TestCase):
},
]
- config_create = ConfigCreate(priv_ports, pub_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)
@@ -185,14 +305,15 @@ class TestVpeApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'local_ip': '152.16.100.19',
'type': 'PCI-PASSTHROUGH',
- 'vld_id': '',
'netmask': '255.255.255.0',
- 'dpdk_port_num': '0',
+ 'dpdk_port_num': 0,
'bandwidth': '10 Gbps',
'driver': "i40e",
'dst_ip': '152.16.100.20',
'local_iface_name': 'xe0',
'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'uplink_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0',
@@ -203,14 +324,15 @@ class TestVpeApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.1',
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
- 'vld_id': '',
'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',
'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'downlink_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1',
@@ -258,7 +380,7 @@ class TestVpeApproxVnf(unittest.TestCase):
SCENARIO_CFG = {
'options': {
'packetsize': 64,
- 'traffic_type': 4 ,
+ 'traffic_type': 4,
'rfc2544': {
'allowed_drop_rate': '0.8 - 1',
},
@@ -308,7 +430,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens513f0',
- 'vld_id': 'public',
+ 'vld_id': VpeApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -342,7 +464,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens785f0',
- 'vld_id': 'private',
+ 'vld_id': VpeApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -373,7 +495,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens786f0',
- 'vld_id': 'private',
+ 'vld_id': VpeApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -385,7 +507,7 @@ class TestVpeApproxVnf(unittest.TestCase):
},
'xe1': {
'local_iface_name': 'ens786f1',
- 'vld_id': 'public',
+ 'vld_id': VpeApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -443,8 +565,9 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
- resource.check_if_sa_running.return_value = False, 'error'
+ resource.check_if_sa_running.return_value = 1, ''
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
+ resource.check_if_sa_running.return_value = (1, None)
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.q_in = mock.MagicMock()
@@ -466,7 +589,7 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
- resource.check_if_sa_running.return_value = True, 'good'
+ resource.check_if_sa_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
@@ -499,9 +622,6 @@ class TestVpeApproxVnf(unittest.TestCase):
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML)
- vpe_approx_vnf.generate_port_pairs = mock.Mock()
- vpe_approx_vnf.tg_port_pairs = [[[0], [1]]]
- vpe_approx_vnf.vnf_port_pairs = [[[0], [1]]]
vpe_approx_vnf.vnf_cfg = {
'lb_config': 'SW',
'lb_count': 1,
@@ -513,16 +633,56 @@ class TestVpeApproxVnf(unittest.TestCase):
NAME: {
'traffic_type': '4',
'topology': 'nsb_test_case.yaml',
+ 'vnf_config': 'vpe_config',
}
}
}
vpe_approx_vnf.topology = "nsb_test_case.yaml"
vpe_approx_vnf.nfvi_type = "baremetal"
vpe_approx_vnf._provide_config_file = mock.Mock()
+ vpe_approx_vnf._build_config = mock.MagicMock()
self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock)
+ self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock)
self.assertIsNone(vpe_approx_vnf._run())
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig")
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @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, _):
+ mock_ssh(ssh)
+ vpe_approx_vnf = VpeApproxSetupEnvHelper(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 = {
+ 'lb_config': 'SW',
+ 'lb_count': 1,
+ 'worker_config': '1C/1T',
+ 'worker_threads': 1,
+ }
+ vpe_approx_vnf.scenario_helper.scenario_cfg = {
+ 'options': {
+ NAME: {
+ 'traffic_type': '4',
+ 'topology': 'nsb_test_case.yaml',
+ 'vnf_config': 'vpe_config',
+ }
+ }
+ }
+ vpe_approx_vnf.topology = "nsb_test_case.yaml"
+ vpe_approx_vnf.nfvi_type = "baremetal"
+ vpe_approx_vnf._provide_config_file = mock.Mock()
+
+ vpe_approx_vnf.ssh_helper = mock.MagicMock()
+ vpe_approx_vnf.scenario_helper = mock.MagicMock()
+ vpe_approx_vnf.ssh_helper.bin_path = mock.Mock()
+ vpe_approx_vnf.ssh_helper.upload_config_file = mock.MagicMock()
+ self.assertIsNone(vpe_approx_vnf._build_vnf_ports())
+ self.assertIsNotNone(vpe_approx_vnf.build_config())
+
@mock.patch(SSH_HELPER)
def test_wait_for_instantiate(self, ssh, _):
mock_ssh(ssh)
@@ -638,14 +798,14 @@ class TestVpeApproxVnf(unittest.TestCase):
with self.assertRaises(NotImplementedError):
vpe_approx_vnf.scale('')
- def test_terminate(self, _):
+ @mock.patch(SSH_HELPER)
+ def test_terminate(self, ssh, _):
+ mock_ssh(ssh)
+
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
- vpe_approx_vnf.vnf_execute = mock.Mock()
vpe_approx_vnf._vnf_process = mock.MagicMock()
- vpe_approx_vnf._vnf_process.terminate = mock.Mock()
vpe_approx_vnf._resource_collect_stop = mock.Mock()
vpe_approx_vnf.resource_helper = mock.MagicMock()
- vpe_approx_vnf.ssh_helper = mock.MagicMock()
self.assertIsNone(vpe_approx_vnf.terminate())