From 54eea2b3e8c0ddd052f7dfbe2ea46461f87b51bc Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 13 Jul 2021 18:05:48 +0900 Subject: [PATCH] Add support for MultiStrOpt This replaces the provider implementation of octavia_config type so that MultiStrOpt, which is used by several options like - oslo_messaging_notifications/driver - oslo_policy/policy_dirs are handled correctly. Change-Id: Ic8da2858b4c512d31ebbf78a128367d152cf7616 --- .../{ini_setting.rb => openstackconfig.rb} | 4 ++-- lib/puppet/type/octavia_config.rb | 12 ++++++++++-- .../{ini_setting_spec.rb => openstackconfig_spec.rb} | 4 ++-- spec/unit/type/octavia_config_spec.rb | 8 ++++---- 4 files changed, 18 insertions(+), 10 deletions(-) rename lib/puppet/provider/octavia_config/{ini_setting.rb => openstackconfig.rb} (56%) rename spec/unit/provider/octavia_config/{ini_setting_spec.rb => openstackconfig_spec.rb} (91%) diff --git a/lib/puppet/provider/octavia_config/ini_setting.rb b/lib/puppet/provider/octavia_config/openstackconfig.rb similarity index 56% rename from lib/puppet/provider/octavia_config/ini_setting.rb rename to lib/puppet/provider/octavia_config/openstackconfig.rb index 03353bee..03c23a2c 100644 --- a/lib/puppet/provider/octavia_config/ini_setting.rb +++ b/lib/puppet/provider/octavia_config/openstackconfig.rb @@ -1,6 +1,6 @@ Puppet::Type.type(:octavia_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/octavia_config.rb b/lib/puppet/type/octavia_config.rb index 9e0977b2..113c1388 100644 --- a/lib/puppet/type/octavia_config.rb +++ b/lib/puppet/type/octavia_config.rb @@ -7,14 +7,22 @@ Puppet::Type.newtype(:octavia_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/octavia_config/ini_setting_spec.rb b/spec/unit/provider/octavia_config/openstackconfig_spec.rb similarity index 91% rename from spec/unit/provider/octavia_config/ini_setting_spec.rb rename to spec/unit/provider/octavia_config/openstackconfig_spec.rb index fbc970c2..312acb4c 100644 --- a/spec/unit/provider/octavia_config/ini_setting_spec.rb +++ b/spec/unit/provider/octavia_config/openstackconfig_spec.rb @@ -2,7 +2,7 @@ # 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 +# I could not, for the life of me, figure out how to programmatically set the modulepath $LOAD_PATH.push( File.join( File.dirname(__FILE__), @@ -26,7 +26,7 @@ $LOAD_PATH.push( 'lib') ) require 'spec_helper' -provider_class = Puppet::Type.type(:octavia_config).provider(:ini_setting) +provider_class = Puppet::Type.type(:octavia_config).provider(:openstackconfig) describe provider_class do it 'should default to the default setting when no other one is specified' do diff --git a/spec/unit/type/octavia_config_spec.rb b/spec/unit/type/octavia_config_spec.rb index 90d29552..44cef141 100644 --- a/spec/unit/type/octavia_config_spec.rb +++ b/spec/unit/type/octavia_config_spec.rb @@ -1,5 +1,6 @@ require 'puppet' require 'puppet/type/octavia_config' + describe 'Puppet::Type.type(:octavia_config)' do before :each do @octavia_config = Puppet::Type.type(:octavia_config).new(:name => 'DEFAULT/foo', :value => 'bar') @@ -29,12 +30,12 @@ describe 'Puppet::Type.type(:octavia_config)' do it 'should accept a valid value' do @octavia_config[:value] = 'bar' - expect(@octavia_config[:value]).to eq('bar') + expect(@octavia_config[:value]).to eq(['bar']) end it 'should not accept a value with whitespace' do @octavia_config[:value] = 'b ar' - expect(@octavia_config[:value]).to eq('b ar') + expect(@octavia_config[:value]).to eq(['b ar']) end it 'should accept valid ensure values' do @@ -50,7 +51,7 @@ describe 'Puppet::Type.type(:octavia_config)' do }.to raise_error(Puppet::Error, /Invalid value/) end - it 'should autorequire the anchor that install the file' do + it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new anchor = Puppet::Type.type(:anchor).new(:name => 'octavia::install::end') catalog.add_resource anchor, @octavia_config @@ -60,5 +61,4 @@ describe 'Puppet::Type.type(:octavia_config)' do expect(dependency[0].source).to eq(anchor) end - end