Skip to content

Commit af80c3f

Browse files
committed
catch libvirt exception when nodedev not found.
This is a minimal fix to workaround instance where libvirt retruns stale data due to internal caching. In some cases libivrt can return stale data vai the nodedev api when the mac adress of an interface such as an sriov virtual function canages, i.e. when a mac adress is reset after a vm with a virtual funciton is migrated. Change-Id: Ic5e60c8e28263365fad5867e483b6ad55cee7281 Partial-Bug: #1883671
1 parent 2a0cc70 commit af80c3f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16884,6 +16884,22 @@ def test_get_pcinet_info(self):
1688416884
mock_get_net_name.assert_called_once_with(parent_address)
1688516885
mock_dev_lookup.assert_called_once_with(dev_name)
1688616886

16887+
def test_get_pcinet_info_raises(self):
16888+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
16889+
dev_name = "net_enp2s2_02_9a_a1_37_be_54"
16890+
parent_address = "pci_0000_04_11_7"
16891+
16892+
with mock.patch.object(pci_utils, 'get_net_name_by_vf_pci_address',
16893+
return_value=dev_name) as mock_get_net_name, \
16894+
mock.patch.object(
16895+
drvr._host, 'device_lookup_by_name',
16896+
side_effect=fakelibvirt.libvirtError("message")
16897+
) as mock_dev_lookup:
16898+
actualvf = drvr._get_pcinet_info(parent_address)
16899+
self.assertIsNone(actualvf)
16900+
mock_get_net_name.assert_called_once_with(parent_address)
16901+
mock_dev_lookup.assert_called_once_with(dev_name)
16902+
1688716903
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address')
1688816904
def test_get_pcidev_info_non_nic(self, mock_get_ifname):
1688916905
self.stub_out('nova.virt.libvirt.host.Host.device_lookup_by_name',

nova/virt/libvirt/driver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,9 +6894,13 @@ def _get_pcinet_info(self, vf_address):
68946894
"""Returns a dict of NET device."""
68956895
devname = pci_utils.get_net_name_by_vf_pci_address(vf_address)
68966896
if not devname:
6897-
return
6897+
return None
68986898

6899-
virtdev = self._host.device_lookup_by_name(devname)
6899+
try:
6900+
virtdev = self._host.device_lookup_by_name(devname)
6901+
except libvirt.libvirtError as ex:
6902+
LOG.warning(ex)
6903+
return None
69006904
xmlstr = virtdev.XMLDesc(0)
69016905
cfgdev = vconfig.LibvirtConfigNodeDevice()
69026906
cfgdev.parse_str(xmlstr)

0 commit comments

Comments
 (0)