From cc00e708dee3afe151226e51167b144f97c3cbdc Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Wed, 20 Mar 2024 20:08:55 +0100 Subject: [PATCH] Consolidate boolean config opts in nova::compute Make them more consistent by reducing the logic and grouping them together. Change-Id: I7c1dc27edaedb1d8835434f93ea5f6a2bf1b45eb --- manifests/compute.pp | 35 +++++++------------------- spec/classes/nova_compute_spec.rb | 42 +++++++++++++------------------ 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/manifests/compute.pp b/manifests/compute.pp index bc3e1e834..74ae11f49 100644 --- a/manifests/compute.pp +++ b/manifests/compute.pp @@ -52,11 +52,11 @@ # # [*force_config_drive*] # (optional) Whether to force the config drive to be attached to all VMs -# Defaults to false +# Defaults to $facts['os_service_default'] # # [*instance_usage_audit*] # (optional) Generate periodic compute.instance.exists notifications. -# Defaults to false +# Defaults to $facts['os_service_default'] # # [*instance_usage_audit_period*] # (optional) Time period to generate instance usages for. @@ -273,8 +273,8 @@ class nova::compute ( $vncproxy_protocol = 'http', $vncproxy_port = '6080', $vncproxy_path = '/vnc_auto.html', - Boolean $force_config_drive = false, - Boolean $instance_usage_audit = false, + $force_config_drive = $facts['os_service_default'], + $instance_usage_audit = $facts['os_service_default'], $instance_usage_audit_period = $facts['os_service_default'], $flat_injected = $facts['os_service_default'], $mkisofs_cmd = $facts['os_service_default'], @@ -439,28 +439,11 @@ class nova::compute ( ensure_package => $ensure_package, } - if $force_config_drive { - nova_config { 'DEFAULT/force_config_drive': value => true } - } else { - nova_config { 'DEFAULT/force_config_drive': ensure => absent } - } - - if $instance_usage_audit { - nova_config { - 'DEFAULT/instance_usage_audit': value => $instance_usage_audit; - 'DEFAULT/instance_usage_audit_period': value => $instance_usage_audit_period; - } - } else { - nova_config { - 'DEFAULT/instance_usage_audit': ensure => absent; - 'DEFAULT/instance_usage_audit_period': ensure => absent; - } - } - - nova_config { 'DEFAULT/flat_injected': value => $flat_injected } - nova_config { - 'DEFAULT/config_drive_format': value => pick($config_drive_format, $facts['os_service_default']); + 'DEFAULT/force_config_drive': value => $force_config_drive; + 'DEFAULT/instance_usage_audit': value => $instance_usage_audit; + 'DEFAULT/instance_usage_audit_period': value => $instance_usage_audit_period; + 'DEFAULT/flat_injected': value => $flat_injected; + 'DEFAULT/config_drive_format': value => pick($config_drive_format, $facts['os_service_default']); } - } diff --git a/spec/classes/nova_compute_spec.rb b/spec/classes/nova_compute_spec.rb index 23943af04..4d2097059 100644 --- a/spec/classes/nova_compute_spec.rb +++ b/spec/classes/nova_compute_spec.rb @@ -66,6 +66,8 @@ describe 'nova::compute' do it { is_expected.to contain_nova_config('compute/image_type_exclude_list').with_value('') } it { is_expected.to contain_nova_config('DEFAULT/block_device_allocate_retries').with_value('') } it { is_expected.to contain_nova_config('DEFAULT/block_device_allocate_retries_interval').with_value('') } + it { is_expected.to contain_nova_config('DEFAULT/instance_usage_audit').with_value('') } + it { is_expected.to contain_nova_config('DEFAULT/instance_usage_audit_period').with_value('') } it { is_expected.to contain_nova_config('DEFAULT/flat_injected').with_value('') } it { is_expected.to contain_nova_config('DEFAULT/config_drive_format').with_value('') } @@ -289,22 +291,6 @@ describe 'nova::compute' do it { should raise_error(Puppet::Error, /vnc_enabled and spice_enabled is mutually exclusive/) } end - context 'with force_config_drive parameter set to true' do - let :params do - { :force_config_drive => true } - end - - it { is_expected.to contain_nova_config('DEFAULT/force_config_drive').with_value(true) } - end - - context 'with flat_injected parameter set to true' do - let :params do - { :flat_injected => true } - end - - it { is_expected.to contain_nova_config('DEFAULT/flat_injected').with_value(true) } - end - context 'while not managing service state' do let :params do { @@ -315,15 +301,6 @@ describe 'nova::compute' do it { is_expected.to_not contain_service('nova-compute') } end - context 'with instance_usage_audit parameter set to false' do - let :params do - { :instance_usage_audit => false, } - end - - it { is_expected.to contain_nova_config('DEFAULT/instance_usage_audit').with_ensure('absent') } - it { is_expected.to contain_nova_config('DEFAULT/instance_usage_audit_period').with_ensure('absent') } - end - context 'with instance_usage_audit parameter and period' do let :params do { :instance_usage_audit => true, @@ -334,6 +311,21 @@ describe 'nova::compute' do it { is_expected.to contain_nova_config('DEFAULT/instance_usage_audit_period').with_value('year') } end + context 'with flat_injected parameter set to true' do + let :params do + { :flat_injected => true } + end + + it { is_expected.to contain_nova_config('DEFAULT/flat_injected').with_value(true) } + end + + context 'with force_config_drive parameter set to true' do + let :params do + { :force_config_drive => true } + end + + it { is_expected.to contain_nova_config('DEFAULT/force_config_drive').with_value(true) } + end end on_supported_os({