diff options
Diffstat (limited to 'os_net_config/tests')
-rw-r--r-- | os_net_config/tests/test_impl_eni.py | 31 | ||||
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 31 | ||||
-rw-r--r-- | os_net_config/tests/test_objects.py | 16 | ||||
-rw-r--r-- | os_net_config/tests/test_utils.py | 34 |
4 files changed, 109 insertions, 3 deletions
diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py index 4911cb9..51354f8 100644 --- a/os_net_config/tests/test_impl_eni.py +++ b/os_net_config/tests/test_impl_eni.py @@ -18,6 +18,7 @@ import tempfile from oslo_concurrency import processutils +import os_net_config from os_net_config import impl_eni from os_net_config import objects from os_net_config.tests import base @@ -360,3 +361,33 @@ class TestENINetConfigApply(base.TestCase): self.assertEqual((_OVS_BRIDGE_DHCP + _OVS_PORT_IFACE), iface_data) self.assertIn('eth0', self.ifup_interface_names) self.assertIn('br0', self.ifup_interface_names) + + def _failed_execute(*args, **kwargs): + if kwargs.get('check_exit_code', True): + raise processutils.ProcessExecutionError('Test stderr', + 'Test stdout', + str(kwargs)) + + def test_interface_failure(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + self.provider.add_interface(interface) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + self.assertEqual(1, len(self.provider.errors)) + + def test_interface_failure_multiple(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + v4_addr2 = objects.Address('192.168.2.2/24') + interface2 = objects.Interface('em2', addresses=[v4_addr2]) + self.provider.add_interface(interface) + self.provider.add_interface(interface2) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + # Even though the first one failed, we should have attempted both + self.assertEqual(2, len(self.provider.errors)) diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index 82ca116..fcf2d15 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -19,6 +19,7 @@ import tempfile from oslo_concurrency import processutils +import os_net_config from os_net_config import impl_ifcfg from os_net_config import NetConfig from os_net_config import objects @@ -1230,3 +1231,33 @@ class TestIfcfgNetConfigApply(base.TestCase): self.provider.add_interface(interface) self.provider.apply() self.assertNotIn('Restart openvswitch', execute_strings) + + def _failed_execute(*args, **kwargs): + if kwargs.get('check_exit_code', True): + raise processutils.ProcessExecutionError('Test stderr', + 'Test stdout', + str(kwargs)) + + def test_interface_failure(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + self.provider.add_interface(interface) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + self.assertEqual(1, len(self.provider.errors)) + + def test_interface_failure_multiple(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + v4_addr2 = objects.Address('192.168.2.2/24') + interface2 = objects.Interface('em2', addresses=[v4_addr2]) + self.provider.add_interface(interface) + self.provider.add_interface(interface2) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + # Even though the first one failed, we should have attempted both + self.assertEqual(2, len(self.provider.errors)) diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index 438deef..b29bae4 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -993,3 +993,19 @@ class TestOvsDpdkBond(base.TestCase): self.assertEqual("vfio-pci", dpdk_port1.driver) iface2 = dpdk_port1.members[0] self.assertEqual("eth2", iface2.name) + + +class TestVppInterface(base.TestCase): + def test_vpp_interface_from_json(self): + data = """{ +"type": "vpp_interface", +"name": "em1", +"uio_driver": "uio_pci_generic", +"options": "vlan-strip-offload off" +} +""" + + vpp_interface = objects.object_from_json(json.loads(data)) + self.assertEqual("em1", vpp_interface.name) + self.assertEqual("uio_pci_generic", vpp_interface.uio_driver) + self.assertEqual("vlan-strip-offload off", vpp_interface.options) diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py index 9e516b6..8a78946 100644 --- a/os_net_config/tests/test_utils.py +++ b/os_net_config/tests/test_utils.py @@ -21,6 +21,7 @@ import shutil import tempfile import yaml +from os_net_config import objects from os_net_config.tests import base from os_net_config import utils @@ -38,6 +39,33 @@ supports-register-dump: yes supports-priv-flags: no ''' +_VPPCTL_OUTPUT = ''' + Name Idx State Counter Count +GigabitEthernet0/9/0 1 down +local0 0 down + +''' + +_INITIAL_VPP_CONFIG = ''' +unix { + nodaemon + log /tmp/vpp.log + full-coredump +} + + +api-trace { + on +} + +api-segment { + gid vpp +} + +dpdk { +} +''' + class TestUtils(base.TestCase): @@ -83,7 +111,7 @@ class TestUtils(base.TestCase): out = _PCI_OUTPUT return out, None self.stubs.Set(processutils, 'execute', test_execute) - pci = utils._get_pci_address('nic2', False) + pci = utils.get_pci_address('nic2', False) self.assertEqual('0000:00:19.0', pci) def test_get_pci_address_exception(self): @@ -91,7 +119,7 @@ class TestUtils(base.TestCase): if 'ethtool' in name: raise processutils.ProcessExecutionError self.stubs.Set(processutils, 'execute', test_execute) - pci = utils._get_pci_address('nic2', False) + pci = utils.get_pci_address('nic2', False) self.assertEqual(None, pci) def test_get_pci_address_error(self): @@ -99,7 +127,7 @@ class TestUtils(base.TestCase): if 'ethtool' in name: return None, 'Error' self.stubs.Set(processutils, 'execute', test_execute) - pci = utils._get_pci_address('nic2', False) + pci = utils.get_pci_address('nic2', False) self.assertEqual(None, pci) def test_bind_dpdk_interfaces(self): |