diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py index dea0f540..5b10a159 100644 --- a/os_net_config/tests/test_utils.py +++ b/os_net_config/tests/test_utils.py @@ -792,12 +792,6 @@ class TestUtils(base.TestCase): def test_get_stored_pci_address(ifname, noop): 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('os_net_config.utils.get_stored_pci_address', test_get_stored_pci_address) @@ -817,19 +811,16 @@ class TestUtils(base.TestCase): self.assertEqual(utils.get_dpdk_devargs(nic, False), '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) + os.makedirs(os.path.join(nic_path, 'device', 'physfn')) 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 + # Check if devargs is derived, when the operstate is down + os.rmdir(os.path.join(nic_path, 'device', 'physfn')) 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) + self.assertEqual(utils.get_dpdk_devargs(nic, False), + '0000:00:19.0') # now testing the Mellanox CX3 with open(os.path.join(nic_path, 'device', 'device'), 'w') as f: diff --git a/os_net_config/utils.py b/os_net_config/utils.py index 7515d8ed..81bbe9bb 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -323,7 +323,7 @@ def get_dpdk_devargs(ifname, noop): if not noop: vendor_id = common.get_vendor_id(ifname) device_id = common.get_device_id(ifname) - if vendor_id == "0x15b3": + if vendor_id == common.MLNX_VENDOR_ID: logger.info("Getting devargs for Mellanox cards") if device_id == "0x1007": # Some NICs (i.e. Mellanox ConnectX-3) have only one PCI @@ -331,18 +331,12 @@ def get_dpdk_devargs(ifname, noop): # device won’t work. Instead, we should use # "class=eth,mac=" dpdk_devargs = f"class=eth,mac={common.interface_mac(ifname)}" - elif is_active_nic(ifname): - # Other Mellanox devices are active and they are not stored - # in dpdk_mapping.yaml file, so we need to get their pci - # address with ethtool. - dpdk_devargs = get_pci_address(ifname, noop) - elif common.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: - msg = ("Unable to get devargs for interface %s" % ifname) - raise InvalidInterfaceException(msg) + # Get the PCI address of the devices other than CX-3. + # It includes the VFs as well. For all Other Mellanox devices + # the PCI address are not stored in dpdk_mapping.yaml file, + # so we need to get their pci address with ethtool. + dpdk_devargs = get_pci_address(ifname, noop) else: logger.info("Getting stored PCI address as devarg") dpdk_devargs = get_stored_pci_address(ifname, noop)