Skip to content

Commit 0cd4ef2

Browse files
author
Balazs Gibizer
committed
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 (cherry picked from commit b67b928)
1 parent e39bbdc commit 0cd4ef2

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,24 @@ def test_parse_guest_hosdev_usb(self):
16041604
self.assertEqual(obj.mode, 'subsystem')
16051605
self.assertEqual(obj.type, 'usb')
16061606

1607+
def test_config_alias_parse(self):
1608+
xml = """
1609+
<hostdev mode='subsystem' type='pci' managed='yes'>
1610+
<driver name='vfio'/>
1611+
<source>
1612+
<address domain='0x0000' bus='0x81' slot='0x00'
1613+
function='0x1'/>
1614+
</source>
1615+
<alias name='hostdev1'/>
1616+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05'
1617+
function='0x0'/>
1618+
</hostdev>"""
1619+
1620+
xmldoc = etree.fromstring(xml)
1621+
obj = config.LibvirtConfigGuestHostdevPCI()
1622+
obj.parse_dom(xmldoc)
1623+
self.assertEqual('hostdev1', obj.alias)
1624+
16071625

16081626
class LibvirtConfigGuestHostdevMDEV(LibvirtConfigBaseTest):
16091627

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23433,15 +23433,23 @@ def test__detach_with_retry_persistent_success(self):
2343323433
# check that the internal event handling is cleaned up
2343423434
self.assertEqual(set(), drvr._device_event_handler._waiters)
2343523435

23436-
@ddt.data(power_state.RUNNING, power_state.PAUSED)
23437-
def test__detach_with_retry_live_success(self, state):
23436+
@ddt.unpack
23437+
@ddt.data(
23438+
(power_state.RUNNING, vconfig.LibvirtConfigGuestDisk()),
23439+
(power_state.RUNNING, vconfig.LibvirtConfigGuestInterface()),
23440+
(power_state.RUNNING, vconfig.LibvirtConfigGuestHostdevPCI()),
23441+
(power_state.PAUSED, vconfig.LibvirtConfigGuestDisk()),
23442+
(power_state.PAUSED, vconfig.LibvirtConfigGuestInterface()),
23443+
(power_state.PAUSED, vconfig.LibvirtConfigGuestHostdevPCI()),
23444+
)
23445+
def test__detach_with_retry_live_success(self, state, device_class):
2343823446
"""Test detach only from the live domain"""
2343923447
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
2344023448
mock_guest = mock.Mock(spec=libvirt_guest.Guest)
2344123449
mock_guest.get_power_state.return_value = state
2344223450
mock_guest.has_persistent_configuration.return_value = False
2344323451

23444-
mock_dev = mock.Mock(spec=vconfig.LibvirtConfigGuestDisk)
23452+
mock_dev = mock.Mock(spec_set=device_class)
2344523453
mock_dev.alias = 'virtio-disk1'
2344623454

2344723455
mock_get_device_conf_func = mock.Mock(

nova/virt/libvirt/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,8 @@ def __init__(self, **kwargs):
22042204
self.slot = None
22052205
self.function = None
22062206

2207+
self.alias = None
2208+
22072209
def __eq__(self, other):
22082210
if not isinstance(other, LibvirtConfigGuestHostdevPCI):
22092211
return False
@@ -2243,6 +2245,8 @@ def parse_dom(self, xmldoc):
22432245
self.bus = sub.get('bus')
22442246
self.slot = sub.get('slot')
22452247
self.function = sub.get('function')
2248+
elif c.tag == 'alias':
2249+
self.alias = c.get('name')
22462250

22472251

22482252
class LibvirtConfigGuestHostdevMDEV(LibvirtConfigGuestHostdev):

0 commit comments

Comments
 (0)