Add support for MultiStrOpt

This replaces the provider implementation of gnocchi_config type so
that MultiStrOpt, which is used by several options like
 - oslo_policy/policy_dirs
are handled correctly.

Change-Id: I6a99bd57ad8e3713e824e4394b6fc2125167a768
This commit is contained in:
Takashi Kajinami
2021-07-13 18:02:47 +09:00
parent 30d8282954
commit f41c7d8e78
4 changed files with 19 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
Puppet::Type.type(:gnocchi_config).provide( Puppet::Type.type(:gnocchi_config).provide(
:ini_setting, :openstackconfig,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) :parent => Puppet::Type.type(:openstack_config).provider(:ruby)
) do ) do
def self.file_path def self.file_path

View File

@@ -3,18 +3,26 @@ Puppet::Type.newtype(:gnocchi_config) do
ensurable ensurable
newparam(:name, :namevar => true) do newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/gnocchi/gnocchi.conf' desc 'Section/setting name to manage from gnocchi.conf'
newvalues(/\S+\/\S+/) newvalues(/\S+\/\S+/)
end end
newproperty(:value) do newproperty(:value, :array_matching => :all) do
desc 'The value of the setting to be defined.' 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| munge do |value|
value = value.to_s.strip value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i value.capitalize! if value =~ /^(true|false)$/i
value value
end end
newvalues(/^[\S ]*$/)
def is_to_s( currentvalue ) def is_to_s( currentvalue )
if resource.secret? if resource.secret?

View File

@@ -1,7 +1,8 @@
#
# these tests are a little concerning b/c they are hacking around the # 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 # modulepath, so these tests will not catch issues that may eventually arise
# related to loading these plugins. # 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( $LOAD_PATH.push(
File.join( File.join(
File.dirname(__FILE__), File.dirname(__FILE__),
@@ -25,7 +26,7 @@ $LOAD_PATH.push(
'lib') 'lib')
) )
require 'spec_helper' require 'spec_helper'
provider_class = Puppet::Type.type(:gnocchi_config).provider(:ini_setting) provider_class = Puppet::Type.type(:gnocchi_config).provider(:openstackconfig)
describe provider_class do describe provider_class do
it 'should default to the default setting when no other one is specified' do it 'should default to the default setting when no other one is specified' do
@@ -63,4 +64,5 @@ describe provider_class do
provider.exists? provider.exists?
expect(resource[:ensure]).to eq :absent expect(resource[:ensure]).to eq :absent
end end
end end

View File

@@ -30,12 +30,12 @@ describe 'Puppet::Type.type(:gnocchi_config)' do
it 'should accept a valid value' do it 'should accept a valid value' do
@gnocchi_config[:value] = 'bar' @gnocchi_config[:value] = 'bar'
expect(@gnocchi_config[:value]).to eq('bar') expect(@gnocchi_config[:value]).to eq(['bar'])
end end
it 'should not accept a value with whitespace' do it 'should not accept a value with whitespace' do
@gnocchi_config[:value] = 'b ar' @gnocchi_config[:value] = 'b ar'
expect(@gnocchi_config[:value]).to eq('b ar') expect(@gnocchi_config[:value]).to eq(['b ar'])
end end
it 'should accept valid ensure values' do it 'should accept valid ensure values' do