More strictly validate cpu_mode and cpu_models

The nova-compute service fails to start in case
 cpu_mode is 'custom' but cpu_models is default or empty
or
 cpu_models is configured but cpu_mode is not 'custom'

Make the deployment hard-fail in case the given values are not accepted
by nova, to make users aware of their misconfiguration.

Change-Id: Iea4fb9990981ec0dc14a0dabd9674aa3b27a7137
This commit is contained in:
Takashi Kajinami
2024-07-10 01:29:24 +09:00
parent 8600cd851e
commit a5e5529a67
2 changed files with 24 additions and 7 deletions

View File

@@ -29,7 +29,7 @@
#
# [*cpu_models*]
# (optional) The named libvirt CPU models (see names listed in
# /usr/share/libvirt/cpu_map.xml). Only has effect if
# /usr/share/libvirt/cpu_map.xml). This option requires
# cpu_mode="custom" and virt_type="kvm|qemu".
# Defaults to []
#
@@ -398,16 +398,18 @@ class nova::compute::libvirt (
'libvirt/tb_cache_size': value => $tb_cache_size;
}
# cpu_model param is only valid if cpu_mode=custom
# otherwise it should be commented out
if $cpu_mode_real == 'custom' and !empty($cpu_models){
if !empty($cpu_models) {
if $cpu_mode_real != 'custom' {
fail('$cpu_models requires that $cpu_mode is "custom"')
}
$cpu_models_real = join($cpu_models, ',')
} else {
if !empty($cpu_models) {
warning('$cpu_models requires that $cpu_mode => "custom" and will be ignored')
if $cpu_mode_real == 'custom' {
fail('$cpu_models is required when $cpu_mode is "custom"')
}
$cpu_models_real = $facts['os_service_default']
}
nova_config {
'libvirt/cpu_models': value => $cpu_models_real;
}

View File

@@ -65,7 +65,6 @@ describe 'nova::compute::libvirt' do
:virt_type => 'qemu',
:vncserver_listen => '0.0.0.0',
:cpu_mode => 'host-passthrough',
:cpu_models => ['kvm64', 'qemu64'],
:cpu_model_extra_flags => 'pcid',
:cpu_power_management => false,
:cpu_power_management_strategy => 'cpu_state',
@@ -165,6 +164,22 @@ describe 'nova::compute::libvirt' do
it { is_expected.to contain_nova_config('libvirt/cpu_model_extra_flags').with_value('pcid')}
end
context 'with non-custom cpu_node and cpu_models' do
let :params do
{ :cpu_models => ['kvm64', 'qemu64'] }
end
it { should raise_error(Puppet::Error, /\$cpu_models requires that \$cpu_mode is "custom"/) }
end
context 'with custom cpu_node and no cpu_models' do
let :params do
{ :cpu_mode => 'custom' }
end
it { should raise_error(Puppet::Error, /\$cpu_models is required when \$cpu_mode is "custom"/) }
end
context 'with hw_machine_type set by array' do
let :params do
{ :hw_machine_type => ['x86_64=machinetype1', 'armv7l=machinetype2'] }