Merge "Exclude DPDK mapped VF device even if not present" into stable/train

This commit is contained in:
Zuul 2021-02-04 21:26:26 +00:00 committed by Gerrit Code Review
commit 8b6198f21a
2 changed files with 33 additions and 1 deletions

View File

@ -600,6 +600,30 @@ class TestUtils(base.TestCase):
shutil.rmtree(tmpdir)
shutil.rmtree(tmp_pci_dir)
def test_ordered_active_nics_with_dpdk_mapping_of_vf(self):
tmpdir = tempfile.mkdtemp()
self.stub_out('os_net_config.utils._SYS_CLASS_NET', tmpdir)
tmp_pci_dir = tempfile.mkdtemp()
self.stub_out('os_net_config.utils._SYS_BUS_PCI_DEV', tmp_pci_dir)
physfn_path = utils._SYS_BUS_PCI_DEV + '/0000:05:01.1/physfn'
os.makedirs(physfn_path)
def test_is_available_nic(interface_name, check_active):
return True
self.stub_out('os_net_config.utils._is_available_nic',
test_is_available_nic)
utils._update_dpdk_map('eth2_0', '0000:06:01.1', 'AA:02:03:04:05:FE',
'vfio-pci')
utils.update_sriov_vf_map('eth2', 0, 'eth2_0')
nics = utils.ordered_active_nics()
self.assertEqual(len(nics), 0)
shutil.rmtree(tmpdir)
shutil.rmtree(tmp_pci_dir)
def test_interface_mac_raises(self):
self.assertRaises(IOError, utils.interface_mac, 'ens20f2p3')

View File

@ -167,9 +167,15 @@ def _is_vf(pci_address):
return is_sriov_vf
def _is_vf_by_name(interface_name):
def _is_vf_by_name(interface_name, check_mapping_file=False):
vf_path_check = _SYS_CLASS_NET + '/%s/device/physfn' % interface_name
is_sriov_vf = os.path.isdir(vf_path_check)
if not is_sriov_vf and check_mapping_file:
sriov_map = _get_sriov_map()
for item in sriov_map:
if (item['name'] == interface_name and
item['device_type'] == 'vf'):
is_sriov_vf = True
return is_sriov_vf
@ -249,6 +255,8 @@ def _ordered_nics(check_active):
nic = item['name']
if _is_vf(item['pci_address']):
logger.info("%s is a VF, skipping it for NIC ordering" % nic)
elif _is_vf_by_name(nic, True):
logger.info("%s is a VF, skipping it for NIC ordering" % nic)
elif _is_embedded_nic(nic):
logger.info("%s is an embedded DPDK bound nic" % nic)
if nic not in embedded_nics: