Merge "fup: Merge machine_type_mappings into get_default_machine_type"

This commit is contained in:
Zuul 2019-06-14 06:33:16 +00:00 committed by Gerrit Code Review
commit e0271d76ff
2 changed files with 11 additions and 25 deletions

View File

@ -971,18 +971,6 @@ sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
self.assertEqual('/test/disk', disk_path)
self.assertEqual('ploop', format)
def test_machine_type_mappings(self):
self.useFixture(nova_fixtures.ConfPatcher(
group="libvirt", hw_machine_type=['x86_64=q35', 'i686=legacy']))
self.assertDictEqual({'x86_64': 'q35', 'i686': 'legacy'},
libvirt_utils.machine_type_mappings())
def test_invalid_machine_type_mappings(self):
self.useFixture(nova_fixtures.ConfPatcher(
group="libvirt", hw_machine_type=['x86_64=q35', 'foo']))
self.assertDictEqual({'x86_64': 'q35'},
libvirt_utils.machine_type_mappings())
def test_get_default_machine_type(self):
self.useFixture(nova_fixtures.ConfPatcher(
group="libvirt", hw_machine_type=['x86_64=q35', 'i686=legacy']))
@ -996,3 +984,9 @@ sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
self.useFixture(nova_fixtures.ConfPatcher(
group="libvirt", hw_machine_type=['x86_64=q35', 'i686=legacy']))
self.assertIsNone(libvirt_utils.get_default_machine_type('sparc'))
def test_get_default_machine_type_invalid(self):
self.useFixture(nova_fixtures.ConfPatcher(
group="libvirt", hw_machine_type=['x86_64=q35', 'foo']))
self.assertEqual('q35',
libvirt_utils.get_default_machine_type('x86_64'))

View File

@ -554,23 +554,15 @@ def get_machine_type(image_meta):
return get_default_machine_type(get_arch(image_meta))
def machine_type_mappings():
mappings = {}
def get_default_machine_type(arch):
# NOTE(lyarwood): Values defined in [libvirt]/hw_machine_type take
# precedence here if available for the provided arch.
for mapping in CONF.libvirt.hw_machine_type or {}:
host_arch, _, machine_type = mapping.partition('=')
if machine_type == '':
LOG.warning("Invalid hw_machine_type config value %s", mapping)
else:
mappings[host_arch] = machine_type
return mappings
def get_default_machine_type(arch):
# NOTE(lyarwood): Values defined in [libvirt]/hw_machine_type take
# precedence here if available for the provided arch.
machine_type = machine_type_mappings().get(arch)
if machine_type:
return machine_type
elif host_arch == arch:
return machine_type
# NOTE(kchamart): For ARMv7 and AArch64, use the 'virt' board as the
# default machine type. It is the recommended board, which is designed
# to be used with virtual machines. The 'virt' board is more flexible,