From 6722b8cc463f76f6afd187da558be813fc3f0ca6 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 2 Nov 2021 09:05:25 +0900 Subject: [PATCH] Add support for MultiStrOpt (inspector) This replaces the provider implementation of ironic_inspector_config type so that MultiStrOpt, which is used by several options like - oslo_policy/policy_dirs are handled correctly. The same was already implemented for ironic_config by [1]. [1] 0f4a5263a7f4264f6148e8c04f32992b0b07e1a5 Change-Id: If032600c34394f9f0f3686971082aafeab9be3ea (cherry picked from commit ecdeb8f36575675998e1d3e77fba53fb5ee87e50) (cherry picked from commit 7e1f4200372542e9169c4e18fcf5f557b9e2ce46) --- .../{ini_setting.rb => openstackconfig.rb} | 4 +- lib/puppet/type/ironic_inspector_config.rb | 12 ++++- ...etting_spec.rb => openstackconfig_spec.rb} | 18 ++++---- .../unit/type/ironic_inspector_config_spec.rb | 45 +++++++++++++++++++ 4 files changed, 66 insertions(+), 13 deletions(-) rename lib/puppet/provider/ironic_inspector_config/{ini_setting.rb => openstackconfig.rb} (60%) rename spec/unit/provider/ironic_inspector_config/{ini_setting_spec.rb => openstackconfig_spec.rb} (80%) diff --git a/lib/puppet/provider/ironic_inspector_config/ini_setting.rb b/lib/puppet/provider/ironic_inspector_config/openstackconfig.rb similarity index 60% rename from lib/puppet/provider/ironic_inspector_config/ini_setting.rb rename to lib/puppet/provider/ironic_inspector_config/openstackconfig.rb index fc448160..91689afb 100644 --- a/lib/puppet/provider/ironic_inspector_config/ini_setting.rb +++ b/lib/puppet/provider/ironic_inspector_config/openstackconfig.rb @@ -1,6 +1,6 @@ Puppet::Type.type(:ironic_inspector_config).provide( - :ini_setting, - :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) + :openstackconfig, + :parent => Puppet::Type.type(:openstack_config).provider(:ruby) ) do def self.file_path diff --git a/lib/puppet/type/ironic_inspector_config.rb b/lib/puppet/type/ironic_inspector_config.rb index 69f0be1f..513aa54e 100644 --- a/lib/puppet/type/ironic_inspector_config.rb +++ b/lib/puppet/type/ironic_inspector_config.rb @@ -7,14 +7,22 @@ Puppet::Type.newtype(:ironic_inspector_config) do newvalues(/\S+\/\S+/) end - newproperty(:value) do + newproperty(:value, :array_matching => :all) do desc 'The value of the setting to be defined.' + def insync?(is) + return true if @should.empty? + return false unless is.is_a? Array + return false unless is.length == @should.length + return ( + is & @should == is or + is & @should.map(&:to_s) == is + ) + end munge do |value| value = value.to_s.strip value.capitalize! if value =~ /^(true|false)$/i value end - newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? diff --git a/spec/unit/provider/ironic_inspector_config/ini_setting_spec.rb b/spec/unit/provider/ironic_inspector_config/openstackconfig_spec.rb similarity index 80% rename from spec/unit/provider/ironic_inspector_config/ini_setting_spec.rb rename to spec/unit/provider/ironic_inspector_config/openstackconfig_spec.rb index edf78060..dd94faaf 100644 --- a/spec/unit/provider/ironic_inspector_config/ini_setting_spec.rb +++ b/spec/unit/provider/ironic_inspector_config/openstackconfig_spec.rb @@ -1,3 +1,8 @@ +# +# 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 programmatically set the modulepath $LOAD_PATH.push( File.join( File.dirname(__FILE__), @@ -23,16 +28,13 @@ $LOAD_PATH.push( require 'spec_helper' -provider_class = Puppet::Type.type(:ironic_inspector_config).provider(:ini_setting) +provider_class = Puppet::Type.type(:ironic_inspector_config).provider(:openstackconfig) describe provider_class do it 'should default to the default setting when no other one is specified' do resource = Puppet::Type::Ironic_inspector_config.new( - { - :name => 'DEFAULT/foo', - :value => 'bar' - } + {:name => 'DEFAULT/foo', :value => 'bar'} ) provider = provider_class.new(resource) expect(provider.section).to eq('DEFAULT') @@ -41,10 +43,7 @@ describe provider_class do it 'should allow setting to be set explicitly' do resource = Puppet::Type::Ironic_inspector_config.new( - { - :name => 'dude/foo', - :value => 'bar' - } + {:name => 'dude/foo', :value => 'bar'} ) provider = provider_class.new(resource) expect(provider.section).to eq('dude') @@ -68,4 +67,5 @@ describe provider_class do provider.exists? expect(resource[:ensure]).to eq :absent end + end diff --git a/spec/unit/type/ironic_inspector_config_spec.rb b/spec/unit/type/ironic_inspector_config_spec.rb index 433c21ec..b1c6b397 100644 --- a/spec/unit/type/ironic_inspector_config_spec.rb +++ b/spec/unit/type/ironic_inspector_config_spec.rb @@ -6,6 +6,51 @@ describe 'Puppet::Type.type(:ironic_inspector_config)' do @ironic_inspector_config = Puppet::Type.type(:ironic_inspector_config).new(:name => 'DEFAULT/foo', :value => 'bar') end + it 'should require a name' do + expect { + Puppet::Type.type(:ironic_inspector_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(:ironic_inspector_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(:ironic_inspector_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(:ironic_inspector_config).new(:name => 'DEFAULT/foo', :ensure => :absent) + end + + it 'should accept a valid value' do + @ironic_inspector_config[:value] = 'bar' + expect(@ironic_inspector_config[:value]).to eq(['bar']) + end + + it 'should not accept a value with whitespace' do + @ironic_inspector_config[:value] = 'b ar' + expect(@ironic_inspector_config[:value]).to eq(['b ar']) + end + + it 'should accept valid ensure values' do + @ironic_inspector_config[:ensure] = :present + expect(@ironic_inspector_config[:ensure]).to eq(:present) + @ironic_inspector_config[:ensure] = :absent + expect(@ironic_inspector_config[:ensure]).to eq(:absent) + end + + it 'should not accept invalid ensure values' do + expect { + @ironic_inspector_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 => 'ironic::install::end')