Add support for rootwrap.conf

Change-Id: I2a6f5c4c6a185c1bf71c4136dee425afdfc0ce56
This commit is contained in:
Takashi Kajinami 2021-12-27 12:05:35 +09:00
parent 6bdf24f750
commit ddeb43dacc
7 changed files with 167 additions and 1 deletions

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:ceilometer_rootwrap_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/ceilometer/rootwrap.conf'
end
end

View File

@ -0,0 +1,29 @@
Puppet::Type.newtype(:ceilometer_rootwrap_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/ceilometer/rootwrap.conf'
newvalues(/\S+\/\S+/)
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
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
newvalues(/^[\S ]*$/)
end
autorequire(:anchor) do
['ceilometer::install::end']
end
end

View File

@ -19,17 +19,23 @@
# DEFAULT/bar:
# value: barValue
#
# [*ceilometer_rootwrap_config*]
# (optional) Allow configuration of rootwrap.conf.
#
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
class ceilometer::config (
$ceilometer_config = {},
$ceilometer_config = {},
$ceilometer_rootwrap_config = {},
) {
include ceilometer::deps
validate_legacy(Hash, 'validate_hash', $ceilometer_config)
validate_legacy(Hash, 'validate_hash', $ceilometer_rootwrap_config)
create_resources('ceilometer_config', $ceilometer_config)
create_resources('ceilometer_rootwrap_config', $ceilometer_rootwrap_config)
}

View File

@ -39,6 +39,11 @@ class ceilometer::deps {
# before dbsync starts
Oslo::Db<||> -> Anchor['ceilometer::dbsync::begin']
# rootwrap config should occur in the config block also.
Anchor['ceilometer::config::begin']
-> Ceilometer_rootwrap_config<||>
~> Anchor['ceilometer::config::end']
# Ensure files are modified in the config block
Anchor['ceilometer::config::begin']
-> File<| tag == 'ceilometer-yamls' |>

View File

@ -0,0 +1,10 @@
---
features:
- |
The new ``ceilometer_rootwrap_config`` resource has been added. This
resource can be used to manage contents of ``rootwrap.conf``
- |
The new ``ceilometer::config::ceilometer_rootwrap_config`` parameter has
been added. This parameter accepts arbitrary configuration of
``rootwrap.conf``.

View File

@ -0,0 +1,42 @@
require 'spec_helper'
provider_class = Puppet::Type.type(:ceilometer_rootwrap_config).provider(:ini_setting)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Ceilometer_rootwrap_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Ceilometer_rootwrap_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Ceilometer_rootwrap_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Ceilometer_rootwrap_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,64 @@
require 'puppet'
require 'puppet/type/ceilometer_rootwrap_config'
describe 'Puppet::Type.type(:ceilometer_rootwrap_config)' do
before :each do
@ceilometer_rootwrap_config = Puppet::Type.type(:ceilometer_rootwrap_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:ceilometer_rootwrap_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:ceilometer_rootwrap_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:ceilometer_rootwrap_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:ceilometer_rootwrap_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@ceilometer_rootwrap_config[:value] = 'bar'
expect(@ceilometer_rootwrap_config[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@ceilometer_rootwrap_config[:value] = 'b ar'
expect(@ceilometer_rootwrap_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@ceilometer_rootwrap_config[:ensure] = :present
expect(@ceilometer_rootwrap_config[:ensure]).to eq(:present)
@ceilometer_rootwrap_config[:ensure] = :absent
expect(@ceilometer_rootwrap_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@ceilometer_rootwrap_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'ceilometer::install::end')
catalog.add_resource anchor, @ceilometer_rootwrap_config
dependency = @ceilometer_rootwrap_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@ceilometer_rootwrap_config)
expect(dependency[0].source).to eq(anchor)
end
end