Parse alias from domain hostdev

In I16e7df6932bb7dff243706ee49338ba6b3782085 we missed that
LibvirtConfigGuestHostdevPCI is not a child class of
LibvirtConfigGuestInterface and therefore we missed parsing out the
alias field from the domain xml for hostdevs. The new libvirt driver
device detach logic[1] uses the alias as the identifier towards libvirt
so now hostdevs cannot be detached. This patch parses out the alias
field to fix the issue.

Closes-Bug: #1942345
Related-Bug: #1882521

[1] https://review.opendev.org/q/topic:bug/1882521

Change-Id: I30d30a772475cb82d0fd088f14a54a35646bd1dc
This commit is contained in:
Balazs Gibizer 2021-09-01 17:32:56 +02:00
parent e81211318a
commit b67b928c38
3 changed files with 33 additions and 3 deletions

View File

@ -1604,6 +1604,24 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigBaseTest):
self.assertEqual(obj.mode, 'subsystem')
self.assertEqual(obj.type, 'usb')
def test_config_alias_parse(self):
xml = """
<hostdev mode='subsystem' type='pci' managed='yes'>
<driver name='vfio'/>
<source>
<address domain='0x0000' bus='0x81' slot='0x00'
function='0x1'/>
</source>
<alias name='hostdev1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05'
function='0x0'/>
</hostdev>"""
xmldoc = etree.fromstring(xml)
obj = config.LibvirtConfigGuestHostdevPCI()
obj.parse_dom(xmldoc)
self.assertEqual('hostdev1', obj.alias)
class LibvirtConfigGuestHostdevMDEV(LibvirtConfigBaseTest):

View File

@ -23612,15 +23612,23 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
# check that the internal event handling is cleaned up
self.assertEqual(set(), drvr._device_event_handler._waiters)
@ddt.data(power_state.RUNNING, power_state.PAUSED)
def test__detach_with_retry_live_success(self, state):
@ddt.unpack
@ddt.data(
(power_state.RUNNING, vconfig.LibvirtConfigGuestDisk()),
(power_state.RUNNING, vconfig.LibvirtConfigGuestInterface()),
(power_state.RUNNING, vconfig.LibvirtConfigGuestHostdevPCI()),
(power_state.PAUSED, vconfig.LibvirtConfigGuestDisk()),
(power_state.PAUSED, vconfig.LibvirtConfigGuestInterface()),
(power_state.PAUSED, vconfig.LibvirtConfigGuestHostdevPCI()),
)
def test__detach_with_retry_live_success(self, state, device_class):
"""Test detach only from the live domain"""
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
mock_guest = mock.Mock(spec=libvirt_guest.Guest)
mock_guest.get_power_state.return_value = state
mock_guest.has_persistent_configuration.return_value = False
mock_dev = mock.Mock(spec=vconfig.LibvirtConfigGuestDisk)
mock_dev = mock.Mock(spec_set=device_class)
mock_dev.alias = 'virtio-disk1'
mock_get_device_conf_func = mock.Mock(

View File

@ -2204,6 +2204,8 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev):
self.slot = None
self.function = None
self.alias = None
def __eq__(self, other):
if not isinstance(other, LibvirtConfigGuestHostdevPCI):
return False
@ -2243,6 +2245,8 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev):
self.bus = sub.get('bus')
self.slot = sub.get('slot')
self.function = sub.get('function')
elif c.tag == 'alias':
self.alias = c.get('name')
class LibvirtConfigGuestHostdevMDEV(LibvirtConfigGuestHostdev):