From f708feee359491c8727354bbaec60954363df1f7 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 23 Feb 2022 16:14:12 +0000 Subject: [PATCH] libvirt: Ignore LibvirtConfigObject kwargs We were mostly ignoring these except for a few limited examples. Do it for everything. Change-Id: Id55e1a8f3559386e27c5cb6a0fde94a4a69e7ea9 Signed-off-by: Stephen Finucane --- nova/tests/unit/virt/libvirt/test_config.py | 11 +++-- nova/virt/libvirt/config.py | 54 +++++++++++++-------- nova/virt/libvirt/driver.py | 6 ++- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index 396edfd02482..1967939e5634 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -1535,7 +1535,10 @@ class LibvirtConfigGuestGraphicsTest(LibvirtConfigBaseTest): class LibvirtConfigGuestHostdev(LibvirtConfigBaseTest): 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() expected = """ @@ -3949,8 +3952,10 @@ class LibvirtConfigSecretTest(LibvirtConfigBaseTest): class LibvirtConfigGuestVPMEMTest(LibvirtConfigBaseTest): def test_config_vpmem(self): - obj = config.LibvirtConfigGuestVPMEM( - devpath='/dev/dax0.0', size_kb=4096 * units.Ki, align_kb=2048) + obj = config.LibvirtConfigGuestVPMEM() + obj.source_path = '/dev/dax0.0' + obj.target_size = 4096 * units.Ki + obj.align_size = 2048 xml = obj.to_xml() self.assertXmlEqual(xml, """ diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 1a81be3ade56..b5fbe4b094a9 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -45,9 +45,12 @@ class LibvirtConfigObject(object): def __init__(self, **kwargs): super(LibvirtConfigObject, self).__init__() - self.root_name = kwargs.get("root_name") - self.ns_prefix = kwargs.get('ns_prefix') - self.ns_uri = kwargs.get('ns_uri') + self.root_name = kwargs.pop("root_name") + self.ns_prefix = kwargs.pop("ns_prefix", None) + self.ns_uri = kwargs.pop("ns_uri", None) + + # handle programmer error + assert not kwargs def _new_node(self, node_name, **kwargs): if self.ns_uri is None: @@ -1532,7 +1535,8 @@ class LibvirtConfigGuestFilesys(LibvirtConfigGuestDevice): class LibvirtConfigGuestDiskEncryptionSecret(LibvirtConfigObject): def __init__(self, **kwargs): - super(LibvirtConfigGuestDiskEncryptionSecret, self).__init__(**kwargs) + super(LibvirtConfigGuestDiskEncryptionSecret, self).__init__( + root_name='diskencryptionsecret', **kwargs) self.type = None self.uuid = None @@ -1552,7 +1556,8 @@ class LibvirtConfigGuestDiskEncryption(LibvirtConfigObject): """ def __init__(self, **kwargs): - super(LibvirtConfigGuestDiskEncryption, self).__init__(**kwargs) + super(LibvirtConfigGuestDiskEncryption, self).__init__( + root_name='diskencryption', **kwargs) self.format = None self.secret = None @@ -1575,7 +1580,8 @@ class LibvirtConfigGuestDiskEncryption(LibvirtConfigObject): class LibvirtConfigGuestDiskMirror(LibvirtConfigObject): def __init__(self, **kwargs): - super(LibvirtConfigGuestDiskMirror, self).__init__(**kwargs) + super(LibvirtConfigGuestDiskMirror, self).__init__( + root_name='diskmirror', **kwargs) self.ready = None def parse_dom(self, xmldoc): @@ -1585,6 +1591,8 @@ class LibvirtConfigGuestDiskMirror(LibvirtConfigObject): class LibvirtConfigGuestIDMap(LibvirtConfigObject): def __init__(self, **kwargs): + if 'root_name' not in kwargs: + kwargs['root_name'] = 'id' super(LibvirtConfigGuestIDMap, self).__init__(**kwargs) self.start = 0 self.target = 0 @@ -2168,13 +2176,14 @@ class LibvirtConfigGuestPCIeRootPortController(LibvirtConfigGuestController): class LibvirtConfigGuestHostdev(LibvirtConfigGuestDevice): def __init__(self, **kwargs): - super(LibvirtConfigGuestHostdev, self).\ - __init__(root_name="hostdev", **kwargs) - self.mode = kwargs.get('mode') - self.type = kwargs.get('type') + super(LibvirtConfigGuestHostdev, self).__init__( + root_name="hostdev", **kwargs, + ) + self.mode = None + self.type = None # managed attribute is only used by PCI devices but mediated devices # need to say managed=no - self.managed = kwargs.get('managed', 'yes') + self.managed = "yes" def format_dom(self): dev = super(LibvirtConfigGuestHostdev, self).format_dom() @@ -2194,8 +2203,11 @@ class LibvirtConfigGuestHostdev(LibvirtConfigGuestDevice): class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev): def __init__(self, **kwargs): super(LibvirtConfigGuestHostdevPCI, self).\ - __init__(mode='subsystem', type='pci', - **kwargs) + __init__(**kwargs) + + self.mode = 'subsystem' + self.type = 'pci' + # These are returned from libvirt as hexadecimal strings with 0x prefix # even if they have a different meaningful range: domain 16 bit, # bus 8 bit, slot 5 bit, and function 3 bit @@ -2252,10 +2264,14 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigGuestHostdev): class LibvirtConfigGuestHostdevMDEV(LibvirtConfigGuestHostdev): def __init__(self, **kwargs): - super(LibvirtConfigGuestHostdevMDEV, self).__init__( - mode='subsystem', type='mdev', managed='no', **kwargs) + super(LibvirtConfigGuestHostdevMDEV, self).__init__(**kwargs) + + self.mode = 'subsystem' + self.type = 'mdev' + self.managed = 'no' + # model attribute is only supported by mediated devices - self.model = kwargs.get('model', 'vfio-pci') + self.model = 'vfio-pci' self.uuid = None def format_dom(self): @@ -3585,11 +3601,11 @@ class LibvirtConfigGuestVPMEM(LibvirtConfigGuestDevice): self.model = "nvdimm" self.access = "shared" - self.source_path = kwargs.get("devpath", "") - self.align_size = kwargs.get("align_kb", 0) + self.source_path = "" + self.align_size = 0 self.pmem = True - self.target_size = kwargs.get("size_kb", 0) + self.target_size = 0 self.target_node = 0 self.label_size = 2 * units.Ki diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 4ab8489461ea..f4a07afcea5b 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -7017,8 +7017,10 @@ class LibvirtDriver(driver.ComputeDriver): size_kb = vpmem.size // units.Ki align_kb = vpmem.align // units.Ki - vpmem_config = vconfig.LibvirtConfigGuestVPMEM( - devpath=vpmem.devpath, size_kb=size_kb, align_kb=align_kb) + vpmem_config = vconfig.LibvirtConfigGuestVPMEM() + 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 guest.max_memory_size += size_kb