Fix UEFI firmware path and connection attribute in libvirt driver

Fixes libvirt domain XML build for UEFI boot and fixes typo in
connection attribute name in `set_boot_mode` method of the
libvirt driver.

Unit tests catching this bug reside in the next patch.

Change-Id: I63db95e83d42d59ea67d7fdfbbb1803ac7e5f9bb
This commit is contained in:
Ilya Etingof
2018-11-09 18:13:30 +01:00
parent 483fefed8f
commit c09ce2ce75

View File

@@ -74,11 +74,23 @@ class LibvirtDriver(AbstractDriver):
BOOT_MODE_MAP = {
'Legacy': 'rom',
'Uefi': 'pflash',
'Uefi': 'pflash'
}
BOOT_MODE_MAP_REV = {v: k for k, v in BOOT_MODE_MAP.items()}
# NOTE(etingof): we have these firmware blobs hardcoded here
# which seems to work for CentOS, for instance.
# What's not clear is how to adapt to possible different
# boot loaders paths dependent on libvirt packaging and custom
# domain configuration...
BOOT_LOADER_MAP = {
'Uefi': {
'x86_64': '/usr/share/OVMF/OVMF_CODE.fd',
'aarch64': '/usr/share/AAVMF/AAVMF_CODE.fd'
}
}
DEFAULT_BIOS_ATTRIBUTES = {"BootMode": "Uefi",
"EmbeddedSata": "Raid",
"NicBoot1": "NetworkBoot",
@@ -277,7 +289,7 @@ class LibvirtDriver(AbstractDriver):
tree = ET.fromstring(domain.XMLDesc())
try:
target = self.BOOT_MODE_MAP[boot_mode]
loader_type = self.BOOT_MODE_MAP[boot_mode]
except KeyError:
msg = ('Unknown boot mode requested: '
@@ -286,16 +298,31 @@ class LibvirtDriver(AbstractDriver):
raise FishyError(msg)
for os_element in tree.findall('os'):
# Remove all "boot" elements
for loader_element in os_element.findall('loader'):
os_element.remove(loader_element)
# Add a new loader element with the request boot mode
loader_element = ET.SubElement(os_element, 'loader')
loader_element.set('type', target)
type_element = os_element.find('type')
if type_element is None:
os_arch = None
else:
os_arch = type_element.get('arch')
try:
self._conn.defineXML(ET.tostring(tree).decode('utf-8'))
loader_path = self.BOOT_LOADER_MAP[boot_mode][os_arch]
except KeyError:
# NOTE(etingof): assume no specific boot loader
loader_path = ''
# Update all "loader" elements
for loader_element in os_element.findall('loader'):
loader_element.set('type', loader_type)
# NOTE(etingof): here we override previous boot loader for
# for the domain. If it's different than what we have
# hardcoded in the BOOT_LOADER_MAP, we won't be able to
# revert back to the original boor loader should we change
# domain boot mode.
loader_element.text = loader_path
try:
conn.defineXML(ET.tostring(tree).decode('utf-8'))
except libvirt.libvirtError as e:
msg = ('Error changing boot mode at libvirt URI "%(uri)s": '