aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/network_services')
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_iniparser.py52
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py14
2 files changed, 51 insertions, 15 deletions
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 15d6adea1..1ad8df9c6 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py
@@ -28,6 +28,7 @@ stl_patch.start()
if stl_patch:
from yardstick.network_services.vnf_generic.vnf.iniparser import ParseError
+ from yardstick.network_services.vnf_generic.vnf.iniparser import LineParser
from yardstick.network_services.vnf_generic.vnf.iniparser import BaseParser
from yardstick.network_services.vnf_generic.vnf.iniparser import ConfigParser
@@ -38,16 +39,18 @@ key1=value1
list1: value2
value3
value4
-key2="double quote value"
key3='single quote value' ; comment here
key4=
-[section2]
+[section2] ; comment with #2 other symbol
# here is a comment line
list2: value5
-key with no value
+key with no value # mixed comment ; symbols
; another comment line
key5=
+
+[section1] ; reopen a section!
+key2="double quote value"
"""
PARSE_TEXT_2 = """\
@@ -86,6 +89,17 @@ class TestParseError(unittest.TestCase):
self.assertEqual(str(error), "at line 2, a: 'c'")
+class TestLineParser(unittest.TestCase):
+
+ def test___repr__(self):
+ line_parser = LineParser('', 101)
+ self.assertIsNotNone(repr(line_parser))
+
+ def test_error_invalid_assignment(self):
+ line_parser = LineParser('', 101)
+ self.assertIsNotNone(line_parser.error_invalid_assignment())
+
+
class TestBaseParser(unittest.TestCase):
@staticmethod
@@ -96,23 +110,26 @@ class TestBaseParser(unittest.TestCase):
return internal_open
- @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open')
- def test_parse_none(self, mock_open):
- mock_open.side_effect = self.make_open('')
-
+ def test_parse(self):
parser = BaseParser()
+ parser.parse()
- parser.parse([])
+ def test_parse_empty_string(self):
+ parser = BaseParser()
+ self.assertIsNone(parser.parse(''))
def test_not_implemented_methods(self):
parser = BaseParser()
with self.assertRaises(NotImplementedError):
- parser.assignment('key', 'value')
+ parser.assignment('key', 'value', LineParser('', 100))
with self.assertRaises(NotImplementedError):
parser.new_section('section')
+ with self.assertRaises(NotImplementedError):
+ parser.comment('comment')
+
class TestConfigParser(unittest.TestCase):
@@ -128,18 +145,25 @@ 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', [])
+ existing_data = [['section0', [['key0', 'value0']]]]
+ config_parser = ConfigParser('my_file', existing_data)
config_parser.parse()
expected = [
[
+ 'section0',
+ [
+ ['key0', 'value0'],
+ ],
+ ],
+ [
'section1',
[
['key1', 'value1'],
['list1', 'value2\nvalue3\nvalue4'],
- ['key2', 'double quote value'],
['key3', 'single quote value'],
['key4', ''],
+ ['key2', 'double quote value'],
],
],
[
@@ -153,12 +177,16 @@ class TestConfigParser(unittest.TestCase):
]
self.assertEqual(config_parser.sections, expected)
+ self.assertIsNotNone(config_parser.find_section('section1'))
+ self.assertIsNone(config_parser.find_section('section3'))
+ self.assertEqual(config_parser.find_section_index('section1'), 1)
+ self.assertEqual(config_parser.find_section_index('section3'), -1)
@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 = [
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
index 0264facf5..983c21e61 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
@@ -186,6 +186,7 @@ class TestVnfSshHelper(unittest.TestCase):
@mock.patch('yardstick.ssh.paramiko')
def test_upload_config_file(self, mock_paramiko):
ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path')
+ ssh_helper._run = mock.MagicMock()
self.assertFalse(ssh_helper.is_connected)
cfg_file = ssh_helper.upload_config_file('my/prefix', 'my content')
@@ -227,6 +228,7 @@ class TestVnfSshHelper(unittest.TestCase):
@mock.patch('yardstick.ssh.provision_tool')
def test_provision_tool(self, mock_provision_tool, mock_paramiko):
ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path')
+ ssh_helper._run = mock.MagicMock()
self.assertFalse(ssh_helper.is_connected)
ssh_helper.provision_tool()
@@ -412,6 +414,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'virtual-interface': {
'dst_mac': '00:00:00:00:00:03',
'vpci': '0000:05:00.0',
+ 'dpdk_port_num': '0',
'driver': 'i40e',
'local_ip': '152.16.100.19',
'type': 'PCI-PASSTHROUGH',
@@ -419,7 +422,9 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'dpdk_port_num': '0',
'bandwidth': '10 Gbps',
'dst_ip': '152.16.100.20',
- 'local_mac': '00:00:00:00:00:01'
+ 'local_mac': '00:00:00:00:00:01',
+ 'vld_id': 'private_0',
+ 'ifname': 'xe0',
},
'vnfd-connection-point-ref': 'xe0',
'name': 'xe0'
@@ -428,6 +433,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'virtual-interface': {
'dst_mac': '00:00:00:00:00:04',
'vpci': '0000:05:00.1',
+ 'dpdk_port_num': '1',
'driver': 'ixgbe',
'local_ip': '152.16.40.19',
'type': 'PCI-PASSTHROUGH',
@@ -435,7 +441,9 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
'dpdk_port_num': '1',
'bandwidth': '10 Gbps',
'dst_ip': '152.16.40.20',
- 'local_mac': '00:00:00:00:00:02'
+ 'local_mac': '00:00:00:00:00:02',
+ 'vld_id': 'public_0',
+ 'ifname': 'xe1',
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'
@@ -600,8 +608,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
dpdk_setup_helper.CFG_CONFIG = 'config'
dpdk_setup_helper.CFG_SCRIPT = 'script'
- dpdk_setup_helper.all_ports = [3, 4, 5]
dpdk_setup_helper.pipeline_kwargs = {}
+ dpdk_setup_helper.all_ports = [0, 1, 2]
expected = {
'cfg_file': 'config',