summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorabhijitsinha <abhijit.sinha@intel.com>2017-08-28 20:35:46 +0100
committerRoss Brattain <ross.b.brattain@intel.com>2017-09-04 14:49:45 -0700
commita1722f91ac250e2a021b7a1cc4e4f99f11ff41e0 (patch)
tree75e9b060dca5e2e96734bc1e026b76fd3cc4296c /tests
parentc19115bafe0141326b189f317a684bf4681c8bd0 (diff)
Addition of Prox NSB changes in yardstick
JIRA: YARDSTICK-802 Addition of Prox L2Fwd, MPLS test cases for BM and Heat. updates: Most of tg_prox and prox_vnf were absorbed into the base classes. delete most of ProxDpdkVnfSetupEnvHelper, it is handled by DpdkVnfSetupEnvHelper baseclass use standard _build_pipeline_kwargs methods don't use terminate() use baseclass version add new method kill_vnf that runs pkill -x replace resource_helper.execute() with vnf_execture for dumping stats In order to share code between tg_prox and vnf_prox refactor to have tg_prox hold and wrap a ProxApproxVnf instance and call methods on that class. Do this instead of multiple-inheritance. Implement ProxApproxVnf.terminate() using prox socket command based exit, (stop_all, quit, force_quit). vnf_execute calls resource_helper.execute() which calls socket methods on the sut object. Since tg_prox wraps the VNF object, we can call terminate on the VNF object and it should work correctly. move prox config generation to parent process we need to get core number info from config file inside the TG processes, so we need to generate the config in the parent process so the data is copied to the child during the fork. moved more config file methods to the setup_helper class. we run force_quit after quit, so the socket should already be closed this will trigger socket error, so add _ignore_errors option for vnf_execute to ignore socket errors Fixed the terminate issue. Added MPLS tests. Added TG Stats in_packet/out_packet Fixed compile (pep8) issues Fixed MPLS TG port stats, in/out packets Added Grafana dashboards for L2FWD and MPLS Traffic profiles modified for tolerated loss and precision as per DATS tests. Added unit test case for Mpls Single port test stats collection support. Change-Id: Idd9493f597c668a3bb7d90e167e6a418546106e8 Signed-off-by: Abhijit Sinha <abhijit.sinha@intel.com> Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_binsearch.py12
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_mpls.py93
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py187
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_base.py16
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py207
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_iniparser.py65
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py1163
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py71
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py8
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py202
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py8
11 files changed, 1209 insertions, 823 deletions
diff --git a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
index 72b86709c..0edce7a14 100644
--- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
+++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
@@ -37,8 +37,8 @@ class TestProxBinSearchProfile(unittest.TestCase):
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
if args[2] > 75.0:
- return fail_tuple
- return success_tuple
+ return fail_tuple, {}
+ return success_tuple, {}
tp_config = {
'traffic_profile': {
@@ -51,7 +51,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
traffic_generator = mock.MagicMock()
- traffic_generator.resource_helper.run_test = target
+ traffic_generator.run_test = target
profile = ProxBinSearchProfile(tp_config)
profile.init(mock.MagicMock())
@@ -67,8 +67,8 @@ class TestProxBinSearchProfile(unittest.TestCase):
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
if args[2] > 25.0:
- return fail_tuple
- return success_tuple
+ return fail_tuple, {}
+ return success_tuple, {}
tp_config = {
'traffic_profile': {
@@ -82,7 +82,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
traffic_generator = mock.MagicMock()
- traffic_generator.resource_helper.run_test = target
+ traffic_generator.run_test = target
profile = ProxBinSearchProfile(tp_config)
profile.init(mock.MagicMock())
diff --git a/tests/unit/network_services/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py
new file mode 100644
index 000000000..77bca9cc0
--- /dev/null
+++ b/tests/unit/network_services/traffic_profile/test_prox_mpls.py
@@ -0,0 +1,93 @@
+# 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
+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.prox_helpers import ProxTestDataTuple
+ from yardstick.network_services.traffic_profile.prox_mpls_tag_untag import ProxMplsTagUntagProfile
+
+
+class TestProxMplsTagUntagProfile(unittest.TestCase):
+
+ def test_mpls_1(self):
+ def target(*args, **kwargs):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+ traffic_generator.run_test = target
+
+ profile = ProxMplsTagUntagProfile(tp_config)
+ profile.init(mock.MagicMock())
+
+ profile.execute(traffic_generator)
+ self.assertEqual(round(profile.current_lower, 2), 74.69)
+ self.assertEqual(round(profile.current_upper, 2), 75.39)
+ self.assertEqual(len(runs), 8)
+
+ def test_mpls_2(self):
+ def target(*args, **kwargs):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 25.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+ traffic_generator.run_test = target
+
+ profile = ProxMplsTagUntagProfile(tp_config)
+ profile.init(mock.MagicMock())
+
+ profile.execute(traffic_generator)
+ self.assertEqual(round(profile.current_lower, 2), 24.06)
+ self.assertEqual(round(profile.current_upper, 2), 25.47)
+ self.assertEqual(len(runs), 7)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
index 7570067b9..2e83353cd 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'
@@ -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..e1c69e7b3 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):
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..e5503697a 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
@@ -22,6 +22,7 @@ import unittest
import mock
from tests.unit import STL_MOCKS
+from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
STLClient = mock.MagicMock()
@@ -35,6 +36,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'
@@ -281,51 +283,45 @@ class TestCgnaptApproxVnf(unittest.TestCase):
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(SSH_HELPER)
+ def test_collect_kpi(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)
+ 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")
- 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()))
+ @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 +331,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__1": ""}})
+ 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 +370,36 @@ 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("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(self, ssh, mock_time, mock_cgnapt_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()
+ cgnapt_approx_vnf.vnf_execute.assert_called_once()
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
index b74e5d9fd..15d6adea1 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
@@ -45,6 +45,7 @@ key4=
[section2]
# here is a comment line
list2: value5
+key with no value
; another comment line
key5=
"""
@@ -69,15 +70,10 @@ PARSE_TEXT_BAD_3 = """\
PARSE_TEXT_BAD_4 = """\
[section1]
-no list or key
-"""
-
-PARSE_TEXT_BAD_5 = """\
-[section1]
bad continuation
"""
-PARSE_TEXT_BAD_6 = """\
+PARSE_TEXT_BAD_5 = """\
[section1]
=value with no key
"""
@@ -106,7 +102,7 @@ class TestBaseParser(unittest.TestCase):
parser = BaseParser()
- self.assertIsNone(parser.parse())
+ parser.parse([])
def test_not_implemented_methods(self):
parser = BaseParser()
@@ -132,39 +128,49 @@ class TestConfigParser(unittest.TestCase):
def test_parse(self, mock_open):
mock_open.side_effect = self.make_open(PARSE_TEXT_1)
- config_parser = ConfigParser('my_file', {})
+ 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', ''],
+ expected = [
+ [
+ 'section1',
+ [
+ ['key1', 'value1'],
+ ['list1', 'value2\nvalue3\nvalue4'],
+ ['key2', 'double quote value'],
+ ['key3', 'single quote value'],
+ ['key4', ''],
+ ],
],
- 'section2': [
- ['list2', 'value5'],
- ['key5', ''],
+ [
+ 'section2',
+ [
+ ['list2', 'value5'],
+ ['key with no value', '@'],
+ ['key5', ''],
+ ],
],
- }
+ ]
- self.assertDictEqual(config_parser.sections, expected)
+ self.assertEqual(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 = ConfigParser('my_file', [])
config_parser.parse()
- expected = {
- 'section1': [
- ['list1', 'item1\nitem2\nended by eof'],
+ expected = [
+ [
+ 'section1',
+ [
+ ['list1', 'item1\nitem2\nended by eof'],
+ ],
],
- }
+ ]
- self.assertDictEqual(config_parser.sections, expected)
+ self.assertEqual(config_parser.sections, expected)
@mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
def test_parse_negative(self, mock_open):
@@ -172,15 +178,14 @@ class TestConfigParser(unittest.TestCase):
'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,
+ 'bad_continuation': PARSE_TEXT_BAD_4,
+ 'value with no key': PARSE_TEXT_BAD_5,
}
for bad_reason, bad_text in bad_text_dict.items():
mock_open.side_effect = self.make_open(bad_text)
- config_parser = ConfigParser('my_file', {})
+ config_parser = ConfigParser('my_file', [])
try:
# TODO: replace with assertRaises, when the UT framework supports
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..cba3d449f 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,14 +20,12 @@ 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
-
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
@@ -44,7 +42,6 @@ if stl_patch:
class TestCoreTuple(unittest.TestCase):
-
def test___init__(self):
core_tuple = CoreSocketTuple('core 5s6')
self.assertEqual(core_tuple.core_id, 5)
@@ -65,7 +62,6 @@ class TestCoreTuple(unittest.TestCase):
'5s6',
'core',
'core h',
- 'core 5',
'core 5s',
'core 5 6',
'core 5 6h',
@@ -125,7 +121,6 @@ class TestCoreTuple(unittest.TestCase):
class TestTotStatsTuple(unittest.TestCase):
-
def test___new___negative(self):
with self.assertRaises(TypeError):
# no values
@@ -141,7 +136,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 +173,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 +210,6 @@ class TestProxTestDataTuple(unittest.TestCase):
class TestPacketDump(unittest.TestCase):
-
PAYLOAD = "payload"
def test__init__(self):
@@ -290,7 +284,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 +368,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 +475,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 +504,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)
@@ -626,79 +634,48 @@ class TestProxSocketHelper(unittest.TestCase):
class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
-
- def test_rebind_drivers(self):
- def find_drivers(*args, **kwargs):
- setup_helper.used_drivers = used_drivers
-
- used_drivers = {
- 'a': (1, 'b'),
- 'c': (2, 'd'),
- }
-
- 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.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])
-
- 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])
-
-
-class TestProxResourceHelper(unittest.TestCase):
-
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 +687,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 +696,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,9 +705,499 @@ 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_rebind_drivers(self):
+ def find_drivers(*args, **kwargs):
+ setup_helper.used_drivers = used_drivers
+
+ used_drivers = {
+ 'a': (1, 'b'),
+ 'c': (2, 'd'),
+ }
+
+ 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.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])
+
+ 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])
+
+ @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',
+ }
+
+ 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_dict, '4')
+ self.assertNotEqual(helper.remote_path, '5')
+ helper.build_config_file()
+ self.assertEqual(helper.additional_files, {})
+ self.assertEqual(helper.prox_config_dict, '4')
+ self.assertEqual(helper.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',
+ }
+
+ 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(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']
+ 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_dict, '44')
+ self.assertNotEqual(helper.remote_path, '55')
+ expected = {'h.i': '33', 'l': '34', 'm_n': '35'}
+ helper.build_config_file()
+ self.assertDictEqual(helper.additional_files, expected)
+ self.assertEqual(helper.prox_config_dict, '44')
+ self.assertEqual(helper.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"
+ prox_cmd = helper.build_config()
+ expected = "sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli -f -f /tmp/prox.cfg '"
+ self.assertEqual(prox_cmd, expected)
+
+ 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 = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ 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'
+ vnfd_helper.interfaces = [
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:de:ad:88',
+ },
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:de:ad:ee',
+ },
+ },
+ {
+ 'virtual-interface': {
+ 'dst_mac': '00:00:00:de:ad:ff',
+ },
+ },
+ ]
+ sections_data = [
+ [
+ 'lua',
+ [
+ ['dofile("ipv4.lua")', ''],
+ ],
+ ],
+ [
+ 'port 0',
+ [
+ ['ip', ''],
+ ['mac', 'foo'],
+ ['dst mac', '@@2'],
+ ['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:de:ad:ff'],
+ ['tx port', '1'],
+ ],
+ ],
+ [
+ 'port 2',
+ [
+ ['ip', ''],
+ ['$sut_mac0', '00 00 00 de ad 88'],
+ ['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_generate_prox_lua_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)
+ helper.LUA_PARAMETER_NAME = 'sut'
+
+ expected = ''
+ result = helper.generate_prox_lua_file()
self.assertEqual(result, expected)
+ 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,
+ },
+ },
+ ]
+
+ 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)
+
+ def test_upload_prox_lua(self):
+ def identity(*args):
+ return args
+
+ vnfd_helper = mock.MagicMock()
+ vnfd_helper.interfaces = []
+ ssh_helper = mock.MagicMock()
+ scenario_helper = mock.MagicMock()
+
+ helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ helper.generate_prox_lua_file = mock.MagicMock(return_value=234)
+ helper.put_string_to_file = identity
+
+ 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',
+ },
+ }
+
+ expected = 234, 'my_dir/key_side'
+ result = helper.upload_prox_lua('my_dir', input_data)
+ self.assertEqual(result, expected)
+
+ 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__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):
def test_line_rate_to_pps(self):
expected = 0.25 * 1e8
result = ProxResourceHelper.line_rate_to_pps(180, 4)
@@ -754,43 +1221,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
@@ -812,54 +1245,18 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper._cpu_topology)
self.assertIs(result, helper.cpu_topology)
- def test_vpci_to_if_name_map(self):
- 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',
- },
- },
- {
- 'name': 'vnf2',
- 'virtual-interface': {
- 'vpci': '0000:04.05.06',
- },
- },
- ]
- 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
- self.assertDictEqual(result, expected)
- self.assertIs(result, helper._vpci_to_if_name_map)
- self.assertIs(result, helper.vpci_to_if_name_map)
-
def test_test_cores(self):
setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = {}
helper._cpu_topology = []
expected = []
result = helper.test_cores
self.assertEqual(result, expected)
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = OrderedDict([
+ setup_helper.prox_config_dict = [
('section1', []),
('section2', [
('a', 'b'),
@@ -878,7 +1275,9 @@ class TestProxResourceHelper(unittest.TestCase):
('index', 7),
('mode', 'gen'),
]),
- ])
+ ]
+
+ helper = ProxResourceHelper(setup_helper)
helper._cpu_topology = {
1: {
3: {
@@ -903,18 +1302,146 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper._test_cores)
self.assertIs(result, helper.test_cores)
+ def test_get_test_type(self):
+ setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
+ helper = ProxResourceHelper(setup_helper)
+ setup_helper.prox_config_dict = [
+ ('global', [
+ ('name', helper.PROX_CORE_MPLS_TEST)
+ ]),
+ ('section2', [
+ ('a', 'b'),
+ ('c', 'd'),
+ ]),
+ ('core 1', []),
+ ('core 2', [
+ ('index', 8),
+ ('mode', ''),
+ ]),
+ ('core 3', [
+ ('index', 5),
+ ('mode', 'gen'),
+ ]),
+ ('core 4', [
+ ('index', 7),
+ ('mode', 'gen'),
+ ]),
+ ]
+ test_type = helper.get_test_type()
+ self.assertEqual(test_type, helper.PROX_CORE_MPLS_TEST)
+
+ def test_get_cores(self):
+ setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
+ helper = ProxResourceHelper(setup_helper)
+ helper._cpu_topology = {
+ 0: {
+ 1: {
+ 5: (5, 1, 0)
+ },
+ 2: {
+ 6: (6, 2, 0)
+ },
+ 3: {
+ 7: (7, 3, 0)
+ },
+ 4: {
+ 8: (8, 3, 0)
+ },
+ }
+ }
+
+ setup_helper.prox_config_dict = [
+ ('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'),
+ ]),
+ ]
+
+ expected = [7, 8]
+ result = helper.get_cores(helper.PROX_CORE_GEN_MODE)
+ self.assertEqual(result, expected)
+
+ def test_get_cores_mpls(self):
+ setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
+ helper = ProxResourceHelper(setup_helper)
+ helper._cpu_topology = {
+ 0: {
+ 1: {
+ 5: (5, 1, 0)
+ },
+ 2: {
+ 6: (6, 2, 0)
+ },
+ 3: {
+ 7: (7, 3, 0)
+ },
+ 4: {
+ 8: (8, 3, 0)
+ },
+ }
+ }
+
+ setup_helper.prox_config_dict = [
+ ('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_tagged = [7]
+ expected_plain = [8]
+ result_tagged, result_plain = helper.get_cores_mpls(helper.PROX_CORE_GEN_MODE)
+ self.assertEqual(result_tagged, expected_tagged)
+ self.assertEqual(result_plain, expected_plain)
+
def test_latency_cores(self):
setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = {}
helper._cpu_topology = []
expected = []
result = helper.latency_cores
self.assertEqual(result, expected)
- helper = ProxResourceHelper(setup_helper)
- helper.prox_config_dict = OrderedDict([
+ setup_helper.prox_config_dict = [
('section1', []),
('section2', [
('a', 'b'),
@@ -933,7 +1460,9 @@ class TestProxResourceHelper(unittest.TestCase):
('index', 7),
('mode', 'lat'),
]),
- ])
+ ]
+
+ helper = ProxResourceHelper(setup_helper)
helper._cpu_topology = {
1: {
3: {
@@ -958,74 +1487,30 @@ class TestProxResourceHelper(unittest.TestCase):
self.assertIs(result, helper._latency_cores)
self.assertIs(result, helper.latency_cores)
- def test_start_collect(self):
+ def test_run_traffic(self):
setup_helper = mock.MagicMock()
helper = ProxResourceHelper(setup_helper)
- self.assertIsNone(helper.start_collect())
+ traffic_proifle = mock.MagicMock(**{"done": True})
+ helper.run_traffic(traffic_proifle)
+ self.assertEqual(helper._terminated.value, 1)
- def test_terminate(self):
+ def test__run_traffic_once(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',
- }
+ traffic_proifle = mock.MagicMock(**{"done": True})
+ helper._run_traffic_once(traffic_proifle)
+ self.assertEqual(helper._terminated.value, 1)
- mock_find_path.side_effect = ['1', '2']
+ def test_start_collect(self):
setup_helper = mock.MagicMock()
- setup_helper.scenario_helper = ScenarioHelper('vnf1')
- setup_helper.scenario_helper.scenario_cfg = {
- 'task_path': 'a/b',
- 'options': {
- 'vnf1': vnf1,
- },
- }
-
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()
- 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',
- }
+ self.assertIsNone(helper.start_collect())
- mock_find_path.side_effect = ['1', '2']
+ def test_terminate(self):
setup_helper = mock.MagicMock()
- setup_helper.scenario_helper = ScenarioHelper('vnf1')
- setup_helper.scenario_helper.scenario_cfg = {
- 'task_path': 'a/b',
- 'options': {
- 'vnf1': vnf1,
- },
- }
-
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()
- self.assertEqual(result, expected)
- self.assertTrue(helper.additional_file)
- self.assertEqual(helper.remote_prox_file_name, '33')
+ with self.assertRaises(NotImplementedError):
+ helper.terminate()
def test_up_post(self):
setup_helper = mock.MagicMock()
@@ -1048,20 +1533,69 @@ class TestProxResourceHelper(unittest.TestCase):
result = helper.execute('my_command')
self.assertIsNone(result)
- def test_copy_to_target(self):
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
+ def test_traffic_context(self, mock_time):
setup_helper = mock.MagicMock()
+ setup_helper.prox_config_dict = {}
+
helper = ProxResourceHelper(setup_helper)
- expected = '/tmp/c'
- result = helper.copy_to_target('a/b', 'c')
- self.assertEqual(result, expected)
+ helper._cpu_topology = {
+ 0: {
+ 1: {
+ 5: (5, 1, 0)
+ },
+ 2: {
+ 6: (6, 2, 0)
+ },
+ 3: {
+ 7: (7, 3, 0)
+ },
+ 4: {
+ 8: (8, 3, 0)
+ },
+ }
+ }
+
+ setup_helper.prox_config_dict = [
+ ('global', [
+ ('name', helper.PROX_CORE_MPLS_TEST)
+ ]),
+ ('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'),
+ ]),
+ ]
- 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)
+ setup_helper.vnfd_helper.interfaces = []
+
+ client = mock.MagicMock()
+ client.hz.return_value = 2
+ client.port_stats.return_value = tuple(range(12))
+
+ helper.client = client
+ helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8])
+
+ helper._test_cores = [3, 4]
+
+ with helper.traffic_context(64, 1):
+ pass
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
def test_run_test(self, mock_time):
@@ -1088,220 +1622,25 @@ class TestProxResourceHelper(unittest.TestCase):
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)
-
- def test_generate_prox_lua_file(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
-
- helper = ProxResourceHelper(setup_helper)
- helper.LUA_PARAMETER_NAME = 'sut'
-
- expected = ''
- result = helper.generate_prox_lua_file()
- self.assertEqual(result, expected)
-
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,
- },
- },
+ {'name': 'a', 'virtual-interface': {'vpci': 'z'}},
+ {'name': 'b', 'virtual-interface': {'vpci': 'y'}},
+ {'name': 'c', 'virtual-interface': {'vpci': 'x'}},
+ {'name': 'd', 'virtual-interface': {'vpci': 'w'}},
]
+ helper._test_cores = [3, 4]
- 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)
-
- def test_upload_prox_lua(self):
- def identity(*args):
- return args
-
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
-
- helper = ProxResourceHelper(setup_helper)
- helper.generate_prox_lua_file = mock.MagicMock(return_value=234)
- helper.put_string_to_file = identity
-
- 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',
- },
- }
-
- expected = 234, 'my_dir/key_side'
- result = helper.upload_prox_lua('my_dir', input_data)
- self.assertEqual(result, expected)
-
- def test_put_string_to_file(self):
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
-
- helper = ProxResourceHelper(setup_helper)
-
- expected = 'a/b'
- result = helper.put_string_to_file('my long string', 'a/b')
- self.assertEqual(result, expected)
-
- @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()
-
- sections_data = {}
-
- mock_parser_type.side_effect = init
-
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
-
- helper = ProxResourceHelper(setup_helper)
- helper.additional_file = False
-
- expected = {}
- result = helper.generate_prox_config_file('a/b')
- self.assertEqual(result, expected)
-
- 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',
- },
- },
- {
- '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', ''],
- ['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'],
- ],
- }
- 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 = {}
-
- mock_parser_type.side_effect = init
-
- setup_helper = mock.MagicMock()
- setup_helper.vnfd_helper.interfaces = []
-
- 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',
- },
- },
- {
- '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'],
- ],
+ expected_test_data = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7, 1.3e7)
+ expected_port_samples = {
+ 'a': {'in_packets': 6, 'out_packets': 7},
+ 'b': {'in_packets': 6, 'out_packets': 7},
+ 'c': {'in_packets': 6, 'out_packets': 7},
+ 'd': {'in_packets': 6, 'out_packets': 7},
}
-
- with self.assertRaises(Exception):
- helper.generate_prox_config_file('a/b')
+ test_data, port_samples = helper.run_test(230, 60, 65)
+ self.assertEqual(test_data, expected_test_data, '\n'.join(str(x) for x in test_data))
+ self.assertEqual(port_samples, expected_port_samples,
+ '\n'.join(str(x) for x in port_samples))
def test_get_latency(self):
setup_helper = mock.MagicMock()
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..4b115f2d6 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
@@ -376,50 +377,25 @@ class TestProxApproxVnf(unittest.TestCase):
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 configs/file56.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 +413,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 +437,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_tg_prox.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
index 12abadf98..a12abb625 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
@@ -20,7 +20,7 @@ import mock
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from tests.unit import STL_MOCKS
-
+from yardstick.network_services.nfvi.resource import ResourceProfile
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
NAME = 'vnf__1'
@@ -331,13 +331,14 @@ 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 = mock.Mock(autospec=ResourceProfile)
+ 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'}
@@ -424,5 +425,6 @@ class TestProxTrafficGen(unittest.TestCase):
prox_traffic_gen._traffic_process.terminate = mock.Mock()
prox_traffic_gen.ssh_helper = mock.MagicMock()
prox_traffic_gen.setup_helper = mock.MagicMock()
+ prox_traffic_gen._vnf_wrapper.setup_helper = mock.MagicMock()
prox_traffic_gen.resource_helper = mock.MagicMock()
self.assertEqual(None, prox_traffic_gen.terminate())
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..c3d53ff03 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'
@@ -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..ffd0d539b 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
@@ -638,14 +638,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())