aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/tests
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config/tests')
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py38
-rw-r--r--os_net_config/tests/test_utils.py72
2 files changed, 104 insertions, 6 deletions
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 3a56f4d..d41cf60 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -413,6 +413,14 @@ class TestIfcfgNetConfig(base.TestCase):
def get_route6_config(self, name='em1'):
return self.provider.route6_data.get(name, '')
+ def stub_get_stored_pci_address(self, ifname, noop):
+ if 'eth0' in ifname:
+ return "0000:00:07.0"
+ if 'eth1' in ifname:
+ return "0000:00:08.0"
+ if 'eth2' in ifname:
+ return "0000:00:09.0"
+
def test_add_base_interface(self):
interface = objects.Interface('em1')
self.provider.add_interface(interface)
@@ -894,6 +902,8 @@ DNS2=5.6.7.8
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_port(dpdk_port)
self.provider.add_ovs_user_bridge(bridge)
@@ -915,6 +925,7 @@ PEERDNS=no
DEVICETYPE=ovs
TYPE=OVSDPDKPort
OVS_BRIDGE=br-link
+OVS_EXTRA="set Interface $DEVICE options:dpdk-devargs=0000:00:09.0"
"""
self.assertEqual(br_link_config,
self.provider.bridge_data['br-link'])
@@ -934,6 +945,8 @@ OVS_BRIDGE=br-link
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_port(dpdk_port)
self.provider.add_ovs_user_bridge(bridge)
@@ -957,7 +970,8 @@ TYPE=OVSDPDKPort
OVS_BRIDGE=br-link
RX_QUEUE=4
MTU=9000
-OVS_EXTRA="set Interface $DEVICE mtu_request=$MTU \
+OVS_EXTRA="set Interface $DEVICE options:dpdk-devargs=0000:00:09.0 \
+-- set Interface $DEVICE mtu_request=$MTU \
-- set Interface $DEVICE options:n_rxq=$RX_QUEUE"
"""
self.assertEqual(br_link_config,
@@ -980,6 +994,8 @@ OVS_EXTRA="set Interface $DEVICE mtu_request=$MTU \
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_bond(bond)
self.provider.add_ovs_user_bridge(bridge)
@@ -994,6 +1010,8 @@ DEVICETYPE=ovs
TYPE=OVSDPDKBond
OVS_BRIDGE=br-link
BOND_IFACES="dpdk0 dpdk1"
+OVS_EXTRA="set Interface dpdk0 options:dpdk-devargs=0000:00:08.0 \
+-- set Interface dpdk1 options:dpdk-devargs=0000:00:09.0"
"""
self.assertEqual(dpdk_bond_config,
self.get_interface_config('dpdkbond0'))
@@ -1015,6 +1033,8 @@ BOND_IFACES="dpdk0 dpdk1"
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_bond(bond)
self.provider.add_ovs_user_bridge(bridge)
@@ -1030,7 +1050,9 @@ TYPE=OVSDPDKBond
OVS_BRIDGE=br-link
BOND_IFACES="dpdk0 dpdk1"
MTU=9000
-OVS_EXTRA="set Interface dpdk0 mtu_request=$MTU \
+OVS_EXTRA="set Interface dpdk0 options:dpdk-devargs=0000:00:08.0 \
+-- set Interface dpdk1 options:dpdk-devargs=0000:00:09.0 \
+-- set Interface dpdk0 mtu_request=$MTU \
-- set Interface dpdk1 mtu_request=$MTU"
"""
self.assertEqual(dpdk_bond_config,
@@ -1053,6 +1075,8 @@ OVS_EXTRA="set Interface dpdk0 mtu_request=$MTU \
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_bond(bond)
self.provider.add_ovs_user_bridge(bridge)
@@ -1068,7 +1092,9 @@ TYPE=OVSDPDKBond
OVS_BRIDGE=br-link
BOND_IFACES="dpdk0 dpdk1"
RX_QUEUE=4
-OVS_EXTRA="set Interface dpdk0 options:n_rxq=$RX_QUEUE \
+OVS_EXTRA="set Interface dpdk0 options:dpdk-devargs=0000:00:08.0 \
+-- set Interface dpdk1 options:dpdk-devargs=0000:00:09.0 \
+-- set Interface dpdk0 options:n_rxq=$RX_QUEUE \
-- set Interface dpdk1 options:n_rxq=$RX_QUEUE"
"""
self.assertEqual(dpdk_bond_config,
@@ -1091,6 +1117,8 @@ OVS_EXTRA="set Interface dpdk0 options:n_rxq=$RX_QUEUE \
self.assertEqual(driver, 'vfio-pci')
self.stubs.Set(utils, 'bind_dpdk_interfaces',
test_bind_dpdk_interfaces)
+ self.stubs.Set(utils, 'get_stored_pci_address',
+ self.stub_get_stored_pci_address)
self.provider.add_ovs_dpdk_bond(bond)
self.provider.add_ovs_user_bridge(bridge)
@@ -1107,7 +1135,9 @@ OVS_BRIDGE=br-link
BOND_IFACES="dpdk0 dpdk1"
RX_QUEUE=4
MTU=9000
-OVS_EXTRA="set Interface dpdk0 mtu_request=$MTU \
+OVS_EXTRA="set Interface dpdk0 options:dpdk-devargs=0000:00:08.0 \
+-- set Interface dpdk1 options:dpdk-devargs=0000:00:09.0 \
+-- set Interface dpdk0 mtu_request=$MTU \
-- set Interface dpdk1 mtu_request=$MTU \
-- set Interface dpdk0 options:n_rxq=$RX_QUEUE \
-- set Interface dpdk1 options:n_rxq=$RX_QUEUE"
diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py
index dcd6045..e09b6f7 100644
--- a/os_net_config/tests/test_utils.py
+++ b/os_net_config/tests/test_utils.py
@@ -130,6 +130,24 @@ class TestUtils(base.TestCase):
pci = utils.get_pci_address('nic2', False)
self.assertEqual(None, pci)
+ def test_get_stored_pci_address_success(self):
+ def test_get_dpdk_map():
+ return [{'name': 'eth1', 'pci_address': '0000:00:09.0',
+ 'mac_address': '01:02:03:04:05:06',
+ 'driver': 'vfio-pci'}]
+
+ self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map)
+ pci = utils.get_stored_pci_address('eth1', False)
+ self.assertEqual('0000:00:09.0', pci)
+
+ def test_get_stored_pci_address_empty(self):
+ def test_get_dpdk_map():
+ return []
+
+ self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map)
+ pci = utils.get_stored_pci_address('eth1', False)
+ self.assertEqual(None, pci)
+
def test_bind_dpdk_interfaces(self):
def test_execute(name, dummy1, dummy2=None, dummy3=None):
if 'ethtool' in name:
@@ -143,8 +161,10 @@ class TestUtils(base.TestCase):
self.stubs.Set(processutils, 'execute', test_execute)
self.stubs.Set(utils, '_get_dpdk_mac_address',
test_get_dpdk_mac_address)
-
- utils.bind_dpdk_interfaces('nic2', 'vfio-pci', False)
+ try:
+ utils.bind_dpdk_interfaces('nic2', 'vfio-pci', False)
+ except utils.OvsDpdkBindException:
+ self.fail("Received OvsDpdkBindException unexpectedly")
def test_bind_dpdk_interfaces_fail(self):
def test_execute(name, dummy1, dummy2=None, dummy3=None):
@@ -164,6 +184,54 @@ class TestUtils(base.TestCase):
utils.bind_dpdk_interfaces, 'eth1', 'vfio-pci',
False)
+ def test_bind_dpdk_interfaces_skip_valid_device(self):
+ def test_execute(name, dummy1, dummy2=None, dummy3=None):
+ if 'ethtool' in name:
+ return None, 'Error'
+ if 'driverctl' in name:
+ return None, None
+
+ def test_get_dpdk_mac_address(name):
+ return '01:02:03:04:05:06'
+
+ def test_get_dpdk_map():
+ return [{'name': 'eth1', 'pci_address': '0000:00:09.0',
+ 'mac_address': '01:02:03:04:05:06',
+ 'driver': 'vfio-pci'}]
+
+ self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map)
+ self.stubs.Set(processutils, 'execute', test_execute)
+ self.stubs.Set(utils, '_get_dpdk_mac_address',
+ test_get_dpdk_mac_address)
+ try:
+ utils.bind_dpdk_interfaces('eth1', 'vfio-pci', False)
+ except utils.OvsDpdkBindException:
+ self.fail("Received OvsDpdkBindException unexpectedly")
+
+ def test_bind_dpdk_interfaces_fail_invalid_device(self):
+ def test_execute(name, dummy1, dummy2=None, dummy3=None):
+ if 'ethtool' in name:
+ return None, 'Error'
+ if 'driverctl' in name:
+ return None, None
+
+ def test_get_dpdk_mac_address(name):
+ return '01:02:03:04:05:06'
+
+ def test_get_dpdk_map():
+ return [{'name': 'eth1', 'pci_address': '0000:00:09.0',
+ 'mac_address': '01:02:03:04:05:06',
+ 'driver': 'vfio-pci'}]
+
+ self.stubs.Set(utils, '_get_dpdk_map', test_get_dpdk_map)
+ self.stubs.Set(processutils, 'execute', test_execute)
+ self.stubs.Set(utils, '_get_dpdk_mac_address',
+ test_get_dpdk_mac_address)
+
+ self.assertRaises(utils.OvsDpdkBindException,
+ utils.bind_dpdk_interfaces, 'eth2', 'vfio-pci',
+ False)
+
def test__update_dpdk_map_new(self):
utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
'vfio-pci')