summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py176
1 files changed, 92 insertions, 84 deletions
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 f91852f74..c1664f2f0 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
@@ -11,35 +11,20 @@
# 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 multiprocessing import Process, Queue
-import os
import time
import mock
from six.moves import configparser
import unittest
-from yardstick.tests import STL_MOCKS
-from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath
-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'
-
-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.vpe_vnf import ConfigCreate
- from yardstick.network_services.nfvi.resource import ResourceProfile
- from yardstick.network_services.vnf_generic.vnf.vpe_vnf import \
- VpeApproxVnf, VpeApproxSetupEnvHelper
+from yardstick.network_services.nfvi.resource import ResourceProfile
+from yardstick.network_services.vnf_generic.vnf import base as vnf_base
+from yardstick.network_services.vnf_generic.vnf import sample_vnf
+from yardstick.network_services.vnf_generic.vnf import vpe_vnf
+from yardstick.tests.unit.network_services.vnf_generic.vnf import test_base
TEST_FILE_YAML = 'nsb_test_case.yaml'
@@ -48,7 +33,7 @@ NAME = 'vnf_1'
PING_OUTPUT_1 = "Pkts in: 101\r\n\tPkts dropped by AH: 100\r\n\tPkts dropped by other: 100"
-MODULE_PATH = FileAbsPath(__file__)
+MODULE_PATH = test_base.FileAbsPath(__file__)
get_file_abspath = MODULE_PATH.get_path
@@ -156,20 +141,20 @@ class TestConfigCreate(unittest.TestCase):
}
def test___init__(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
self.assertEqual(config_create.uplink_ports, ['xe0'])
self.assertEqual(config_create.downlink_ports, ['xe1'])
self.assertEqual(config_create.socket, 2)
def test_dpdk_port_to_link_id(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
self.assertEqual(config_create.dpdk_port_to_link_id_map, {'xe0': 0, 'xe1': 1})
def test_vpe_initialize(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
config = configparser.ConfigParser()
config_create.vpe_initialize(config)
self.assertEqual(config.get('EAL', 'log_level'), '0')
@@ -179,16 +164,16 @@ class TestConfigCreate(unittest.TestCase):
self.assertEqual(config.get('MEMPOOL1', 'pool_size'), '2M')
def test_vpe_rxq(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
config = configparser.ConfigParser()
config_create.downlink_ports = ['xe0']
config_create.vpe_rxq(config)
self.assertEqual(config.get('RXQ0.0', 'mempool'), 'MEMPOOL1')
def test_get_sink_swq(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 2)
config = configparser.ConfigParser()
config.add_section('PIPELINE0')
config.set('PIPELINE0', 'key1', 'value1')
@@ -205,8 +190,8 @@ class TestConfigCreate(unittest.TestCase):
self.assertEqual(config_create.get_sink_swq(config, 'PIPELINE0', 'key5', 5), 'SWQ0 SINK1')
def test_generate_vpe_script(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- vpe_config_vnf = ConfigCreate(vnfd_helper, 2)
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ vpe_config_vnf = vpe_vnf.ConfigCreate(vnfd_helper, 2)
intf = [
{
"name": 'xe1',
@@ -230,15 +215,34 @@ class TestConfigCreate(unittest.TestCase):
self.assertNotEqual(result, '')
def test_create_vpe_config(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- config_create = ConfigCreate(vnfd_helper, 23)
- config_create.downlink_ports = ['xe1']
+ vnfd_helper = vnf_base.VnfdHelper(self.VNFD_0)
+ config_create = vpe_vnf.ConfigCreate(vnfd_helper, 23)
config_create.uplink_ports = ['xe1']
- curr_path = os.path.dirname(os.path.abspath(__file__))
- vpe_cfg = "samples/vnf_samples/nsut/vpe/vpe_config"
- vnf_cfg = os.path.join(curr_path, "../../../../..", vpe_cfg)
- config_create.create_vpe_config(vnf_cfg)
- os.system("git checkout -- %s" % vnf_cfg)
+ with mock.patch.object(config_create, 'vpe_upstream') as mock_up, \
+ mock.patch.object(config_create, 'vpe_downstream') as \
+ mock_down, \
+ mock.patch.object(config_create, 'vpe_tmq') as mock_tmq, \
+ mock.patch.object(config_create, 'vpe_initialize') as \
+ mock_ini, \
+ mock.patch.object(config_create, 'vpe_rxq') as mock_rxq:
+ mock_ini_obj = mock.Mock()
+ mock_rxq_obj = mock.Mock()
+ mock_up_obj = mock.Mock()
+ mock_down_obj = mock.Mock()
+ mock_tmq_obj = mock.Mock()
+ mock_ini.return_value = mock_ini_obj
+ mock_rxq.return_value = mock_rxq_obj
+ mock_up.return_value = mock_up_obj
+ mock_down.return_value = mock_down_obj
+ mock_tmq.return_value = mock_tmq_obj
+ config_create.create_vpe_config('fake_config_file')
+
+ mock_rxq.assert_called_once_with(mock_ini_obj)
+ mock_up.assert_called_once_with('fake_config_file', 0)
+ mock_down.assert_called_once_with('fake_config_file', 0)
+ mock_tmq.assert_called_once_with(mock_down_obj, 0)
+ mock_up_obj.write.assert_called_once()
+ mock_tmq_obj.write.assert_called_once()
class TestVpeApproxVnf(unittest.TestCase):
@@ -410,7 +414,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens513f0',
- 'vld_id': VpeApproxVnf.DOWNLINK,
+ 'vld_id': vpe_vnf.VpeApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -444,7 +448,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens785f0',
- 'vld_id': VpeApproxVnf.UPLINK,
+ 'vld_id': vpe_vnf.VpeApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -475,7 +479,7 @@ class TestVpeApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens786f0',
- 'vld_id': VpeApproxVnf.UPLINK,
+ 'vld_id': vpe_vnf.VpeApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -487,7 +491,7 @@ class TestVpeApproxVnf(unittest.TestCase):
},
'xe1': {
'local_iface_name': 'ens786f1',
- 'vld_id': VpeApproxVnf.DOWNLINK,
+ 'vld_id': vpe_vnf.VpeApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -545,20 +549,21 @@ class TestVpeApproxVnf(unittest.TestCase):
self._mock_time_sleep.stop()
def test___init__(self):
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_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)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server',
+ return_value='mock_node')
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_collect_kpi_sa_not_running(self, ssh, *args):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
resource.check_if_system_agent_running.return_value = 1, ''
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
resource.check_if_system_agent_running.return_value = (1, None)
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.scenario_helper.scenario_cfg = {
'nodes': {vpe_approx_vnf.name: "mock"}
}
@@ -577,16 +582,17 @@ 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)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server',
+ return_value='mock_node')
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_collect_kpi_sa_running(self, ssh, *args):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
resource.check_if_system_agent_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.scenario_helper.scenario_cfg = {
'nodes': {vpe_approx_vnf.name: "mock"}
}
@@ -605,20 +611,20 @@ class TestVpeApproxVnf(unittest.TestCase):
}
self.assertEqual(vpe_approx_vnf.collect_kpi(), expected)
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_vnf_execute(self, ssh):
- mock_ssh(ssh)
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ test_base.mock_ssh(ssh)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
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)
self.assertEqual(vpe_approx_vnf.vnf_execute("quit", 0), '')
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_run_vpe(self, ssh):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML)
vpe_approx_vnf.vnf_cfg = {
'lb_config': 'SW',
@@ -647,11 +653,11 @@ class TestVpeApproxVnf(unittest.TestCase):
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig")
@mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.ConfigCreate")
@mock.patch("six.moves.builtins.open")
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_build_config(self, ssh, *args):
- mock_ssh(ssh)
- vpe_approx_vnf = VpeApproxSetupEnvHelper(mock.MagicMock(),
- mock.MagicMock(), mock.MagicMock())
+ test_base.mock_ssh(ssh)
+ vpe_approx_vnf = vpe_vnf.VpeApproxSetupEnvHelper(
+ mock.MagicMock(), mock.MagicMock(), mock.MagicMock())
vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML)
vpe_approx_vnf.generate_port_pairs = mock.Mock()
vpe_approx_vnf.vnf_cfg = {
@@ -687,9 +693,9 @@ class TestVpeApproxVnf(unittest.TestCase):
expected = 'sudo tool_path -p 0x3 -f /tmp/vpe_config -s /tmp/vpe_script --hwlb 3'
self.assertEqual(vpe_approx_vnf.build_config(), expected)
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_wait_for_instantiate(self, ssh):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
mock_process = mock.Mock(autospec=Process)
mock_process.is_alive.return_value = True
@@ -701,18 +707,19 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_resource = mock.MagicMock()
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock_process
vpe_approx_vnf.q_out = mock_q_out
- vpe_approx_vnf.queue_wrapper = mock.Mock(autospec=QueueFileWrapper)
+ vpe_approx_vnf.queue_wrapper = mock.Mock(
+ autospec=vnf_base.QueueFileWrapper)
vpe_approx_vnf.resource_helper.resource = mock_resource
vpe_approx_vnf.q_out.put("pipeline>")
self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432)
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_wait_for_instantiate_fragmented(self, ssh):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
mock_process = mock.Mock(autospec=Process)
mock_process.is_alive.return_value = True
@@ -725,17 +732,18 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_resource = mock.MagicMock()
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock_process
vpe_approx_vnf.q_out = mock_q_out
- vpe_approx_vnf.queue_wrapper = mock.Mock(autospec=QueueFileWrapper)
+ vpe_approx_vnf.queue_wrapper = mock.Mock(
+ autospec=vnf_base.QueueFileWrapper)
vpe_approx_vnf.resource_helper.resource = mock_resource
self.assertEqual(vpe_approx_vnf.wait_for_instantiate(), 432)
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_wait_for_instantiate_crash(self, ssh):
- mock_ssh(ssh, exec_result=(1, "", ""))
+ test_base.mock_ssh(ssh, exec_result=(1, "", ""))
mock_process = mock.Mock(autospec=Process)
mock_process.is_alive.return_value = False
@@ -743,7 +751,7 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_resource = mock.MagicMock()
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock_process
vpe_approx_vnf.resource_helper.resource = mock_resource
@@ -752,9 +760,9 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertIn('VNF process died', str(raised.exception))
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_wait_for_instantiate_panic(self, ssh):
- mock_ssh(ssh, exec_result=(1, "", ""))
+ test_base.mock_ssh(ssh, exec_result=(1, "", ""))
mock_process = mock.Mock(autospec=Process)
mock_process.is_alive.return_value = True
@@ -762,7 +770,7 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_resource = mock.MagicMock()
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock_process
vpe_approx_vnf.resource_helper.resource = mock_resource
@@ -772,9 +780,9 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertIn('Error starting', str(raised.exception))
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_wait_for_instantiate_panic_fragmented(self, ssh):
- mock_ssh(ssh, exec_result=(1, "", ""))
+ test_base.mock_ssh(ssh, exec_result=(1, "", ""))
mock_process = mock.Mock(autospec=Process)
mock_process.is_alive.return_value = True
@@ -787,7 +795,7 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_resource = mock.MagicMock()
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock_process
vpe_approx_vnf.q_out = mock_q_out
vpe_approx_vnf.resource_helper.resource = mock_resource
@@ -797,11 +805,11 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertIn('Error starting', str(raised.exception))
- @mock.patch(SSH_HELPER)
+ @mock.patch.object(sample_vnf, 'VnfSshHelper')
def test_terminate(self, ssh):
- mock_ssh(ssh)
+ test_base.mock_ssh(ssh)
- vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf = vpe_vnf.VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf._vnf_process = mock.MagicMock()
vpe_approx_vnf._resource_collect_stop = mock.Mock()
vpe_approx_vnf.resource_helper = mock.MagicMock()