Merge "Add NIC Partitioning support for Mellanox VFs"

This commit is contained in:
Zuul 2020-07-28 06:30:34 +00:00 committed by Gerrit Code Review
commit bca47783bc
2 changed files with 40 additions and 7 deletions

View File

@ -612,6 +612,12 @@ class TestUtils(base.TestCase):
def test_get_stored_pci_address(ifname, noop): def test_get_stored_pci_address(ifname, noop):
return "0000:00:07.0" return "0000:00:07.0"
def test_vf_by_name(ifname):
return True
def test_not_vf_by_name(ifname):
return False
self.stub_out('oslo_concurrency.processutils.execute', test_execute) self.stub_out('oslo_concurrency.processutils.execute', test_execute)
self.stub_out('os_net_config.utils.get_stored_pci_address', self.stub_out('os_net_config.utils.get_stored_pci_address',
test_get_stored_pci_address) test_get_stored_pci_address)
@ -630,6 +636,21 @@ class TestUtils(base.TestCase):
f.write('0x15b3') f.write('0x15b3')
self.assertEqual(utils.get_dpdk_devargs(nic, False), self.assertEqual(utils.get_dpdk_devargs(nic, False),
'0000:00:19.0') '0000:00:19.0')
# Testing VFs of Mellanox Connect-X cards
self.stub_out('os_net_config.utils._is_vf_by_name',
test_vf_by_name)
self.assertEqual(utils.get_dpdk_devargs(nic, False),
'0000:00:19.0')
# Check if exception is raised, when the operstate is down
# and not VF
with open(os.path.join(nic_path, 'operstate'), 'w') as f:
f.write('down')
self.stub_out('os_net_config.utils._is_vf_by_name',
test_not_vf_by_name)
self.assertRaises(utils.InvalidInterfaceException,
utils.get_dpdk_devargs, nic, False)
# now testing the Mellanox CX3 # now testing the Mellanox CX3
with open(os.path.join(nic_path, 'device', 'device'), 'w') as f: with open(os.path.join(nic_path, 'device', 'device'), 'w') as f:
f.write('0x1007') f.write('0x1007')

View File

@ -59,6 +59,10 @@ WantedBy=multi-user.target
_VPP_EXEC_FILE = '/etc/vpp/vpp-exec' _VPP_EXEC_FILE = '/etc/vpp/vpp-exec'
class InvalidInterfaceException(ValueError):
pass
class OvsDpdkBindException(ValueError): class OvsDpdkBindException(ValueError):
pass pass
@ -160,11 +164,13 @@ def _is_vf(pci_address):
vf_path_check = _SYS_BUS_PCI_DEV + '/%s/physfn' % pci_address vf_path_check = _SYS_BUS_PCI_DEV + '/%s/physfn' % pci_address
is_sriov_vf = os.path.isdir(vf_path_check) is_sriov_vf = os.path.isdir(vf_path_check)
if is_sriov_vf: return is_sriov_vf
return True
# nic is not VF
return False def _is_vf_by_name(interface_name):
vf_path_check = _SYS_CLASS_NET + '/%s/device/physfn' % interface_name
is_sriov_vf = os.path.isdir(vf_path_check)
return is_sriov_vf
def _is_available_nic(interface_name, check_active=True): def _is_available_nic(interface_name, check_active=True):
@ -186,9 +192,7 @@ def _is_available_nic(interface_name, check_active=True):
# the nic numbering. All the VFs will have a reference to the PF with # the nic numbering. All the VFs will have a reference to the PF with
# directory name as 'physfn', if this directory is present it should be # directory name as 'physfn', if this directory is present it should be
# ignored. # ignored.
vf_path_check = _SYS_CLASS_NET + '/%s/device/physfn' % interface_name if _is_vf_by_name(interface_name):
is_sriov_vf = os.path.isdir(vf_path_check)
if is_sriov_vf:
return False return False
# nic is available # nic is available
@ -420,6 +424,14 @@ def get_dpdk_devargs(ifname, noop):
# in dpdk_mapping.yaml file, so we need to get their pci # in dpdk_mapping.yaml file, so we need to get their pci
# address with ethtool. # address with ethtool.
dpdk_devargs = get_pci_address(ifname, noop) dpdk_devargs = get_pci_address(ifname, noop)
elif _is_vf_by_name(ifname):
# For Mellanox devices the VFs bound with DPDK shall
# be treated the same as VFs of other devices
dpdk_devargs = get_pci_address(ifname, noop)
else:
logger.error("Unable to get devargs for interface %s" % ifname)
msg = ("Unable to get devargs for interface %s" % ifname)
raise InvalidInterfaceException(msg)
else: else:
logger.info("Getting stored PCI address as devarg") logger.info("Getting stored PCI address as devarg")
dpdk_devargs = get_stored_pci_address(ifname, noop) dpdk_devargs = get_stored_pci_address(ifname, noop)