Support virtlockd configurations

... so that this module supports configuration of all libvirt daemons.

Change-Id: I93a02935df3a23e15b4a37081dc2a6ea646f6c79
(cherry picked from commit 5242d3a08b)
This commit is contained in:
Takashi Kajinami 2022-04-19 08:31:45 +09:00
parent 74dd92f930
commit a0df16f5bd
9 changed files with 341 additions and 0 deletions

View File

@ -0,0 +1,37 @@
Puppet::Type.type(:virtlockd_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
def exists?
if resource[:value] == ensure_absent_val
resource[:ensure] = :absent
elsif resource[:quote]
unless resource[:value].start_with?('"')
resource[:value] = '"' + resource[:value] + '"'
end
end
super
end
def section
''
end
def setting
resource[:name]
end
def separator
'='
end
def ensure_absent_val
resource[:ensure_absent_val]
end
def self.file_path
'/etc/libvirt/virtlockd.conf'
end
end

View File

@ -0,0 +1,57 @@
Puppet::Type.newtype(:virtlockd_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'setting name to manage from virtlockd.conf'
newvalues(/\S+/)
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
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('<SERVICE DEFAULT>')
end
autorequire(:anchor) do
['nova::install::end']
end
end

View File

@ -21,6 +21,10 @@
# (optional) Allow configuration of arbitrary virtlogd configurations.
# The value is an hash of virtlogd_config resources.
#
# [*virtlockd_config*]
# (optional) Allow configuration of arbitrary virtlockd configurations.
# The value is an hash of virtlockd_config resources.
#
# [*virtnodedevd_config*]
# (optional) Allow configuration of arbitrary virtnodedevd configurations.
# The value is an hash of virtnodedevd_config resources.
@ -47,6 +51,7 @@
class nova::compute::libvirt::config (
$libvirtd_config = {},
$virtlogd_config = {},
$virtlockd_config = {},
$virtnodedevd_config = {},
$virtproxyd_config = {},
$virtqemud_config = {},
@ -58,6 +63,7 @@ class nova::compute::libvirt::config (
validate_legacy(Hash, 'validate_hash', $libvirtd_config)
validate_legacy(Hash, 'validate_hash', $virtlogd_config)
validate_legacy(Hash, 'validate_hash', $virtlockd_config)
validate_legacy(Hash, 'validate_hash', $virtnodedevd_config)
validate_legacy(Hash, 'validate_hash', $virtproxyd_config)
validate_legacy(Hash, 'validate_hash', $virtqemud_config)
@ -66,6 +72,7 @@ class nova::compute::libvirt::config (
create_resources('libvirtd_config', $libvirtd_config)
create_resources('virtlogd_config', $virtlogd_config)
create_resources('virtlockd_config', $virtlockd_config)
create_resources('virtnodedevd_config', $virtnodedevd_config)
create_resources('virtproxyd_config', $virtproxyd_config)
create_resources('virtqemud_config', $virtqemud_config)

View File

@ -0,0 +1,65 @@
# == Class: nova::compute::libvirt::virtlockd
#
# virtlockd configuration
#
# === Parameters:
#
# [*log_level*]
# Defines a log level to filter log outputs.
# Defaults to $::os_service_default
#
# [*log_filters*]
# Defines a log filter to select a different logging level for
# for a given category log outputs.
# Defaults to $::os_service_default
#
# [*log_outputs*]
# (optional) Defines log outputs, as specified in
# https://libvirt.org/logging.html
# Defaults to $::os_service_default
#
# [*max_clients*]
# The maximum number of concurrent client connections to allow
# on primary socket.
# Defaults to $::os_service_default
#
# [*admin_max_clients*]
# The maximum number of concurrent client connections to allow
# on administrative socket.
# Defaults to $::os_service_default
#
# [*max_size*]
# Maximum file size before rolling over.
# Defaults to $::os_service_default
#
# [*max_backups*]
# Maximum nuber of backup files to keep.
# Defaults to $::os_service_default
#
class nova::compute::libvirt::virtlockd (
$log_level = $::os_service_default,
$log_filters = $::os_service_default,
$log_outputs = $::os_service_default,
$max_clients = $::os_service_default,
$admin_max_clients = $::os_service_default,
$max_size = $::os_service_default,
$max_backups = $::os_service_default,
) {
include nova::deps
require nova::compute::libvirt
virtlockd_config {
'log_level': value => pick($log_level, $::os_service_default);
'log_filters': value => pick($log_filters, $::os_service_default), quote => true;
'log_outputs': value => pick($log_outputs, $::os_service_default), quote => true;
'max_clients': value => pick($max_clients, $::os_service_default);
'admin_max_clients': value => pick($admin_max_clients, $::os_service_default);
'max_size': value => pick($max_size, $::os_service_default);
'max_backups': value => pick($max_backups, $::os_service_default);
}
Anchor['nova::config::begin']
-> Virtlockd_config<||>
-> Anchor['nova::config::end']
}

View File

@ -0,0 +1,4 @@
---
features:
- |
Now this module supports configuration of the ``virtlockd`` service.

View File

@ -13,6 +13,11 @@ describe 'nova::compute::libvirt::config' do
'foo2' => { 'value' => 'fooValue' },
'bar2' => { 'value' => 'barValue' },
'baz2' => { 'ensure' => 'absent' }
},
:virtlockd_config => {
'foo3' => { 'value' => 'fooValue' },
'bar3' => { 'value' => 'barValue' },
'baz3' => { 'ensure' => 'absent' }
}
}
end
@ -31,6 +36,12 @@ describe 'nova::compute::libvirt::config' do
should contain_virtlogd_config('bar2').with_value('barValue')
should contain_virtlogd_config('baz2').with_ensure('absent')
}
it {
should contain_virtlockd_config('foo3').with_value('fooValue')
should contain_virtlockd_config('bar3').with_value('barValue')
should contain_virtlockd_config('baz3').with_ensure('absent')
}
end
end

View File

@ -0,0 +1,67 @@
# Unit tests for nova::compute::libvirt::virtlockd class
#
require 'spec_helper'
describe 'nova::compute::libvirt::virtlockd' do
let :pre_condition do
<<-eos
include nova
include nova::compute
include nova::compute::libvirt
eos
end
shared_examples_for 'nova-compute-libvirt-virtlockd' do
context 'with default parameters' do
let :params do
{}
end
it { is_expected.to contain_class('nova::deps')}
it { is_expected.to contain_class('nova::compute::libvirt::virtlockd')}
it { is_expected.to contain_virtlockd_config('log_level').with_value('<SERVICE DEFAULT>')}
it { is_expected.to contain_virtlockd_config('log_outputs').with_value('<SERVICE DEFAULT>').with_quote(true)}
it { is_expected.to contain_virtlockd_config('log_filters').with_value('<SERVICE DEFAULT>').with_quote(true)}
it { is_expected.to contain_virtlockd_config('max_clients').with_value('<SERVICE DEFAULT>')}
it { is_expected.to contain_virtlockd_config('admin_max_clients').with_value('<SERVICE DEFAULT>')}
end
context 'with specified parameters' do
let :params do
{ :log_level => 3,
:log_outputs => '3:syslog',
:log_filters => '1:logging 4:object 4:json 4:event 1:util',
:max_clients => 1024,
:admin_max_clients => 5,
:max_size => 2097152,
:max_backups => 3,
}
end
it { is_expected.to contain_class('nova::deps')}
it { is_expected.to contain_class('nova::compute::libvirt::virtlockd')}
it { is_expected.to contain_virtlockd_config('log_level').with_value(params[:log_level])}
it { is_expected.to contain_virtlockd_config('log_outputs').with_value(params[:log_outputs]).with_quote(true)}
it { is_expected.to contain_virtlockd_config('log_filters').with_value(params[:log_filters]).with_quote(true)}
it { is_expected.to contain_virtlockd_config('max_clients').with_value(params[:max_clients])}
it { is_expected.to contain_virtlockd_config('admin_max_clients').with_value(params[:admin_max_clients])}
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'nova-compute-libvirt-virtlockd'
end
end
end

View File

@ -0,0 +1,69 @@
#
# these tests are a little concerning b/c they are hacking around the
# modulepath, so these tests will not catch issues that may eventually arise
# related to loading these plugins.
# I could not, for the life of me, figure out how to programatcally set the modulepath
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:virtlockd_config).provider(:ini_setting)
describe provider_class do
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Virtlockd_config.new(
{:name => 'foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('')
expect(provider.setting).to eq('foo')
end
it 'should quote the value when quote is true' do
resource = Puppet::Type::Virtlockd_config.new(
{:name => 'foo', :value => 'baa', :quote => true }
)
provider = provider_class.new(resource)
provider.exists?
expect(provider.section).to eq('')
expect(provider.setting).to eq('foo')
expect(resource[:value]).to eq('"baa"')
end
it 'should not quote the value when quote is true but the value is quoted' do
resource = Puppet::Type::Virtlockd_config.new(
{:name => 'foo', :value => '"baa"', :quote => true }
)
provider = provider_class.new(resource)
provider.exists?
expect(provider.section).to eq('')
expect(provider.setting).to eq('foo')
expect(resource[:value]).to eq('"baa"')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Virtlockd_config.new(
{:name => 'foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value and quote is true' do
resource = Puppet::Type::Virtlockd_config.new(
{:name => 'foo', :value => '<SERVICE DEFAULT>', :quote => true}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,24 @@
require 'puppet'
require 'puppet/type/virtlockd_config'
describe 'Puppet::Type.type(:virtlockd_config)' do
before :each do
@virtlockd_config = Puppet::Type.type(:virtlockd_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should accept a valid value' do
@virtlockd_config[:value] = 'bar'
expect(@virtlockd_config[:value]).to eq('bar')
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, @virtlockd_config
dependency = @virtlockd_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@virtlockd_config)
expect(dependency[0].source).to eq(anchor)
end
end