From 06875a6c739738fe70cd072f3078ea2dc6ec8b86 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 4 Apr 2023 00:48:59 +0900 Subject: [PATCH] Add native resource type for qemu.conf This introduces the native resource type to manipulate qemu.conf, so that we can define the resources in the same way for all libvirt config files. This also updates all libvirt config resource types to convert boolean values automatically, because libvirt does not support raw boolean values and the values should be converted to 1/0. Change-Id: I562d19299e0377e02f2587f5ef36d35069b5a5cd --- .../provider/qemu_config/ini_setting.rb | 10 + lib/puppet/type/libvirtd_config.rb | 8 +- lib/puppet/type/qemu_config.rb | 63 ++++++ lib/puppet/type/virtlockd_config.rb | 8 +- lib/puppet/type/virtlogd_config.rb | 8 +- lib/puppet/type/virtnodedevd_config.rb | 8 +- lib/puppet/type/virtproxyd_config.rb | 8 +- lib/puppet/type/virtqemud_config.rb | 8 +- lib/puppet/type/virtsecretd_config.rb | 8 +- lib/puppet/type/virtstoraged_config.rb | 8 +- manifests/compute/libvirt/config.pp | 7 + manifests/compute/libvirt/qemu.pp | 83 +++---- manifests/deps.pp | 1 + manifests/migration/qemu.pp | 35 +-- .../notes/qemu_config-9c7a99cf69972152.yaml | 9 + .../classes/nova_compute_libvirt_qemu_spec.rb | 202 +++++------------- spec/classes/nova_migration_qemu_spec.rb | 33 ++- spec/unit/type/libvirtd_config_spec.rb | 10 + spec/unit/type/qemu_config_spec.rb | 34 +++ spec/unit/type/virtlockd_config_spec.rb | 10 + spec/unit/type/virtlogd_config_spec.rb | 10 + spec/unit/type/virtnodedevd_config_spec.rb | 10 + spec/unit/type/virtproxyd_config_spec.rb | 10 + spec/unit/type/virtsecretd_config_spec.rb | 10 + 24 files changed, 340 insertions(+), 261 deletions(-) create mode 100644 lib/puppet/provider/qemu_config/ini_setting.rb create mode 100644 lib/puppet/type/qemu_config.rb create mode 100644 releasenotes/notes/qemu_config-9c7a99cf69972152.yaml create mode 100644 spec/unit/type/qemu_config_spec.rb diff --git a/lib/puppet/provider/qemu_config/ini_setting.rb b/lib/puppet/provider/qemu_config/ini_setting.rb new file mode 100644 index 000000000..d5dfe09fe --- /dev/null +++ b/lib/puppet/provider/qemu_config/ini_setting.rb @@ -0,0 +1,10 @@ +Puppet::Type.type(:qemu_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:libvirtd_config).provider(:ini_setting) +) do + + def self.file_path + '/etc/libvirt/qemu.conf' + end + +end diff --git a/lib/puppet/type/libvirtd_config.rb b/lib/puppet/type/libvirtd_config.rb index 0d1af4221..c10e9c7b0 100644 --- a/lib/puppet/type/libvirtd_config.rb +++ b/lib/puppet/type/libvirtd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:libvirtd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/qemu_config.rb b/lib/puppet/type/qemu_config.rb new file mode 100644 index 000000000..92a1c2036 --- /dev/null +++ b/lib/puppet/type/qemu_config.rb @@ -0,0 +1,63 @@ +Puppet::Type.newtype(:qemu_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'setting name to manage from qemu.conf' + newvalues(/\S+/) + end + + newproperty(:value) do + desc 'The value of the setting to be defined.' + munge do |value| + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end + value + end + + def is_to_s( currentvalue ) + if resource.secret? + return '[old secret redacted]' + else + return currentvalue + end + end + + def should_to_s( newvalue ) + if resource.secret? + return '[new secret redacted]' + else + return newvalue + end + end + end + + newparam(:secret, :boolean => true) do + desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + + newvalues(:true, :false) + + defaultto false + end + + newparam(:quote, :boolean => true) do + desc 'Whether to quote the value. Defauls to `false`.' + newvalues(:true, :false) + defaultto false + end + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:anchor) do + ['nova::install::end'] + end + +end diff --git a/lib/puppet/type/virtlockd_config.rb b/lib/puppet/type/virtlockd_config.rb index b7f08ade9..9f89f6140 100644 --- a/lib/puppet/type/virtlockd_config.rb +++ b/lib/puppet/type/virtlockd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtlockd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtlogd_config.rb b/lib/puppet/type/virtlogd_config.rb index 5735959d5..4babb0a8a 100644 --- a/lib/puppet/type/virtlogd_config.rb +++ b/lib/puppet/type/virtlogd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtlogd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtnodedevd_config.rb b/lib/puppet/type/virtnodedevd_config.rb index 4276d0e60..c8cb14fd3 100644 --- a/lib/puppet/type/virtnodedevd_config.rb +++ b/lib/puppet/type/virtnodedevd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtnodedevd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtproxyd_config.rb b/lib/puppet/type/virtproxyd_config.rb index bd751b190..137336596 100644 --- a/lib/puppet/type/virtproxyd_config.rb +++ b/lib/puppet/type/virtproxyd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtproxyd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtqemud_config.rb b/lib/puppet/type/virtqemud_config.rb index 0ff0d7228..9acbebf21 100644 --- a/lib/puppet/type/virtqemud_config.rb +++ b/lib/puppet/type/virtqemud_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtqemud_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtsecretd_config.rb b/lib/puppet/type/virtsecretd_config.rb index caa18190b..9c596e788 100644 --- a/lib/puppet/type/virtsecretd_config.rb +++ b/lib/puppet/type/virtsecretd_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtsecretd_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/lib/puppet/type/virtstoraged_config.rb b/lib/puppet/type/virtstoraged_config.rb index 76d4d15b6..04a0f0084 100644 --- a/lib/puppet/type/virtstoraged_config.rb +++ b/lib/puppet/type/virtstoraged_config.rb @@ -10,7 +10,13 @@ Puppet::Type.newtype(:virtstoraged_config) do newproperty(:value) do desc 'The value of the setting to be defined.' munge do |value| - value = value.to_s.strip + if [true, false].include?(value) + # NOTE(tkajinam): libvirt config file does not accept boolean values + # and the value should be converted to 1/0. + value = value ? '1' : '0' + else + value = value.to_s.strip + end value end diff --git a/manifests/compute/libvirt/config.pp b/manifests/compute/libvirt/config.pp index e1db3bf28..6d92c0904 100644 --- a/manifests/compute/libvirt/config.pp +++ b/manifests/compute/libvirt/config.pp @@ -45,6 +45,10 @@ # (optional) Allow configuration of arbitrary virtstoraged configurations. # The value is an hash of virtstoraged_config resources. # +# [*qemu_config*] +# (optional) Allow configuration of arbitrary qemu configurations. +# The value is an hash of qemu_config resources. +# # NOTE: The configuration MUST NOT be already handled by this module # or Puppet catalog compilation will fail with duplicate resources. # @@ -57,6 +61,7 @@ class nova::compute::libvirt::config ( $virtqemud_config = {}, $virtsecretd_config = {}, $virtstoraged_config = {}, + $qemu_config = {}, ) { include nova::deps @@ -69,6 +74,7 @@ class nova::compute::libvirt::config ( validate_legacy(Hash, 'validate_hash', $virtqemud_config) validate_legacy(Hash, 'validate_hash', $virtsecretd_config) validate_legacy(Hash, 'validate_hash', $virtstoraged_config) + validate_legacy(Hash, 'validate_hash', $qemu_config) create_resources('libvirtd_config', $libvirtd_config) create_resources('virtlogd_config', $virtlogd_config) @@ -78,4 +84,5 @@ class nova::compute::libvirt::config ( create_resources('virtqemud_config', $virtqemud_config) create_resources('virtsecretd_config', $virtsecretd_config) create_resources('virtstoraged_config', $virtstoraged_config) + create_resources('qemu_config', $qemu_config) } diff --git a/manifests/compute/libvirt/qemu.pp b/manifests/compute/libvirt/qemu.pp index 4b7414642..635f7bb16 100644 --- a/manifests/compute/libvirt/qemu.pp +++ b/manifests/compute/libvirt/qemu.pp @@ -76,84 +76,55 @@ class nova::compute::libvirt::qemu( fail('libvirt version < 4.5 is no longer supported') } - Anchor['nova::config::begin'] - -> Augeas<| tag == 'qemu-conf-augeas'|> - -> Anchor['nova::config::end'] - - Augeas<| tag == 'qemu-conf-augeas'|> - ~> Service<| tag == 'libvirt-qemu-service' |> + Qemu_config<||> ~> Service<| tag == 'libvirt-qemu-service' |> if $configure_qemu { if $vnc_tls { - $vnc_tls_value = 1 - $vnc_tls_verify_value = $vnc_tls_verify ? { true => 1, false => 0 } + $vnc_tls_verify_real = $vnc_tls_verify } else { - $vnc_tls_value = 0 - $vnc_tls_verify_value = 0 + $vnc_tls_verify_real = false } - $default_tls_verify_value = $default_tls_verify ? { true => 1, false => 0 } - $nbd_tls_value = $nbd_tls ? { true => 1, false => 0 } - - $augues_changes_default = [ - "set max_files ${max_files}", - "set max_processes ${max_processes}", - "set vnc_tls ${vnc_tls_value}", - "set vnc_tls_x509_verify ${vnc_tls_verify_value}", - "set default_tls_x509_verify ${default_tls_verify_value}", - ] + qemu_config { + 'max_files': value => $max_files; + 'max_processes': value => $max_processes; + 'vnc_tls': value => $vnc_tls; + 'vnc_tls_x509_verify': value => $vnc_tls_verify_real; + 'default_tls_x509_verify': value => $default_tls_verify; + } if $user and !empty($user) { - $augues_user_changes = ["set user ${user}"] + qemu_config { 'user': value => $user, quote =>true } } else { - $augues_user_changes = ['rm user'] + qemu_config { 'user': ensure => absent } } if $group and !empty($group) { - $augues_group_changes = ["set group ${group}"] + qemu_config { 'group': value => $group, quote =>true } } else { - $augues_group_changes = ['rm group'] + qemu_config { 'group': ensure => absent } } if $memory_backing_dir and !empty($memory_backing_dir) { - $augues_memory_backing_dir_changes = ["set memory_backing_dir ${memory_backing_dir}"] + qemu_config { 'memory_backing_dir': value => $memory_backing_dir, quote =>true } } else { - $augues_memory_backing_dir_changes = ['rm memory_backing_dir'] + qemu_config { 'memory_backing_dir': ensure => absent } } - $augues_nbd_tls_changes = ["set nbd_tls ${nbd_tls_value}"] - $augues_changes = concat( - $augues_changes_default, - $augues_user_changes, - $augues_group_changes, - $augues_memory_backing_dir_changes, - $augues_nbd_tls_changes - ) + qemu_config { 'nbd_tls': value => $nbd_tls } - augeas { 'qemu-conf-limits': - context => '/files/etc/libvirt/qemu.conf', - changes => $augues_changes, - tag => 'qemu-conf-augeas', - } } else { - - $augues_changes = [ - 'rm max_files', - 'rm max_processes', - 'rm vnc_tls', - 'rm vnc_tls_x509_verify', - 'rm default_tls_x509_verify', - 'rm user', - 'rm group', - 'rm memory_backing_dir', - 'rm nbd_tls', - ] - - augeas { 'qemu-conf-limits': - context => '/files/etc/libvirt/qemu.conf', - changes => $augues_changes, - tag => 'qemu-conf-augeas', + qemu_config { + 'max_files': ensure => absent; + 'max_processes': ensure => absent; + 'vnc_tls': ensure => absent; + 'vnc_tls_x509_verify': ensure => absent; + 'default_tls_x509_verify': ensure => absent; + 'user': ensure => absent; + 'group': ensure => absent; + 'memory_backing_dir': ensure => absent; + 'nbd_tls': ensure => absent; } } } diff --git a/manifests/deps.pp b/manifests/deps.pp index 2dee87188..acc2ca9c6 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -72,6 +72,7 @@ class nova::deps { Anchor['nova::config::begin'] -> Virtqemud_config<||> -> Anchor['nova::config::end'] Anchor['nova::config::begin'] -> Virtsecretd_config<||> -> Anchor['nova::config::end'] Anchor['nova::config::begin'] -> Virtstoraged_config<||> -> Anchor['nova::config::end'] + Anchor['nova::config::begin'] -> Qemu_config<||> -> Anchor['nova::config::end'] # all cache settings should be applied and all packages should be installed # before service startup diff --git a/manifests/migration/qemu.pp b/manifests/migration/qemu.pp index 2bab8dc47..6b98eebac 100644 --- a/manifests/migration/qemu.pp +++ b/manifests/migration/qemu.pp @@ -10,46 +10,33 @@ # # [*migration_port_min*] # (optional) Lower limit of port range used for migration. -# Defaults to 49152. +# Defaults to $facts['os_service_default']. # # [*migration_port_max*] # (optional) Higher limit of port range used for migration. -# Defaults to 49215. +# Defaults to $facts['os_service_default']. # class nova::migration::qemu( $configure_qemu = false, - $migration_port_min = 49152, - $migration_port_max = 49215, + $migration_port_min = $facts['os_service_default'], + $migration_port_max = $facts['os_service_default'], ){ include nova::deps validate_legacy(Boolean, 'validate_bool', $configure_qemu) - Anchor['nova::config::begin'] - -> Augeas<| tag == 'qemu-conf-augeas'|> - -> Anchor['nova::config::end'] - - Augeas<| tag == 'qemu-conf-augeas'|> - ~> Service<| tag == 'libvirt-qemu-service' |> + Qemu_config<||> ~> Service<| tag == 'libvirt-qemu-service' |> if $configure_qemu { - augeas { 'qemu-conf-migration-ports': - context => '/files/etc/libvirt/qemu.conf', - changes => [ - "set migration_port_min ${migration_port_min}", - "set migration_port_max ${migration_port_max}", - ], - tag => 'qemu-conf-augeas', + qemu_config { + 'migration_port_min': value => $migration_port_min; + 'migration_port_max': value => $migration_port_max; } } else { - augeas { 'qemu-conf-migration-ports': - context => '/files/etc/libvirt/qemu.conf', - changes => [ - 'rm migration_port_min', - 'rm migration_port_max', - ], - tag => 'qemu-conf-augeas', + qemu_config { + 'migration_port_min': ensure => absent; + 'migration_port_max': ensure => absent; } } } diff --git a/releasenotes/notes/qemu_config-9c7a99cf69972152.yaml b/releasenotes/notes/qemu_config-9c7a99cf69972152.yaml new file mode 100644 index 000000000..1672ce9ce --- /dev/null +++ b/releasenotes/notes/qemu_config-9c7a99cf69972152.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The new ``qemu_config`` resource type has been added. This resource type + allows configuring options in `/etc/libvirt/qemu.conf`. + + - | + The new ``nova::compute::libvirt::config::qemu_config`` parameter has been + added. diff --git a/spec/classes/nova_compute_libvirt_qemu_spec.rb b/spec/classes/nova_compute_libvirt_qemu_spec.rb index 39996bb35..38a51f3b9 100644 --- a/spec/classes/nova_compute_libvirt_qemu_spec.rb +++ b/spec/classes/nova_compute_libvirt_qemu_spec.rb @@ -5,101 +5,56 @@ describe 'nova::compute::libvirt::qemu' do shared_examples_for 'nova compute libvirt with qemu' do context 'when not configuring qemu' do - let :params do - { - :configure_qemu => false, - } + it 'should remove all configuations' do + is_expected.to contain_qemu_config('max_files').with_ensure('absent') + is_expected.to contain_qemu_config('max_processes').with_ensure('absent') + is_expected.to contain_qemu_config('vnc_tls').with_ensure('absent') + is_expected.to contain_qemu_config('vnc_tls_x509_verify').with_ensure('absent') + is_expected.to contain_qemu_config('default_tls_x509_verify').with_ensure('absent') + is_expected.to contain_qemu_config('user').with_ensure('absent') + is_expected.to contain_qemu_config('group').with_ensure('absent') + is_expected.to contain_qemu_config('memory_backing_dir').with_ensure('absent') + is_expected.to contain_qemu_config('nbd_tls').with_ensure('absent') end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "rm max_files", - "rm max_processes", - "rm vnc_tls", - "rm vnc_tls_x509_verify", - "rm default_tls_x509_verify", - "rm user", - "rm group", - "rm memory_backing_dir", - "rm nbd_tls", - ], - }) } end - context 'when configuring qemu by default' do + context 'when configuring qemu with defaults' do let :params do { :configure_qemu => true, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should configure the default values' do + is_expected.to contain_qemu_config('max_files').with_value(1024) + is_expected.to contain_qemu_config('max_processes').with_value(4096) + is_expected.to contain_qemu_config('vnc_tls').with_value(false) + is_expected.to contain_qemu_config('vnc_tls_x509_verify').with_value(false) + is_expected.to contain_qemu_config('default_tls_x509_verify').with_value(true) + is_expected.to contain_qemu_config('user').with_ensure('absent') + is_expected.to contain_qemu_config('group').with_ensure('absent') + is_expected.to contain_qemu_config('memory_backing_dir').with_ensure('absent') + is_expected.to contain_qemu_config('nbd_tls').with_value(false) + end end context 'when configuring qemu with overridden parameters' do - let :params do - { - :configure_qemu => true, - :max_files => 32768, - :max_processes => 131072, - } - end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 32768", - "set max_processes 131072", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } - end - - context 'when configuring qemu with user/group parameter' do let :params do { :configure_qemu => true, - :user => 'qemu-user', - :group => 'qemu-group', :max_files => 32768, :max_processes => 131072, + :user => 'qemu-user', + :group => 'qemu-group', :memory_backing_dir => '/tmp', } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 32768", - "set max_processes 131072", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "set user qemu-user", - "set group qemu-group", - "set memory_backing_dir /tmp", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should configure the given values' do + is_expected.to contain_qemu_config('max_files').with_value(32768) + is_expected.to contain_qemu_config('max_processes').with_value(131072) + is_expected.to contain_qemu_config('user').with_value('qemu-user').with_quote(true) + is_expected.to contain_qemu_config('group').with_value('qemu-group').with_quote(true) + is_expected.to contain_qemu_config('memory_backing_dir').with_value('/tmp').with_quote(true) + end end context 'when configuring qemu with vnc_tls' do @@ -109,21 +64,10 @@ describe 'nova::compute::libvirt::qemu' do :vnc_tls => true, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 1", - "set vnc_tls_x509_verify 1", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should configure vnc tls' do + is_expected.to contain_qemu_config('vnc_tls').with_value(true) + is_expected.to contain_qemu_config('vnc_tls_x509_verify').with_value(true) + end end context 'when configuring qemu with default_tls_verify enabled' do @@ -133,21 +77,9 @@ describe 'nova::compute::libvirt::qemu' do :default_tls_verify => true, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should enable default_tls_x509_verify' do + is_expected.to contain_qemu_config('default_tls_x509_verify').with_value(true) + end end context 'when configuring qemu with vnc_tls_verify disabled' do @@ -158,21 +90,10 @@ describe 'nova::compute::libvirt::qemu' do :vnc_tls_verify => false, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 1", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should disable vnc_tls_x509_veridy' do + is_expected.to contain_qemu_config('vnc_tls').with_value(true) + is_expected.to contain_qemu_config('vnc_tls_x509_verify').with_value(false) + end end context 'when configuring qemu with default_tls_verify disabled' do @@ -182,45 +103,21 @@ describe 'nova::compute::libvirt::qemu' do :default_tls_verify => false, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 0", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 0", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should disable default_tls_x509_verify' do + is_expected.to contain_qemu_config('default_tls_x509_verify').with_value(false) + end end - context 'when configuring qemu with nbd_tls and libvirt >= 4.5' do + context 'when configuring qemu with nbd_tls' do let :params do { :configure_qemu => true, :nbd_tls => true, } end - it { is_expected.to contain_augeas('qemu-conf-limits').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ - "set max_files 1024", - "set max_processes 4096", - "set vnc_tls 0", - "set vnc_tls_x509_verify 0", - "set default_tls_x509_verify 1", - "rm user", - "rm group", - "rm memory_backing_dir", - "set nbd_tls 1", - ], - :tag => 'qemu-conf-augeas', - }) } + it 'should enable nbd_tls' do + is_expected.to contain_qemu_config('nbd_tls').with_value(true) + end end end @@ -236,5 +133,4 @@ describe 'nova::compute::libvirt::qemu' do it_configures 'nova compute libvirt with qemu' end end - end diff --git a/spec/classes/nova_migration_qemu_spec.rb b/spec/classes/nova_migration_qemu_spec.rb index e2caebfd7..9356168e9 100644 --- a/spec/classes/nova_migration_qemu_spec.rb +++ b/spec/classes/nova_migration_qemu_spec.rb @@ -11,43 +11,36 @@ describe 'nova::migration::qemu' do shared_examples_for 'nova migration with qemu' do context 'when not configuring qemu' do - let :params do - { - :configure_qemu => false - } + it 'should clear all configurations' do + is_expected.to contain_qemu_config('migration_port_min').with_ensure('absent') + is_expected.to contain_qemu_config('migration_port_max').with_ensure('absent') end - it { is_expected.to contain_augeas('qemu-conf-migration-ports').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ "rm migration_port_min", "rm migration_port_max" ], - }) } end - context 'when configuring qemu by default' do + context 'when configuring qemu with defaults' do let :params do { :configure_qemu => true } end - it { is_expected.to contain_augeas('qemu-conf-migration-ports').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ "set migration_port_min 49152", "set migration_port_max 49215" ], - :tag => 'qemu-conf-augeas', - }) } + it 'should configure the default values' do + is_expected.to contain_qemu_config('migration_port_min').with_value('') + is_expected.to contain_qemu_config('migration_port_max').with_value('') + end end context 'when configuring qemu with overridden parameters' do let :params do { - :configure_qemu => true, + :configure_qemu => true, :migration_port_min => 61138, :migration_port_max => 61200, } end - it { is_expected.to contain_augeas('qemu-conf-migration-ports').with({ - :context => '/files/etc/libvirt/qemu.conf', - :changes => [ "set migration_port_min 61138", "set migration_port_max 61200" ], - :tag => 'qemu-conf-augeas', - }) } + it 'should configure the given values' do + is_expected.to contain_qemu_config('migration_port_min').with_value(61138) + is_expected.to contain_qemu_config('migration_port_max').with_value(61200) + end end end diff --git a/spec/unit/type/libvirtd_config_spec.rb b/spec/unit/type/libvirtd_config_spec.rb index 2caaeea66..bb82b062d 100644 --- a/spec/unit/type/libvirtd_config_spec.rb +++ b/spec/unit/type/libvirtd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:libvirtd_config)' do expect(@libvirtd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @libvirtd_config[:value] = true + expect(@libvirtd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @libvirtd_config[:value] = false + expect(@libvirtd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') diff --git a/spec/unit/type/qemu_config_spec.rb b/spec/unit/type/qemu_config_spec.rb new file mode 100644 index 000000000..453479a55 --- /dev/null +++ b/spec/unit/type/qemu_config_spec.rb @@ -0,0 +1,34 @@ +require 'puppet' +require 'puppet/type/qemu_config' + +describe 'Puppet::Type.type(:qemu_config)' do + before :each do + @qemu_config = Puppet::Type.type(:qemu_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should accept a valid value' do + @qemu_config[:value] = 'bar' + expect(@qemu_config[:value]).to eq('bar') + end + + it 'should accept a valid value' do + @qemu_config[:value] = 'bar' + expect(@qemu_config[:value]).to eq('bar') + end + + it 'should convert a boolean value (true)' do + @qemu_config[:value] = true + expect(@qemu_config[:value]).to eq('1') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') + catalog.add_resource anchor, @qemu_config + dependency = @qemu_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@qemu_config) + expect(dependency[0].source).to eq(anchor) + end + +end diff --git a/spec/unit/type/virtlockd_config_spec.rb b/spec/unit/type/virtlockd_config_spec.rb index a76744533..fff5ea203 100644 --- a/spec/unit/type/virtlockd_config_spec.rb +++ b/spec/unit/type/virtlockd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:virtlockd_config)' do expect(@virtlockd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @virtlockd_config[:value] = true + expect(@virtlockd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @virtlockd_config[:value] = false + expect(@virtlockd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') diff --git a/spec/unit/type/virtlogd_config_spec.rb b/spec/unit/type/virtlogd_config_spec.rb index ba98ce964..20407d7a1 100644 --- a/spec/unit/type/virtlogd_config_spec.rb +++ b/spec/unit/type/virtlogd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:virtlogd_config)' do expect(@virtlogd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @virtlogd_config[:value] = true + expect(@virtlogd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @virtlogd_config[:value] = false + expect(@virtlogd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') diff --git a/spec/unit/type/virtnodedevd_config_spec.rb b/spec/unit/type/virtnodedevd_config_spec.rb index 5d4b1d029..7dd54a8a3 100644 --- a/spec/unit/type/virtnodedevd_config_spec.rb +++ b/spec/unit/type/virtnodedevd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:virtnodedevd_config)' do expect(@virtnodedevd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @virtnodedevd_config[:value] = true + expect(@virtnodedevd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @virtnodedevd_config[:value] = false + expect(@virtnodedevd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') diff --git a/spec/unit/type/virtproxyd_config_spec.rb b/spec/unit/type/virtproxyd_config_spec.rb index c1133ff59..6efa3c043 100644 --- a/spec/unit/type/virtproxyd_config_spec.rb +++ b/spec/unit/type/virtproxyd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:virtproxyd_config)' do expect(@virtproxyd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @virtproxyd_config[:value] = true + expect(@virtproxyd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @virtproxyd_config[:value] = false + expect(@virtproxyd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end') diff --git a/spec/unit/type/virtsecretd_config_spec.rb b/spec/unit/type/virtsecretd_config_spec.rb index 9ced06334..c66893a86 100644 --- a/spec/unit/type/virtsecretd_config_spec.rb +++ b/spec/unit/type/virtsecretd_config_spec.rb @@ -11,6 +11,16 @@ describe 'Puppet::Type.type(:virtsecretd_config)' do expect(@virtsecretd_config[:value]).to eq('bar') end + it 'should convert a boolean value (true)' do + @virtsecretd_config[:value] = true + expect(@virtsecretd_config[:value]).to eq('1') + end + + it 'should convert a boolean value (false)' do + @virtsecretd_config[:value] = false + expect(@virtsecretd_config[:value]).to eq('0') + end + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end')