X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Funit%2Fnetwork_services%2Fvnf_generic%2Fvnf%2Ftest_prox_vnf.py;h=159b1f718941781dceb07a5110f649030e620e8c;hb=6cd3aed0077d6cced71417a48f92527ef1ecbd3e;hp=4b115f2d6851bc13062f0559d9f14cbf0b7e23a5;hpb=0a24ca320c46c10a50d38b8eab6336eb0e32f8c9;p=yardstick.git 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 4b115f2d6..159b1f718 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 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +13,6 @@ # limitations under the License. # -from __future__ import absolute_import - import errno import os import unittest @@ -85,9 +81,10 @@ class TestProxApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', - 'vld_id': '', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -103,10 +100,11 @@ class TestProxApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.1', 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', - 'vld_id': '', + 'vld_id': 'uplink_0', + 'ifname': 'xe1', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -131,6 +129,8 @@ class TestProxApproxVnf(unittest.TestCase): 'packets_in', 'packets_fwd', 'packets_dropped', + 'curr_packets_fwd', + 'curr_packets_in' ], }, 'connection-point': [ @@ -187,7 +187,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -221,7 +221,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -252,7 +252,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -264,7 +264,7 @@ class TestProxApproxVnf(unittest.TestCase): }, 'xe1': { 'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -314,13 +314,13 @@ class TestProxApproxVnf(unittest.TestCase): } @mock.patch(SSH_HELPER) - def test___init__(self, ssh, mock_time): + def test___init__(self, ssh, *args): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) self.assertIsNone(prox_approx_vnf._vnf_process) @mock.patch(SSH_HELPER) - def test_collect_kpi_no_client(self, ssh, mock_time): + def test_collect_kpi_no_client(self, ssh, *args): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) @@ -329,33 +329,37 @@ class TestProxApproxVnf(unittest.TestCase): 'packets_in': 0, 'packets_dropped': 0, 'packets_fwd': 0, - 'collect_stats': {'core': {}}, + 'collect_stats': {'core': {}} } result = prox_approx_vnf.collect_kpi() self.assertEqual(result, expected) @mock.patch(SSH_HELPER) - def test_collect_kpi(self, ssh, mock_time): + def test_collect_kpi(self, ssh, *args): mock_ssh(ssh) resource_helper = mock.MagicMock() resource_helper.execute.return_value = list(range(12)) - resource_helper.collect_kpi.return_value = {'core': {'result': 234}} + resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}} prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper expected = { - 'packets_in': 7, + 'packets_in': 6, 'packets_dropped': 1, - 'packets_fwd': 6, + 'packets_fwd': 7, 'collect_stats': {'core': {'result': 234}}, } result = prox_approx_vnf.collect_kpi() - self.assertEqual(result, expected) + self.assertEqual(result['packets_in'], expected['packets_in']) + self.assertEqual(result['packets_dropped'], expected['packets_dropped']) + self.assertEqual(result['packets_fwd'], expected['packets_fwd']) + self.assertNotEqual(result['packets_fwd'], 0) + self.assertNotEqual(result['packets_fwd'], 0) @mock.patch(SSH_HELPER) - def test_collect_kpi_error(self, ssh, mock_time): + def test_collect_kpi_error(self, ssh, *args): mock_ssh(ssh) resource_helper = mock.MagicMock() @@ -363,42 +367,46 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf = ProxApproxVnf(NAME, deepcopy(self.VNFD0)) prox_approx_vnf.resource_helper = resource_helper prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = [] + prox_approx_vnf.vnfd_helper.port_pairs.interfaces = [] with self.assertRaises(RuntimeError): prox_approx_vnf.collect_kpi() - def _get_file_abspath(self, filename, mock_time): + def _get_file_abspath(self, filename, *args): curr_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(curr_path, filename) return file_path + @mock.patch('yardstick.common.utils.open', create=True) + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) + @mock.patch('yardstick.network_services.helpers.iniparser.open', create=True) @mock.patch(SSH_HELPER) - def test_run_prox(self, ssh, mock_time): + def test_run_prox(self, ssh, *_): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG - prox_approx_vnf.ssh_helper.provision_tool.return_value = '/tool_path12/tool_file34' + prox_approx_vnf.ssh_helper.join_bin_path.return_value = '/tool_path12/tool_file34' prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg' expected = "sudo bash -c 'cd /tool_path12; " \ - "/tool_path12/tool_file34 -o cli -t -f configs/file56.cfg '" + "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '" prox_approx_vnf._run() result = prox_approx_vnf.ssh_helper.run.call_args[0][0] self.assertEqual(result, expected) @mock.patch(SSH_HELPER) - def bad_test_instantiate(self, ssh, mock_time): + def bad_test_instantiate(self, *args): prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) 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 + prox_approx_vnf.setup_helper.build_config.assert_called_once() @mock.patch(SSH_HELPER) - def test_wait_for_instantiate_panic(self, ssh, mock_time): + 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._vnf_process = mock.MagicMock(**{"is_alive.return_value": True}) @@ -408,16 +416,9 @@ class TestProxApproxVnf(unittest.TestCase): with self.assertRaises(RuntimeError): prox_approx_vnf.wait_for_instantiate() - @mock.patch(SSH_HELPER) - def test_scale(self, ssh, mock_time): - mock_ssh(ssh) - prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) - with self.assertRaises(NotImplementedError): - prox_approx_vnf.scale() - @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket') @mock.patch(SSH_HELPER) - def test_terminate(self, ssh, mock_socket, mock_time): + def test_terminate(self, ssh, *args): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock() @@ -429,7 +430,7 @@ class TestProxApproxVnf(unittest.TestCase): self.assertIsNone(prox_approx_vnf.terminate()) @mock.patch(SSH_HELPER) - def test__vnf_up_post(self, ssh, mock_time): + def test__vnf_up_post(self, ssh, *args): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper = mock.Mock() @@ -438,7 +439,7 @@ class TestProxApproxVnf(unittest.TestCase): self.assertEqual(resource_helper.up_post.call_count, 1) @mock.patch(SSH_HELPER) - def test_vnf_execute_oserror(self, ssh, mock_time): + def test_vnf_execute_oserror(self, ssh, *args): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper = mock.Mock() @@ -452,6 +453,3 @@ class TestProxApproxVnf(unittest.TestCase): 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()