Merge "libvirt: Ignore LibvirtConfigObject kwargs"

This commit is contained in:
Zuul 2022-07-19 11:27:26 +00:00 committed by Gerrit Code Review
commit 9d8a8d8ed8
3 changed files with 47 additions and 24 deletions

View File

@ -1535,7 +1535,10 @@ class LibvirtConfigGuestGraphicsTest(LibvirtConfigBaseTest):
class LibvirtConfigGuestHostdev(LibvirtConfigBaseTest): class LibvirtConfigGuestHostdev(LibvirtConfigBaseTest):
def test_config_pci_guest_host_dev(self): def test_config_pci_guest_host_dev(self):
obj = config.LibvirtConfigGuestHostdev(mode='subsystem', type='pci') obj = config.LibvirtConfigGuestHostdev()
obj.mode = 'subsystem'
obj.type = 'pci'
xml = obj.to_xml() xml = obj.to_xml()
expected = """ expected = """
<hostdev mode="subsystem" type="pci" managed="yes"/> <hostdev mode="subsystem" type="pci" managed="yes"/>
@ -3949,8 +3952,10 @@ class LibvirtConfigSecretTest(LibvirtConfigBaseTest):
class LibvirtConfigGuestVPMEMTest(LibvirtConfigBaseTest): class LibvirtConfigGuestVPMEMTest(LibvirtConfigBaseTest):
def test_config_vpmem(self): def test_config_vpmem(self):
obj = config.LibvirtConfigGuestVPMEM( obj = config.LibvirtConfigGuestVPMEM()
devpath='/dev/dax0.0', size_kb=4096 * units.Ki, align_kb=2048) obj.source_path = '/dev/dax0.0'
obj.target_size = 4096 * units.Ki
obj.align_size = 2048
xml = obj.to_xml() xml = obj.to_xml()
self.assertXmlEqual(xml, """ self.assertXmlEqual(xml, """

View File

@ -45,9 +45,12 @@ class LibvirtConfigObject(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigObject, self).__init__() super(LibvirtConfigObject, self).__init__()
self.root_name = kwargs.get("root_name") self.root_name = kwargs.pop("root_name")
self.ns_prefix = kwargs.get('ns_prefix') self.ns_prefix = kwargs.pop("ns_prefix", None)
self.ns_uri = kwargs.get('ns_uri') self.ns_uri = kwargs.pop("ns_uri", None)
# handle programmer error
assert not kwargs
def _new_node(self, node_name, **kwargs): def _new_node(self, node_name, **kwargs):
if self.ns_uri is None: if self.ns_uri is None:
@ -1532,7 +1535,8 @@ class LibvirtConfigGuestFilesys(LibvirtConfigGuestDevice):
class LibvirtConfigGuestDiskEncryptionSecret(LibvirtConfigObject): class LibvirtConfigGuestDiskEncryptionSecret(LibvirtConfigObject):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestDiskEncryptionSecret, self).__init__(**kwargs) super(LibvirtConfigGuestDiskEncryptionSecret, self).__init__(
root_name='diskencryptionsecret', **kwargs)
self.type = None self.type = None
self.uuid = None self.uuid = None
@ -1552,7 +1556,8 @@ class LibvirtConfigGuestDiskEncryption(LibvirtConfigObject):
""" """
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestDiskEncryption, self).__init__(**kwargs) super(LibvirtConfigGuestDiskEncryption, self).__init__(
root_name='diskencryption', **kwargs)
self.format = None self.format = None
self.secret = None self.secret = None
@ -1575,7 +1580,8 @@ class LibvirtConfigGuestDiskEncryption(LibvirtConfigObject):
class LibvirtConfigGuestDiskMirror(LibvirtConfigObject): class LibvirtConfigGuestDiskMirror(LibvirtConfigObject):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestDiskMirror, self).__init__(**kwargs) super(LibvirtConfigGuestDiskMirror, self).__init__(
root_name='diskmirror', **kwargs)
self.ready = None self.ready = None
def parse_dom(self, xmldoc): def parse_dom(self, xmldoc):
@ -1585,6 +1591,8 @@ class LibvirtConfigGuestDiskMirror(LibvirtConfigObject):
class LibvirtConfigGuestIDMap(LibvirtConfigObject): class LibvirtConfigGuestIDMap(LibvirtConfigObject):
def __init__(self, **kwargs): def __init__(self, **kwargs):
if 'root_name' not in kwargs:
kwargs['root_name'] = 'id'
super(LibvirtConfigGuestIDMap, self).__init__(**kwargs) super(LibvirtConfigGuestIDMap, self).__init__(**kwargs)
self.start = 0 self.start = 0
self.target = 0 self.target = 0
@ -2168,13 +2176,14 @@ class LibvirtConfigGuestPCIeRootPortController(LibvirtConfigGuestController):
class LibvirtConfigGuestHostdev(LibvirtConfigGuestDevice): class LibvirtConfigGuestHostdev(LibvirtConfigGuestDevice):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestHostdev, self).\ super(LibvirtConfigGuestHostdev, self).__init__(
__init__(root_name="hostdev", **kwargs) root_name="hostdev", **kwargs,
self.mode = kwargs.get('mode') )
self.type = kwargs.get('type') self.mode = None
self.type = None
# managed attribute is only used by PCI devices but mediated devices # managed attribute is only used by PCI devices but mediated devices
# need to say managed=no # need to say managed=no
self.managed = kwargs.get('managed', 'yes') self.managed = "yes"
def format_dom(self): def format_dom(self):
dev = super(LibvirtConfigGuestHostdev, self).format_dom() dev = super(LibvirtConfigGuestHostdev, self).format_dom()
@ -2194,8 +2203,11 @@ class LibvirtConfigGuestHostdev(LibvirtConfigGuestDevice):
class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev): class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestHostdevPCI, self).\ super(LibvirtConfigGuestHostdevPCI, self).\
__init__(mode='subsystem', type='pci', __init__(**kwargs)
**kwargs)
self.mode = 'subsystem'
self.type = 'pci'
# These are returned from libvirt as hexadecimal strings with 0x prefix # These are returned from libvirt as hexadecimal strings with 0x prefix
# even if they have a different meaningful range: domain 16 bit, # even if they have a different meaningful range: domain 16 bit,
# bus 8 bit, slot 5 bit, and function 3 bit # bus 8 bit, slot 5 bit, and function 3 bit
@ -2252,10 +2264,14 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev):
class LibvirtConfigGuestHostdevMDEV(LibvirtConfigGuestHostdev): class LibvirtConfigGuestHostdevMDEV(LibvirtConfigGuestHostdev):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(LibvirtConfigGuestHostdevMDEV, self).__init__( super(LibvirtConfigGuestHostdevMDEV, self).__init__(**kwargs)
mode='subsystem', type='mdev', managed='no', **kwargs)
self.mode = 'subsystem'
self.type = 'mdev'
self.managed = 'no'
# model attribute is only supported by mediated devices # model attribute is only supported by mediated devices
self.model = kwargs.get('model', 'vfio-pci') self.model = 'vfio-pci'
self.uuid = None self.uuid = None
def format_dom(self): def format_dom(self):
@ -3585,11 +3601,11 @@ class LibvirtConfigGuestVPMEM(LibvirtConfigGuestDevice):
self.model = "nvdimm" self.model = "nvdimm"
self.access = "shared" self.access = "shared"
self.source_path = kwargs.get("devpath", "") self.source_path = ""
self.align_size = kwargs.get("align_kb", 0) self.align_size = 0
self.pmem = True self.pmem = True
self.target_size = kwargs.get("size_kb", 0) self.target_size = 0
self.target_node = 0 self.target_node = 0
self.label_size = 2 * units.Ki self.label_size = 2 * units.Ki

View File

@ -7013,8 +7013,10 @@ class LibvirtDriver(driver.ComputeDriver):
size_kb = vpmem.size // units.Ki size_kb = vpmem.size // units.Ki
align_kb = vpmem.align // units.Ki align_kb = vpmem.align // units.Ki
vpmem_config = vconfig.LibvirtConfigGuestVPMEM( vpmem_config = vconfig.LibvirtConfigGuestVPMEM()
devpath=vpmem.devpath, size_kb=size_kb, align_kb=align_kb) vpmem_config.source_path = vpmem.devpath
vpmem_config.target_size = size_kb
vpmem_config.align_size = align_kb
# max memory size needs contain vpmem size # max memory size needs contain vpmem size
guest.max_memory_size += size_kb guest.max_memory_size += size_kb