From ddeb43dacc61a4181a5420365f1803d7cbb055c8 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 27 Dec 2021 12:05:35 +0900 Subject: [PATCH] Add support for rootwrap.conf Change-Id: I2a6f5c4c6a185c1bf71c4136dee425afdfc0ce56 --- .../ceilometer_rootwrap_config/ini_setting.rb | 10 +++ lib/puppet/type/ceilometer_rootwrap_config.rb | 29 +++++++++ manifests/config.pp | 8 ++- manifests/deps.pp | 5 ++ .../notes/rootwrap-544101dc45c1220b.yaml | 10 +++ .../ini_setting_spec.rb | 42 ++++++++++++ .../type/ceilometer_rootwrap_config_spec.rb | 64 +++++++++++++++++++ 7 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 lib/puppet/provider/ceilometer_rootwrap_config/ini_setting.rb create mode 100644 lib/puppet/type/ceilometer_rootwrap_config.rb create mode 100644 releasenotes/notes/rootwrap-544101dc45c1220b.yaml create mode 100644 spec/unit/provider/ceilometer_rootwrap_config/ini_setting_spec.rb create mode 100644 spec/unit/type/ceilometer_rootwrap_config_spec.rb diff --git a/lib/puppet/provider/ceilometer_rootwrap_config/ini_setting.rb b/lib/puppet/provider/ceilometer_rootwrap_config/ini_setting.rb new file mode 100644 index 00000000..d7f643af --- /dev/null +++ b/lib/puppet/provider/ceilometer_rootwrap_config/ini_setting.rb @@ -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 diff --git a/lib/puppet/type/ceilometer_rootwrap_config.rb b/lib/puppet/type/ceilometer_rootwrap_config.rb new file mode 100644 index 00000000..2ead36fa --- /dev/null +++ b/lib/puppet/type/ceilometer_rootwrap_config.rb @@ -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('') + 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 diff --git a/manifests/config.pp b/manifests/config.pp index cf1d5b70..e884144a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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) } diff --git a/manifests/deps.pp b/manifests/deps.pp index 50c2fb64..7cff5ff0 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -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' |> diff --git a/releasenotes/notes/rootwrap-544101dc45c1220b.yaml b/releasenotes/notes/rootwrap-544101dc45c1220b.yaml new file mode 100644 index 00000000..c34e6f94 --- /dev/null +++ b/releasenotes/notes/rootwrap-544101dc45c1220b.yaml @@ -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``. diff --git a/spec/unit/provider/ceilometer_rootwrap_config/ini_setting_spec.rb b/spec/unit/provider/ceilometer_rootwrap_config/ini_setting_spec.rb new file mode 100644 index 00000000..d11d177a --- /dev/null +++ b/spec/unit/provider/ceilometer_rootwrap_config/ini_setting_spec.rb @@ -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 is specified as a value' do + resource = Puppet::Type::Ceilometer_rootwrap_config.new( + {:name => 'dude/foo', :value => ''} + ) + 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 diff --git a/spec/unit/type/ceilometer_rootwrap_config_spec.rb b/spec/unit/type/ceilometer_rootwrap_config_spec.rb new file mode 100644 index 00000000..90743338 --- /dev/null +++ b/spec/unit/type/ceilometer_rootwrap_config_spec.rb @@ -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