Browse Source

Merge "catch libvirt exception when nodedev not found." into stable/ussuri

changes/90/741590/1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
a4aee1b0f9
2 changed files with 22 additions and 2 deletions
  1. +16
    -0
      nova/tests/unit/virt/libvirt/test_driver.py
  2. +6
    -2
      nova/virt/libvirt/driver.py

+ 16
- 0
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -16887,6 +16887,22 @@ class LibvirtConnTestCase(test.NoDBTestCase,
mock_get_net_name.assert_called_once_with(parent_address)
mock_dev_lookup.assert_called_once_with(dev_name)

def test_get_pcinet_info_raises(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
dev_name = "net_enp2s2_02_9a_a1_37_be_54"
parent_address = "pci_0000_04_11_7"

with mock.patch.object(pci_utils, 'get_net_name_by_vf_pci_address',
return_value=dev_name) as mock_get_net_name, \
mock.patch.object(
drvr._host, 'device_lookup_by_name',
side_effect=fakelibvirt.libvirtError("message")
) as mock_dev_lookup:
actualvf = drvr._get_pcinet_info(parent_address)
self.assertIsNone(actualvf)
mock_get_net_name.assert_called_once_with(parent_address)
mock_dev_lookup.assert_called_once_with(dev_name)

@mock.patch.object(pci_utils, 'get_ifname_by_pci_address')
def test_get_pcidev_info_non_nic(self, mock_get_ifname):
self.stub_out('nova.virt.libvirt.host.Host.device_lookup_by_name',


+ 6
- 2
nova/virt/libvirt/driver.py View File

@@ -6915,9 +6915,13 @@ class LibvirtDriver(driver.ComputeDriver):
"""Returns a dict of NET device."""
devname = pci_utils.get_net_name_by_vf_pci_address(vf_address)
if not devname:
return
return None

virtdev = self._host.device_lookup_by_name(devname)
try:
virtdev = self._host.device_lookup_by_name(devname)
except libvirt.libvirtError as ex:
LOG.warning(ex)
return None
xmlstr = virtdev.XMLDesc(0)
cfgdev = vconfig.LibvirtConfigNodeDevice()
cfgdev.parse_str(xmlstr)


Loading…
Cancel
Save