Accept non-string types for BIOS settings

For BIOS settings allow non-string types to be set.

Change-Id: Icdf030b9a0fa0d785d309335e0ab2e82e25e0acf
This commit is contained in:
Bob Fournier 2022-02-03 16:49:55 -05:00
parent 248ec31ceb
commit 1553bf3182
3 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Allow non-string types to be configured for BIOS settings.

View File

@ -671,6 +671,8 @@ class LibvirtDriver(AbstractSystemsDriver):
bios = ET.SubElement(metadata, '{%s}bios' % (namespace))
attributes = ET.SubElement(bios, '{%s}attributes' % (namespace))
for key, value in sorted(bios_attributes.items()):
if not isinstance(value, str):
value = str(value)
ET.SubElement(attributes,
'{%s}attribute' % (namespace),
name=key,

View File

@ -901,6 +901,18 @@ class LibvirtDriverTestCase(base.BaseTestCase):
result.bios_attributes)
self._assert_bios_xml(result.tree)
def test__process_bios_attributes_update_non_string(self):
with open('sushy_tools/tests/unit/emulator/domain_bios.xml') as f:
domain_xml = f.read()
result = self.test_driver._process_bios_attributes(
domain_xml,
{"NumCores": 11},
True)
self.assertTrue(result.attributes_written)
self.assertEqual({"NumCores": "11"},
result.bios_attributes)
self._assert_bios_xml(result.tree)
def _assert_bios_xml(self, tree):
ns = {'sushy': 'http://openstack.org/xmlns/libvirt/sushy'}
self.assertIsNotNone(tree.find('metadata')