Add support for the 'cpu_models' option in nova.conf
Since OpenStack Train release the 'cpu_models' config option has superseded the 'cpu_model' config option in the nova.conf. This patch adds support for the new 'cpu_models' allowing a user to provide a comma separated list of supported, named CPU models. This patch also includes a unit test for the cpu_mode='custom'. Closes-bug: #2025914 Change-Id: I30328abc07d3304f1bfb67c81360fb5229214c97
This commit is contained in:
parent
31df8c6bf2
commit
b57593f86d
21
config.yaml
21
config.yaml
@ -395,6 +395,27 @@ options:
|
||||
Set to a named libvirt CPU model (see names listed in
|
||||
/usr/share/libvirt/cpu_map.xml). Only has effect if cpu_mode='custom' and
|
||||
virt_type='kvm|qemu'.
|
||||
.
|
||||
Starting from the Train release this option is deprecated and
|
||||
has been superseded by the 'cpu-models' option. This option will be
|
||||
silently ignored if the 'cpu-models' option is non-empty.
|
||||
cpu-models:
|
||||
type: string
|
||||
default:
|
||||
description: |
|
||||
An ordered, comma separated, list of the CPU models supported by the host.
|
||||
The models on the list must be ordered according to the features they
|
||||
support. The less advanced models must precede more advanced, feature
|
||||
rich, models.
|
||||
.
|
||||
Example: 'SandyBridge,IvyBridge,Haswell,Broadwell'
|
||||
.
|
||||
CPU models are listed in:
|
||||
* /usr/share/libvirt/cpu_map.xml (libvirt version < 4.7.0)
|
||||
* /usr/share/libvirt/cpu_map/*.xml (libvirt version >= 4.7.0)
|
||||
.
|
||||
This option only has effect if cpu_mode='custom' and
|
||||
virt_type='kvm|qemu'.
|
||||
cpu-model-extra-flags:
|
||||
type: string
|
||||
default:
|
||||
|
@ -278,7 +278,9 @@ class NovaComputeLibvirtContext(context.OSContextGenerator):
|
||||
elif ctxt['arch'] == 's390x':
|
||||
ctxt['cpu_mode'] = 'none'
|
||||
|
||||
if config('cpu-model'):
|
||||
if config('cpu-models'):
|
||||
ctxt['cpu_models'] = config('cpu-models')
|
||||
elif config('cpu-model'):
|
||||
ctxt['cpu_model'] = config('cpu-model')
|
||||
|
||||
if config('cpu-model-extra-flags'):
|
||||
|
@ -287,7 +287,9 @@ inject_partition = {{ inject_partition }}
|
||||
{% if cpu_mode -%}
|
||||
cpu_mode = {{ cpu_mode }}
|
||||
{% endif -%}
|
||||
{% if cpu_model -%}
|
||||
{% if cpu_models -%}
|
||||
cpu_models = {{ cpu_models }}
|
||||
{% elif cpu_model -%}
|
||||
cpu_model = {{ cpu_model }}
|
||||
{% endif -%}
|
||||
{% if cpu_model_extra_flags %}
|
||||
|
@ -270,7 +270,9 @@ inject_partition = {{ inject_partition }}
|
||||
{% if cpu_mode -%}
|
||||
cpu_mode = {{ cpu_mode }}
|
||||
{% endif -%}
|
||||
{% if cpu_model -%}
|
||||
{% if cpu_models -%}
|
||||
cpu_models = {{ cpu_models }}
|
||||
{% elif cpu_model -%}
|
||||
cpu_model = {{ cpu_model }}
|
||||
{% endif -%}
|
||||
{% if cpu_model_extra_flags %}
|
||||
|
@ -842,6 +842,41 @@ class NovaComputeContextTests(CharmTestCase):
|
||||
self.assertEqual(libvirt()['cpu_mode'],
|
||||
'none')
|
||||
|
||||
@patch.object(context.uuid, 'uuid4')
|
||||
def test_libvirt_cpu_mode_custom_model(self, mock_uuid):
|
||||
self.test_config.set('cpu-mode', 'custom')
|
||||
self.test_config.set('cpu-model', 'Broadwell')
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'bionic'}
|
||||
mock_uuid.return_value = 'e46e530d-18ae-4a67-9ff0-e6e2ba7c60a7'
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
|
||||
self.assertEqual(libvirt()['cpu_mode'], 'custom')
|
||||
self.assertEqual(libvirt()['cpu_model'], 'Broadwell')
|
||||
|
||||
# should be ignored
|
||||
self.test_config.set('cpu-mode', 'host-model')
|
||||
self.test_config.set('cpu-model', 'Haswell')
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
self.assertNotIn('cpu-model', libvirt())
|
||||
|
||||
@patch.object(context.uuid, 'uuid4')
|
||||
def test_libvirt_cpu_mode_custom_models(self, mock_uuid):
|
||||
self.test_config.set('cpu-mode', 'custom')
|
||||
self.test_config.set('cpu-models',
|
||||
'SandyBridge,IvyBridge,Haswell,Broadwell')
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'bionic'}
|
||||
mock_uuid.return_value = 'e46e530d-18ae-4a67-9ff0-e6e2ba7c60a7'
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
|
||||
self.assertEqual(libvirt()['cpu_mode'], 'custom')
|
||||
self.assertEqual(libvirt()['cpu_models'],
|
||||
'SandyBridge,IvyBridge,Haswell,Broadwell')
|
||||
|
||||
# should be ignored
|
||||
self.test_config.set('cpu-model', 'Haswell')
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
self.assertNotIn('cpu_model', libvirt())
|
||||
|
||||
@patch.object(context, 'platform')
|
||||
@patch.object(context.uuid, 'uuid4')
|
||||
def test_libvirt_cpu_mode_aarch64(self, mock_uuid, mock_platform):
|
||||
|
Loading…
Reference in New Issue
Block a user