From 870ff626558c0203a4be1ae64e5d31212c0cd80f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 5 May 2021 10:43:00 +0900 Subject: [PATCH] Add support for MultiStrOpt This replaces the provider implementation of cinder_config type so that MultiStrOpt, which is used by several options like - oslo_messaging_notifications/driver - oslo_policy/policy_dirs is handled correctly. Change-Id: If052cde4da84970df4af657136060532ccb422f7 --- .../{ini_setting.rb => openstackconfig.rb} | 4 ++-- lib/puppet/type/cinder_config.rb | 13 ++++++++++-- ...etting_spec.rb => openstackconfig_spec.rb} | 20 ++++++++----------- spec/unit/type/cinder_config_spec.rb | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) rename lib/puppet/provider/cinder_config/{ini_setting.rb => openstackconfig.rb} (55%) rename spec/unit/provider/cinder_config/{ini_setting_spec.rb => openstackconfig_spec.rb} (76%) diff --git a/lib/puppet/provider/cinder_config/ini_setting.rb b/lib/puppet/provider/cinder_config/openstackconfig.rb similarity index 55% rename from lib/puppet/provider/cinder_config/ini_setting.rb rename to lib/puppet/provider/cinder_config/openstackconfig.rb index 749fb16e..e4bdddd4 100644 --- a/lib/puppet/provider/cinder_config/ini_setting.rb +++ b/lib/puppet/provider/cinder_config/openstackconfig.rb @@ -1,6 +1,6 @@ Puppet::Type.type(:cinder_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/cinder_config.rb b/lib/puppet/type/cinder_config.rb index cfe29bb9..4b497b83 100644 --- a/lib/puppet/type/cinder_config.rb +++ b/lib/puppet/type/cinder_config.rb @@ -7,14 +7,22 @@ Puppet::Type.newtype(:cinder_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? @@ -49,4 +57,5 @@ Puppet::Type.newtype(:cinder_config) do autorequire(:anchor) do ['cinder::install::end'] end + end diff --git a/spec/unit/provider/cinder_config/ini_setting_spec.rb b/spec/unit/provider/cinder_config/openstackconfig_spec.rb similarity index 76% rename from spec/unit/provider/cinder_config/ini_setting_spec.rb rename to spec/unit/provider/cinder_config/openstackconfig_spec.rb index b4ebf99d..e1f61d64 100644 --- a/spec/unit/provider/cinder_config/ini_setting_spec.rb +++ b/spec/unit/provider/cinder_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__), @@ -20,19 +25,13 @@ $LOAD_PATH.push( 'openstacklib', 'lib') ) - require 'spec_helper' - -provider_class = Puppet::Type.type(:cinder_config).provider(:ini_setting) - +provider_class = Puppet::Type.type(:cinder_config).provider(:openstackconfig) describe provider_class do it 'should default to the default setting when no other one is specified' do resource = Puppet::Type::Cinder_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 +40,7 @@ describe provider_class do it 'should allow setting to be set explicitly' do resource = Puppet::Type::Cinder_config.new( - { - :name => 'dude/foo', - :value => 'bar' - } + {:name => 'dude/foo', :value => 'bar'} ) provider = provider_class.new(resource) expect(provider.section).to eq('dude') diff --git a/spec/unit/type/cinder_config_spec.rb b/spec/unit/type/cinder_config_spec.rb index 169d38b9..54fb7526 100644 --- a/spec/unit/type/cinder_config_spec.rb +++ b/spec/unit/type/cinder_config_spec.rb @@ -30,12 +30,12 @@ describe 'Puppet::Type.type(:cinder_config)' do it 'should accept a valid value' do @cinder_config[:value] = 'bar' - expect(@cinder_config[:value]).to eq('bar') + expect(@cinder_config[:value]).to eq(['bar']) end it 'should not accept a value with whitespace' do @cinder_config[:value] = 'b ar' - expect(@cinder_config[:value]).to eq('b ar') + expect(@cinder_config[:value]).to eq(['b ar']) end it 'should accept valid ensure values' do