diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py index 5b10a159..d66f8cb2 100644 --- a/os_net_config/tests/test_utils.py +++ b/os_net_config/tests/test_utils.py @@ -838,6 +838,11 @@ class TestUtils(base.TestCase): tmpdir = tempfile.mkdtemp() self.stub_out('os_net_config.common.SYS_CLASS_NET', tmpdir) + def test_get_pci_addr(interface_name, noop): + return "0000:18:00.2" + self.stub_out('os_net_config.utils.get_pci_address', + test_get_pci_addr) + # SR-IOV PF = ens802f0 # SR-IOV VF = enp129s2 for nic in ['ens802f0', 'enp129s2']: diff --git a/os_net_config/utils.py b/os_net_config/utils.py index 81bbe9bb..bbcd4100 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -105,6 +105,19 @@ def is_real_nic(interface_name): return False +def is_representor_port_by_name(interface_name): + + is_representor_port = False + + bus_info = get_pci_address(interface_name, noop=False) + if not bus_info: + is_representor_port = True + logger.debug("nics %s pci_addr is: %s" % + (interface_name, bus_info)) + + return is_representor_port + + def _is_available_nic(interface_name, check_active=True): try: if interface_name == 'lo': @@ -128,6 +141,12 @@ def _is_available_nic(interface_name, check_active=True): if common.is_vf_by_name(interface_name): return False + # If switchdev(offload) is enabled in a PF interface, there + # will be additional representator ports. It has to be ignored. + # Representator INTF will not have any pci_addr set + if is_representor_port_by_name(interface_name): + return False + # nic is available return True