From 005358a39a87e42061dd5b344916c2ffe0475961 Mon Sep 17 00:00:00 2001 From: "Chornyi, TarasX" Date: Tue, 29 May 2018 17:59:49 +0300 Subject: NFVI support for standalone, baremetal and heat contexts JIRA: YARDSTICK-1257 Change-Id: I6733bd49ac91985e8f3d7722e6990e8733bb430e Signed-off-by: Chornyi, TarasX --- .../tests/unit/benchmark/contexts/test_base.py | 2 + .../network_services/collector/test_subscriber.py | 31 +++++++++++++-- .../unit/network_services/nfvi/test_resource.py | 31 ++++++++++++--- .../vnf_generic/vnf/test_acl_vnf.py | 36 +++++++++++------ .../vnf_generic/vnf/test_cgnapt_vnf.py | 11 +++++- .../vnf_generic/vnf/test_prox_vnf.py | 46 ++++++++++++++-------- .../vnf_generic/vnf/test_router_vnf.py | 19 +++++++-- .../vnf_generic/vnf/test_sample_vnf.py | 40 +++++++++---------- .../vnf_generic/vnf/test_tg_ixload.py | 43 +++++++++++++++----- .../vnf_generic/vnf/test_tg_ping.py | 18 +++++++-- .../vnf_generic/vnf/test_tg_prox.py | 12 +++++- .../vnf_generic/vnf/test_tg_rfc2544_ixia.py | 16 +++++++- .../vnf_generic/vnf/test_tg_rfc2544_trex.py | 29 ++++++++++---- .../vnf_generic/vnf/test_tg_trex.py | 21 +++++++--- .../vnf_generic/vnf/test_udp_replay.py | 40 +++++++++++++------ .../vnf_generic/vnf/test_vfw_vnf.py | 10 +++-- .../vnf_generic/vnf/test_vpe_vnf.py | 16 ++++++-- 17 files changed, 311 insertions(+), 110 deletions(-) (limited to 'yardstick/tests') diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py index 8f1cbcc55..1e63b4831 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_base.py +++ b/yardstick/tests/unit/benchmark/contexts/test_base.py @@ -25,6 +25,8 @@ from yardstick.common.constants import YARDSTICK_ROOT_PATH class DummyContextClass(Context): + __context_type__ = "Dummy" + def __init__(self, host_name_separator='.'): super(DummyContextClass, self).__init__\ (host_name_separator=host_name_separator) diff --git a/yardstick/tests/unit/network_services/collector/test_subscriber.py b/yardstick/tests/unit/network_services/collector/test_subscriber.py index 14e26f7fe..4271f852c 100644 --- a/yardstick/tests/unit/network_services/collector/test_subscriber.py +++ b/yardstick/tests/unit/network_services/collector/test_subscriber.py @@ -38,6 +38,15 @@ class MockVnfAprrox(object): class CollectorTestCase(unittest.TestCase): + NODES = {'context1': [{'name': 'node1', + 'ip': '1.2.3.4', + 'collectd': { + 'plugins': {'abc': 12, 'def': 34}, + 'interval': 987 + }, + }] + } + def setUp(self): vnf = MockVnfAprrox() vnf.start_collect = mock.Mock() @@ -47,30 +56,46 @@ class CollectorTestCase(unittest.TestCase): mock_instance = mock.Mock() mock_instance.execute.return_value = 0, '', '' mock_ssh.from_node.return_value = mock_instance - self.collector = subscriber.Collector([vnf]) + self.collector = subscriber.Collector([vnf], self.NODES) def tearDown(self): self.ssh_patch.stop() def test___init__(self, *_): vnf = MockVnfAprrox() - collector = subscriber.Collector([vnf]) + collector = subscriber.Collector([vnf], self.NODES) self.assertEqual(len(collector.vnfs), 1) + self.assertEqual(len(collector.nodes), 1) def test_start(self, *_): + resource_profile = mock.MagicMock() + self.collector.resource_profiles = {'key': resource_profile} + self.collector.bin_path = 'path' + self.assertIsNone(self.collector.start()) for vnf in self.collector.vnfs: vnf.start_collect.assert_called_once() + for resource_profile in self.collector.resource_profiles.values(): + resource_profile.initiate_systemagent.assert_called_once_with('path') + resource_profile.start.assert_called_once() + resource_profile.amqp_process_for_nfvi_kpi.assert_called_once() + def test_stop(self, *_): + resource_profile = mock.MagicMock() + self.collector.resource_profiles = {'key': resource_profile} + self.assertIsNone(self.collector.stop()) for vnf in self.collector.vnfs: vnf.stop_collect.assert_called_once() + for resource in self.collector.resource_profiles.values(): + resource.stop.assert_called_once() + def test_get_kpi(self, *_): result = self.collector.get_kpi() - self.assertEqual(1, len(result)) + self.assertEqual(2, len(result)) self.assertEqual(4, len(result["vnf__1"])) self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100) self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5) diff --git a/yardstick/tests/unit/network_services/nfvi/test_resource.py b/yardstick/tests/unit/network_services/nfvi/test_resource.py index de9679456..c06658218 100644 --- a/yardstick/tests/unit/network_services/nfvi/test_resource.py +++ b/yardstick/tests/unit/network_services/nfvi/test_resource.py @@ -18,6 +18,7 @@ import mock import unittest from yardstick.common import exceptions +from yardstick.common.exceptions import ResourceCommandError from yardstick.network_services.nfvi.resource import ResourceProfile from yardstick.network_services.nfvi import resource, collectd @@ -139,18 +140,38 @@ class TestResourceProfile(unittest.TestCase): self.resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin") ssh_mock.execute = mock.Mock(return_value=(1, "", "")) - self.assertIsNone(self.resource_profile._start_collectd(ssh_mock, - "/opt/nsb_bin")) + with self.assertRaises(ResourceCommandError): + self.resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin") + + def test__reset_rabbitmq(self): + ssh_mock = mock.Mock() + ssh_mock.execute = mock.Mock(return_value=(1, "", "")) + with self.assertRaises(exceptions.ResourceCommandError): + self.resource_profile._reset_rabbitmq(ssh_mock) + + def test__check_rabbitmq_user(self): + ssh_mock = mock.Mock() + ssh_mock.execute = mock.Mock(return_value=(0, "title\nadmin\t[]", "")) + self.assertTrue(self.resource_profile._check_rabbitmq_user(ssh_mock)) + + def test__set_rabbitmq_admin_user(self): + ssh_mock = mock.Mock() + ssh_mock.execute = mock.Mock(return_value=(1, "", "")) + with self.assertRaises(exceptions.ResourceCommandError): + self.resource_profile._set_rabbitmq_admin_user(ssh_mock) def test__start_rabbitmq(self): ssh_mock = mock.Mock() - ssh_mock.execute = mock.Mock(return_value=(0, "RabbitMQ", "")) - self.assertIsNone(self.resource_profile._start_rabbitmq(ssh_mock)) + self.resource_profile._reset_rabbitmq = mock.Mock() + self.resource_profile._set_rabbitmq_admin_user = mock.Mock() - ssh_mock.execute = mock.Mock(return_value=(0, "", "")) + self.resource_profile._reset_mq_flag = True + ssh_mock.execute = mock.Mock(return_value=(1, "", "")) with self.assertRaises(exceptions.ResourceCommandError): self.resource_profile._start_rabbitmq(ssh_mock) + self.resource_profile._reset_mq_flag = False + self.resource_profile._check_rabbitmq_user = mock.Mock(return_value=False) ssh_mock.execute = mock.Mock(return_value=(1, "", "")) with self.assertRaises(exceptions.ResourceCommandError): self.resource_profile._start_rabbitmq(ssh_mock) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py index ce32a31e2..f04d2c617 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py @@ -23,6 +23,7 @@ from yardstick.tests import STL_MOCKS from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.common import utils from yardstick.common import exceptions +from yardstick.benchmark.contexts import base as ctx_base STLClient = mock.MagicMock() @@ -30,7 +31,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() if stl_patch: - from yardstick.network_services.vnf_generic.vnf.acl_vnf import AclApproxVnf + from yardstick.network_services.vnf_generic.vnf import acl_vnf from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper from yardstick.network_services.nfvi.resource import ResourceProfile from yardstick.network_services.vnf_generic.vnf.acl_vnf import AclApproxSetupEnvSetupEnvHelper @@ -146,7 +147,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': AclApproxVnf.DOWNLINK, + 'vld_id': acl_vnf.AclApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -174,7 +175,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': AclApproxVnf.UPLINK, + 'vld_id': acl_vnf.AclApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -199,7 +200,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': AclApproxVnf.UPLINK, + 'vld_id': acl_vnf.AclApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -209,7 +210,7 @@ class TestAclApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'dpdk_port_num': 0}, 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': AclApproxVnf.DOWNLINK, + 'vld_id': acl_vnf.AclApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -245,22 +246,31 @@ class TestAclApproxVnf(unittest.TestCase): def test___init__(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd) self.assertIsNone(acl_approx_vnf._vnf_process) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd) + acl_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {acl_approx_vnf.name: "mock"} + } 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} + result = { + 'physical_node': 'mock_node', + '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") @@ -269,7 +279,7 @@ class TestAclApproxVnf(unittest.TestCase): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_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) @@ -281,7 +291,7 @@ class TestAclApproxVnf(unittest.TestCase): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_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) @@ -302,7 +312,7 @@ class TestAclApproxVnf(unittest.TestCase): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_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 @@ -322,7 +332,7 @@ class TestAclApproxVnf(unittest.TestCase): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_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() @@ -340,7 +350,7 @@ class TestAclApproxVnf(unittest.TestCase): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - acl_approx_vnf = AclApproxVnf(name, vnfd) + acl_approx_vnf = acl_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", diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py index 6b6f3ef34..635ca41a2 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py @@ -322,9 +322,13 @@ class TestCgnaptApproxVnf(unittest.TestCase): self.assertIsNone(cgnapt_approx_vnf._vnf_process) @mock.patch.object(process, 'check_if_process_failed') + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') def test_collect_kpi(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd) + cgnapt_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {cgnapt_approx_vnf.name: "mock"} + } cgnapt_approx_vnf._vnf_process = mock.MagicMock( **{"is_alive.return_value": True, "exitcode": None}) cgnapt_approx_vnf.q_in = mock.MagicMock() @@ -332,7 +336,12 @@ class TestCgnaptApproxVnf(unittest.TestCase): cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0) cgnapt_approx_vnf.resource = mock.Mock( autospec=resource.ResourceProfile) - result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0} + result = { + 'physical_node': 'mock_node', + 'packets_dropped': 0, + 'packets_fwd': 0, + 'packets_in': 0 + } with mock.patch.object(cgnapt_approx_vnf, 'get_stats', return_value=''): self.assertEqual(result, cgnapt_approx_vnf.collect_kpi()) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index b23854e9f..678e58056 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -20,6 +20,7 @@ import mock from copy import deepcopy from yardstick.tests import STL_MOCKS +from yardstick.benchmark.contexts import base as ctx_base SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -29,7 +30,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() if stl_patch: - from yardstick.network_services.vnf_generic.vnf.prox_vnf import ProxApproxVnf + from yardstick.network_services.vnf_generic.vnf import prox_vnf from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh @@ -187,7 +188,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens513f0', - 'vld_id': ProxApproxVnf.DOWNLINK, + 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -221,7 +222,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens785f0', - 'vld_id': ProxApproxVnf.UPLINK, + 'vld_id': prox_vnf.ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -252,7 +253,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens786f0', - 'vld_id': ProxApproxVnf.UPLINK, + 'vld_id': prox_vnf.ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -264,7 +265,7 @@ class TestProxApproxVnf(unittest.TestCase): }, 'xe1': { 'local_iface_name': 'ens786f1', - 'vld_id': ProxApproxVnf.DOWNLINK, + 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -316,16 +317,21 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def test___init__(self, ssh, *args): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) self.assertIsNone(prox_approx_vnf._vnf_process) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi_no_client(self, ssh, *args): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {prox_approx_vnf.name: "mock"} + } prox_approx_vnf.resource_helper = None expected = { + 'physical_node': 'mock_node', 'packets_in': 0, 'packets_dropped': 0, 'packets_fwd': 0, @@ -334,6 +340,7 @@ class TestProxApproxVnf(unittest.TestCase): result = prox_approx_vnf.collect_kpi() self.assertEqual(result, expected) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) @@ -343,10 +350,14 @@ class TestProxApproxVnf(unittest.TestCase): [2, 1, 2, 3, 4, 5], [3, 1, 2, 3, 4, 5]] resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}} - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {prox_approx_vnf.name: "mock"} + } prox_approx_vnf.resource_helper = resource_helper expected = { + 'physical_node': 'mock_node', 'packets_in': 4, 'packets_dropped': 4, 'packets_fwd': 8, @@ -359,13 +370,16 @@ class TestProxApproxVnf(unittest.TestCase): self.assertNotEqual(result['packets_fwd'], 0) self.assertNotEqual(result['packets_fwd'], 0) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi_error(self, ssh, *args): mock_ssh(ssh) resource_helper = mock.MagicMock() - - prox_approx_vnf = ProxApproxVnf(NAME, deepcopy(self.VNFD0)) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, deepcopy(self.VNFD0)) + prox_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {prox_approx_vnf.name: "mock"} + } prox_approx_vnf.resource_helper = resource_helper prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = [] prox_approx_vnf.vnfd_helper.port_pairs.interfaces = [] @@ -385,7 +399,7 @@ class TestProxApproxVnf(unittest.TestCase): def test_run_prox(self, ssh, *_): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG prox_approx_vnf.ssh_helper.join_bin_path.return_value = '/tool_path12/tool_file34' prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg' @@ -399,7 +413,7 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def bad_test_instantiate(self, *args): - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.scenario_helper = mock.MagicMock() prox_approx_vnf.setup_helper = mock.MagicMock() # we can't mock super @@ -409,7 +423,7 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def test_wait_for_instantiate_panic(self, ssh, *args): mock_ssh(ssh, exec_result=(1, "", "")) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True}) prox_approx_vnf._run_prox = mock.Mock(return_value=0) prox_approx_vnf.WAIT_TIME = 0 @@ -421,7 +435,7 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def test_terminate(self, ssh, *args): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock() prox_approx_vnf._vnf_process.terminate = mock.Mock() prox_approx_vnf.ssh_helper = mock.MagicMock() @@ -433,7 +447,7 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def test__vnf_up_post(self, ssh, *args): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper = mock.Mock() prox_approx_vnf._vnf_up_post() @@ -442,7 +456,7 @@ class TestProxApproxVnf(unittest.TestCase): @mock.patch(SSH_HELPER) def test_vnf_execute_oserror(self, ssh, *args): mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) + prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper = mock.Mock() resource_helper.execute.side_effect = OSError(errno.EPIPE, "") diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py index 5574c6770..edd0ff796 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py @@ -18,6 +18,7 @@ import mock from yardstick.tests import STL_MOCKS from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh +from yardstick.benchmark.contexts import base as ctx_base STLClient = mock.MagicMock() @@ -214,15 +215,25 @@ class TestRouterVNF(unittest.TestCase): stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT) self.assertDictEqual(stats, self.STATS) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") @mock.patch(SSH_HELPER) - def test_collect_kpi(self, ssh, _): + def test_collect_kpi(self, ssh, *args): m = mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] router_vnf = RouterVNF(name, vnfd) + router_vnf.scenario_helper.scenario_cfg = { + 'nodes': {router_vnf.name: "mock"} + } router_vnf.ssh_helper = m - result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}} + result = { + 'physical_node': 'mock_node', + 'packets_dropped': 0, + 'packets_fwd': 0, + 'packets_in': 0, + 'link_stats': {} + } self.assertEqual(result, router_vnf.collect_kpi()) @mock.patch(SSH_HELPER) @@ -235,9 +246,9 @@ class TestRouterVNF(unittest.TestCase): router_vnf._run() router_vnf.ssh_helper.drop_connection.assert_called_once() - @mock.patch("yardstick.network_services.vnf_generic.vnf.router_vnf.Context") + @mock.patch.object(ctx_base, 'Context') @mock.patch(SSH_HELPER) - def test_instantiate(self, ssh, _): + def test_instantiate(self, ssh, *args): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index ce849d174..331e80d00 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -18,7 +18,6 @@ import unittest import mock import six -from yardstick.benchmark.contexts.base import Context from yardstick.common import exceptions as y_exceptions from yardstick.common import utils from yardstick.network_services.nfvi.resource import ResourceProfile @@ -35,6 +34,7 @@ from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper from yardstick.tests.unit.network_services.vnf_generic.vnf import test_base +from yardstick.benchmark.contexts import base as ctx_base class MockError(Exception): @@ -1533,33 +1533,20 @@ class TestSampleVnf(unittest.TestCase): self.assertIsNotNone(sample_vnf.queue_wrapper) self.assertIsNotNone(sample_vnf._vnf_process) + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') @mock.patch("yardstick.ssh.SSH") - def test_instantiate(self, ssh): + def test_instantiate(self, ssh, *args): test_base.mock_ssh(ssh) - nodes = { 'vnf1': 'name1', 'vnf2': 'name2', } - context1 = mock.Mock() - context1._get_server.return_value = None - context2 = mock.Mock() - context2._get_server.return_value = context2 - - try: - Context.list.clear() - except AttributeError: - # clear() but works in Py2.7 - Context.list[:] = [] - - Context.list.extend([ - context1, - context2, - ]) - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf.scenario_helper.scenario_cfg = { + 'nodes': {sample_vnf.name: 'mock'} + } sample_vnf.APP_NAME = 'sample1' sample_vnf._start_server = mock.Mock(return_value=0) sample_vnf._vnf_process = mock.MagicMock() @@ -1572,7 +1559,6 @@ class TestSampleVnf(unittest.TestCase): } self.assertIsNone(sample_vnf.instantiate(scenario_cfg, {})) - self.assertEqual(sample_vnf.nfvi_context, context2) def test__update_collectd_options(self): scenario_cfg = {'options': @@ -1709,9 +1695,13 @@ class TestSampleVnf(unittest.TestCase): self.assertEqual(sample_vnf.get_stats(), 'the stats') - def test_collect_kpi(self): + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') + def test_collect_kpi(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf.scenario_helper.scenario_cfg = { + 'nodes': {sample_vnf.name: "mock"} + } sample_vnf.APP_NAME = 'sample1' sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)' sample_vnf.COLLECT_MAP = { @@ -1728,18 +1718,24 @@ class TestSampleVnf(unittest.TestCase): 'k2': 34, 'k3': 91, 'collect_stats': {}, + 'physical_node': 'mock_node' } result = sample_vnf.collect_kpi() self.assertDictEqual(result, expected) - def test_collect_kpi_default(self): + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') + def test_collect_kpi_default(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sample_vnf = SampleVNF('vnf1', vnfd) + sample_vnf.scenario_helper.scenario_cfg = { + 'nodes': {sample_vnf.name: "mock"} + } sample_vnf.APP_NAME = 'sample1' sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)' sample_vnf.get_stats = mock.Mock(return_value='') expected = { + 'physical_node': 'mock_node', 'packets_in': 0, 'packets_fwd': 0, 'packets_dropped': 0, diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py index 59594a3c3..6858cf70a 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py @@ -22,6 +22,7 @@ import unittest from yardstick import ssh from yardstick.common import utils from yardstick.tests import STL_MOCKS +from yardstick.benchmark.contexts import base as ctx_base STLClient = mock.MagicMock() @@ -137,17 +138,26 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) self.assertIsNone(ixload_traffic_gen.resource_helper.data) - def test_collect_kpi(self): + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') + def test_collect_kpi(self, *args): 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] ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + ixload_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {ixload_traffic_gen.name: "mock"} + } ixload_traffic_gen.data = {} restult = ixload_traffic_gen.collect_kpi() - self.assertEqual({}, restult) + expected = { + 'physical_node': 'mock_node', + 'collect_stats': {}, + } + self.assertEqual(expected, restult) def test_listen_traffic(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -161,8 +171,10 @@ class TestIxLoadTrafficGen(unittest.TestCase): @mock.patch.object(utils, 'find_relative_file') @mock.patch.object(utils, 'makedirs') + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") - def test_instantiate(self, *args): + def test_instantiate(self, shutil, *args): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -176,6 +188,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): 'ixia_profile': "ixload.cfg", 'task_path': "/path/to/task"} ixload_traffic_gen.RESULTS_MOUNT = "/tmp/result" + shutil.copy = mock.Mock() scenario_cfg.update({'options': {'packetsize': 64, 'traffic_type': 4, 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, 'vnf__1': {'rules': 'acl_1rule.yaml', @@ -185,17 +198,21 @@ class TestIxLoadTrafficGen(unittest.TestCase): '1C/1T', 'worker_threads': 1}} }}) + scenario_cfg.update({ + 'nodes': {ixload_traffic_gen.name: "mock"} + }) with mock.patch.object(six.moves.builtins, 'open', create=True) as mock_open: mock_open.return_value = mock.MagicMock() ixload_traffic_gen.instantiate(scenario_cfg, {}) + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") - def test_run_traffic(self, *args): + def test_run_traffic(self, shutil, *args): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -216,15 +233,17 @@ class TestIxLoadTrafficGen(unittest.TestCase): sut.connection = mock.Mock() sut.connection.run = mock.Mock() sut._traffic_runner = mock.Mock(return_value=0) + shutil.copy = mock.Mock() result = sut.run_traffic(mock_traffic_profile) self.assertIsNone(result) + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") - def test_run_traffic_csv(self, *args): + def test_run_traffic_csv(self, shutil, *args): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -245,6 +264,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): sut.connection = mock.Mock() sut.connection.run = mock.Mock() sut._traffic_runner = mock.Mock(return_value=0) + shutil.copy = mock.Mock() subprocess.call(["touch", "/tmp/1.csv"]) sut.rel_bin_path = mock.Mock(return_value="/tmp/*.csv") result = sut.run_traffic(mock_traffic_profile) @@ -257,8 +277,9 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) self.assertIsNone(ixload_traffic_gen.terminate()) - @mock.patch("yardstick.ssh.SSH") - def test_parse_csv_read(self, mock_ssh): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch.object(ssh, 'SSH') + def test_parse_csv_read(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] kpi_data = { 'HTTP Total Throughput (Kbps)': 1, @@ -280,8 +301,9 @@ class TestIxLoadTrafficGen(unittest.TestCase): for key_left, key_right in IxLoadResourceHelper.KPI_LIST.items(): self.assertEqual(result[key_left][-1], int(kpi_data[key_right])) - @mock.patch("yardstick.ssh.SSH") - def test_parse_csv_read_value_error(self, mock_ssh): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") + @mock.patch.object(ssh, 'SSH') + def test_parse_csv_read_value_error(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] http_reader = [{ 'HTTP Total Throughput (Kbps)': 1, @@ -301,8 +323,9 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload_traffic_gen.resource_helper.parse_csv_read(http_reader) self.assertDictEqual(ixload_traffic_gen.resource_helper.result, init_value) + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") @mock.patch.object(ssh, 'SSH') - def test_parse_csv_read_error(self, mock_ssh): + def test_parse_csv_read_error(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] http_reader = [{ 'HTTP Total Throughput (Kbps)': 1, diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 14e0db788..d774bb9f7 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -21,6 +21,7 @@ import unittest from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.tests import STL_MOCKS +from yardstick.benchmark.contexts import base as ctx_base SSH_HELPER = "yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper" @@ -253,14 +254,25 @@ class TestPingTrafficGen(unittest.TestCase): self.assertNotEqual(ext_ifs[0]['virtual-interface']['local_iface_name'], 'if_name_1') self.assertNotEqual(ext_ifs[1]['virtual-interface']['local_iface_name'], 'if_name_2') + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch("yardstick.ssh.SSH") - def test_collect_kpi(self, ssh): + def test_collect_kpi(self, ssh, *args): mock_ssh(ssh, exec_result=(0, "success", "")) + ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0) + ping_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {ping_traffic_gen.name: "mock"} + } ping_traffic_gen._queue = Queue() ping_traffic_gen._queue.put({}) - ping_traffic_gen.collect_kpi() - self.assertEqual(ping_traffic_gen._result, {}) + expected = { + 'physical_node': 'mock_node', + 'collect_stats': {} + } + # NOTE: Why we check _result but not collect_kpi() return value + # self.assertEqual(ping_traffic_gen._result, {}) + self.assertEqual(ping_traffic_gen.collect_kpi(), expected) + @mock.patch(SSH_HELPER) def test_instantiate(self, ssh): diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py index f581ec8d9..050aa4aa0 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py @@ -18,6 +18,7 @@ import mock from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.tests import STL_MOCKS +from yardstick.benchmark.contexts import base as ctx_base SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -324,15 +325,22 @@ class TestProxTrafficGen(unittest.TestCase): self.assertIsNone(prox_traffic_gen._tg_process) self.assertIsNone(prox_traffic_gen._traffic_process) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) - prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0) + prox_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {prox_traffic_gen.name: "mock"} + } prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock( **{"self.check_if_system_agent_running.return_value": [False]}) prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="") - self.assertEqual({}, prox_traffic_gen.collect_kpi()) + expected = { + 'collect_stats': {}, + 'physical_node': 'mock_node' + } + self.assertEqual(prox_traffic_gen.collect_kpi(), expected) @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index dca8098fa..42ac40b50 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -21,6 +21,7 @@ import unittest from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api from yardstick.network_services.traffic_profile import base as tp_base from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia +from yardstick.benchmark.contexts import base as ctx_base TEST_FILE_YAML = 'nsb_test_case.yaml' @@ -186,6 +187,7 @@ class TestIXIATrafficGen(unittest.TestCase): ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd) self.assertIsNone(ixnet_traffic_gen.listen_traffic({})) + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') def test_instantiate(self, *args): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -212,6 +214,9 @@ class TestIXIATrafficGen(unittest.TestCase): 'lb_count': 1, 'worker_config': '1C/1T', 'worker_threads': 1}}}}) + scenario_cfg.update({ + 'nodes': {ixnet_traffic_gen.name: "mock"} + }) ixnet_traffic_gen.topology = "" ixnet_traffic_gen.get_ixobj = mock.MagicMock() ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock() @@ -220,17 +225,26 @@ class TestIXIATrafficGen(unittest.TestCase): IOError, ixnet_traffic_gen.instantiate(scenario_cfg, {})) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') def test_collect_kpi(self, *args): 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] ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd) + ixnet_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {ixnet_traffic_gen.name: "mock"} + } ixnet_traffic_gen.data = {} restult = ixnet_traffic_gen.collect_kpi() - self.assertEqual({}, restult) + + expected = {'collect_stats': {}, + 'physical_node': 'mock_node'} + + self.assertEqual(expected, restult) def test_terminate(self, *args): with mock.patch("yardstick.ssh.SSH") as ssh: diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index 9531b90c4..4d3e4ff0b 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -18,6 +18,7 @@ import unittest from yardstick.network_services.traffic_profile import base as tp_base from yardstick.network_services.vnf_generic.vnf import sample_vnf from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex +from yardstick.benchmark.contexts import base as ctx_base class TestTrexRfcResouceHelper(unittest.TestCase): @@ -224,7 +225,20 @@ class TestTrexTrafficGenRFC(unittest.TestCase): trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0) self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value) - def test_instantiate(self): + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') + def test_collect_kpi(self, *args): + trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0) + trex_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {trex_traffic_gen.name: "mock"} + } + expected = { + 'physical_node': 'mock_node', + 'collect_stats': {}, + } + self.assertEqual(trex_traffic_gen.collect_kpi(), expected) + + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') + def test_instantiate(self, *args): mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -255,10 +269,11 @@ class TestTrexTrafficGenRFC(unittest.TestCase): }, } tg_rfc2544_trex.WAIT_TIME = 3 - scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]}) + scenario_cfg.update({"nodes": {"tg_1": {}, "vnf1": {}}}) self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {})) - def test_instantiate_error(self): + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') + def test_instantiate_error(self, *args): mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -268,10 +283,10 @@ class TestTrexTrafficGenRFC(unittest.TestCase): trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() scenario_cfg = { "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B", - "nodes": [ - "tg_1", - "vnf_1", - ], + "nodes": { + "tg_1": {}, + "vnf1": {} + }, "topology": 'nsb_test_case.yaml', 'options': { 'packetsize': 64, diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py index 4f8742477..350ba8448 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py @@ -21,9 +21,10 @@ from yardstick.network_services.traffic_profile import base as tp_base from yardstick.network_services.traffic_profile import rfc2544 from yardstick.network_services.vnf_generic.vnf import sample_vnf from yardstick.network_services.vnf_generic.vnf import tg_trex +from yardstick.benchmark.contexts import base as ctx_base -NAME = 'vnf_1' +NAME = 'vnf__1' class TestTrexTrafficGen(unittest.TestCase): @@ -303,19 +304,28 @@ class TestTrexTrafficGen(unittest.TestCase): self.assertIsInstance(trex_traffic_gen.resource_helper, tg_trex.TrexResourceHelper) - def test_collect_kpi(self): + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') + def test_collect_kpi(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd) + trex_traffic_gen.scenario_helper.scenario_cfg = { + 'nodes': {trex_traffic_gen.name: "mock"} + } trex_traffic_gen.resource_helper._queue.put({}) result = trex_traffic_gen.collect_kpi() - self.assertEqual({}, result) + expected = { + 'physical_node': 'mock_node', + 'collect_stats': {} + } + self.assertEqual(expected, result) def test_listen_traffic(self): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd) self.assertIsNone(trex_traffic_gen.listen_traffic({})) - def test_instantiate(self): + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') + def test_instantiate(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd) trex_traffic_gen._start_server = mock.Mock(return_value=0) @@ -329,7 +339,8 @@ class TestTrexTrafficGen(unittest.TestCase): self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)) - def test_instantiate_error(self): + @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context') + def test_instantiate_error(self, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd) trex_traffic_gen._start_server = mock.Mock(return_value=0) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py index 05a0ead71..1c4ced303 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py @@ -19,6 +19,7 @@ import os from yardstick.tests import STL_MOCKS from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh +from yardstick.benchmark.contexts import base as ctx_base SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -330,6 +331,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase): self.assertIsNone(udp_replay_approx_vnf._vnf_process) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) @@ -341,14 +343,21 @@ class TestUdpReplayApproxVnf(unittest.TestCase): "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.scenario_helper.scenario_cfg = { + 'nodes': {udp_replay_approx_vnf.name: "mock"} + } 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=get_stats_ret_val) - - result = {'collect_stats': {}, 'packets_dropped': 0, - 'packets_fwd': 14748451, 'packets_in': 14748472} + result = { + 'physical_node': 'mock_node', + 'collect_stats': {}, + 'packets_dropped': 0, + 'packets_fwd': 14748451, + 'packets_in': 14748472 + } self.assertEqual(result, udp_replay_approx_vnf.collect_kpi()) @mock.patch(SSH_HELPER) @@ -372,14 +381,18 @@ class TestUdpReplayApproxVnf(unittest.TestCase): file_path = os.path.join(curr_path, filename) return file_path - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch(SSH_HELPER) - def test__build_config(self, ssh, mock_context, *args): + def test__build_config(self, ssh, mock_get_ctx, *args): mock_ssh(ssh) + nfvi_context = mock.Mock() + nfvi_context.attrs = {'nfvi_type': 'baremetal'} + mock_get_ctx.return_value = nfvi_context + 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 = mock_get_ctx 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") @@ -393,13 +406,16 @@ class TestUdpReplayApproxVnf(unittest.TestCase): self.assertEqual(cmd_line, expected) @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open') - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch(SSH_HELPER) - def test__build_pipeline_kwargs(self, ssh, mock_context, *args): + def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args): mock_ssh(ssh) + + nfvi_context = mock.Mock() + nfvi_context.attrs = {'nfvi_type': "baremetal"} + mock_get_ctx.return_value = nfvi_context + 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") @@ -430,7 +446,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase): udp_replay_approx_vnf.ssh_helper.run.assert_called_once() - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch(SSH_HELPER) def test_instantiate(self, ssh, *args): mock_ssh(ssh) @@ -449,7 +465,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase): self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch('yardstick.ssh.SSH') @mock.patch(SSH_HELPER) def test_instantiate_panic(self, *args): diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py index a0a0794ea..b67a3cdee 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py @@ -21,7 +21,7 @@ from yardstick.tests import STL_MOCKS from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.common import utils - +from yardstick.benchmark.contexts import base as ctx_base STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) @@ -259,12 +259,15 @@ pipeline> """ # noqa @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vfw_approx_vnf = FWApproxVnf(name, vnfd) + vfw_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {vfw_approx_vnf.name: "mock"} + } 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) @@ -273,6 +276,7 @@ pipeline> **{'collect_kpi.return_value': {"core": {}}}) vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS) result = { + 'physical_node': 'mock_node', 'packets_dropped': 0, 'packets_fwd': 6007180, 'packets_in': 6007180, @@ -334,7 +338,7 @@ pipeline> vfw_approx_vnf.ssh_helper.run.assert_called_once() @mock.patch.object(utils, 'find_relative_file') - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch.object(ctx_base.Context, 'get_context_from_server') @mock.patch(SSH_HELPER) def test_instantiate(self, ssh, *args): mock_ssh(ssh) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 73f91d1b1..f91852f74 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -26,6 +26,7 @@ from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import File from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper +from yardstick.benchmark.contexts import base as ctx_base SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -547,8 +548,9 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) self.assertIsNone(vpe_approx_vnf._vnf_process) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) - def test_collect_kpi_sa_not_running(self, ssh): + def test_collect_kpi_sa_not_running(self, ssh, *args): mock_ssh(ssh) resource = mock.Mock(autospec=ResourceProfile) @@ -557,12 +559,16 @@ class TestVpeApproxVnf(unittest.TestCase): resource.check_if_system_agent_running.return_value = (1, None) vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) + vpe_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {vpe_approx_vnf.name: "mock"} + } vpe_approx_vnf.q_in = mock.MagicMock() vpe_approx_vnf.q_out = mock.MagicMock() vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0) vpe_approx_vnf.resource_helper.resource = resource expected = { + 'physical_node': 'mock_node', 'pkt_in_down_stream': 0, 'pkt_in_up_stream': 0, 'pkt_drop_down_stream': 0, @@ -571,8 +577,9 @@ class TestVpeApproxVnf(unittest.TestCase): } self.assertEqual(vpe_approx_vnf.collect_kpi(), expected) + @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node') @mock.patch(SSH_HELPER) - def test_collect_kpi_sa_running(self, ssh): + def test_collect_kpi_sa_running(self, ssh, *args): mock_ssh(ssh) resource = mock.Mock(autospec=ResourceProfile) @@ -580,12 +587,16 @@ class TestVpeApproxVnf(unittest.TestCase): resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234} vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) + vpe_approx_vnf.scenario_helper.scenario_cfg = { + 'nodes': {vpe_approx_vnf.name: "mock"} + } vpe_approx_vnf.q_in = mock.MagicMock() vpe_approx_vnf.q_out = mock.MagicMock() vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0) vpe_approx_vnf.resource_helper.resource = resource expected = { + 'physical_node': 'mock_node', 'pkt_in_down_stream': 0, 'pkt_in_up_stream': 0, 'pkt_drop_down_stream': 0, @@ -634,7 +645,6 @@ class TestVpeApproxVnf(unittest.TestCase): 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("six.moves.builtins.open") @mock.patch(SSH_HELPER) -- cgit 1.2.3-korg