libvirt: fix maxphysaddr passthrough dom parsing

If `hw:maxphysaddr_mode` is set to `passthrough`, the generated XML
doesn't contain a `bits` attribute. Our
`LibvirtConfigCPUMaxPhysAddr.parse_dom()` assumed `bits` was always set
and the tests only tested parsing the XML for the `emulate` mode.

Closes-Bug: #2099663
Change-Id: Ic16561dfb38612ac46c2148f2847006f6890940e
This commit is contained in:
Johannes Kulik
2025-02-20 16:10:11 +01:00
parent ae87118f98
commit 5f6ff008c3
2 changed files with 17 additions and 2 deletions
+15 -1
View File
@@ -547,7 +547,7 @@ class LibvirtConfigCPUTest(LibvirtConfigBaseTest):
</cpu>
""")
def test_parse_dom(self):
def test_parse_dom_emulate(self):
xml = """
<cpu>
<maxphysaddr mode='emulate' bits='42'/>
@@ -560,6 +560,20 @@ class LibvirtConfigCPUTest(LibvirtConfigBaseTest):
self.assertEqual("emulate", obj.maxphysaddr.mode)
self.assertEqual(42, obj.maxphysaddr.bits)
def test_parse_dom_passthrough(self):
"""Passthrough mode has no "bits" attribute"""
xml = """
<cpu>
<maxphysaddr mode='passthrough'/>
</cpu>
"""
xmldoc = etree.fromstring(xml)
obj = config.LibvirtConfigCPU()
obj.parse_dom(xmldoc)
self.assertEqual("passthrough", obj.maxphysaddr.mode)
self.assertIsNone(obj.maxphysaddr.bits)
class LibvirtConfigGuestCPUTest(LibvirtConfigBaseTest):
+2 -1
View File
@@ -851,7 +851,8 @@ class LibvirtConfigCPUMaxPhysAddr(LibvirtConfigObject):
super(LibvirtConfigCPUMaxPhysAddr, self).parse_dom(xmldoc)
self.mode = xmldoc.get("mode")
self.bits = int(xmldoc.get("bits"))
if xmldoc.get("bits") is not None:
self.bits = int(xmldoc.get("bits"))
def format_dom(self):
m = super(LibvirtConfigCPUMaxPhysAddr, self).format_dom()