preserve secure information on xml changes

When setting parameters revolving around boot
mode, options, firmware, it is necessary to
extract and edit the XML document.

Some details, however, are not automatically
extracted and libvirt must be told to provide
secure information. This change prevents us
from accidently loosing such configuration
parameters

Story: 2010382
Task: 46651

Change-Id: I0da2f37c5b630d2a180f59b74f23c027ee56e17b
This commit is contained in:
Julia Kreger 2022-10-25 08:13:28 -07:00 committed by Jay Faulkner
parent 7aac77d406
commit 348e965114
2 changed files with 23 additions and 1 deletions

View File

@ -0,0 +1,10 @@
---
security:
- |
Secure information in the Libvirt domain XML document is now preserved.
For more information, please see `story 2010382
<https://storyboard.openstack.org/#!/story/2010382>`_.
fixes:
- |
Fixes an issue where secure fields were accidently lost in the Libvirt
domain XML document.

View File

@ -60,6 +60,17 @@ class VirtualBMC(bmc.Bmc):
'sasl_username': libvirt_sasl_username,
'sasl_password': libvirt_sasl_password}
# Copied from nova/virt/libvirt/guest.py
def get_xml_desc(self, domain, dump_sensitive=False):
"""Returns xml description of guest.
:param domain: The libvirt domain to call
:param dump_sensitive: Dump security sensitive information
:returns string: XML description of the guest
"""
flags = dump_sensitive and libvirt.VIR_DOMAIN_XML_SECURE or 0
return domain.XMLDesc(flags=flags)
def get_boot_device(self):
LOG.debug('Get boot device called for %(domain)s',
{'domain': self.domain_name})
@ -87,7 +98,8 @@ class VirtualBMC(bmc.Bmc):
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
tree = ET.fromstring(domain.XMLDesc())
tree = ET.fromstring(
self.get_xml_desc(domain, dump_sensitive=True))
# Remove all "boot" element under "devices"
# They are mutually exclusive with "os/boot"