Add support for MultiStrOpt

This replaces the provider implementation of cloudkitty_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: Iefdfa5b83cb1f5ff691cc38e0f691babac9bdfb0
This commit is contained in:
Takashi Kajinami
2022-02-13 00:12:05 +09:00
parent 3c3dc10c81
commit b13a35dd3a
4 changed files with 15 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
Puppet::Type.type(:cloudkitty_config).provide( Puppet::Type.type(:cloudkitty_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

@@ -7,14 +7,22 @@ Puppet::Type.newtype(:cloudkitty_config) do
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,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
provider_class = Puppet::Type.type(:cloudkitty_config).provider(:ini_setting) provider_class = Puppet::Type.type(:cloudkitty_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

View File

@@ -29,12 +29,12 @@ describe 'Puppet::Type.type(:cloudkitty_config)' do
it 'should accept a valid value' do it 'should accept a valid value' do
@cloudkitty_config[:value] = 'bar' @cloudkitty_config[:value] = 'bar'
expect(@cloudkitty_config[:value]).to eq('bar') expect(@cloudkitty_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
@cloudkitty_config[:value] = 'b ar' @cloudkitty_config[:value] = 'b ar'
expect(@cloudkitty_config[:value]).to eq('b ar') expect(@cloudkitty_config[:value]).to eq(['b ar'])
end end
it 'should accept valid ensure values' do it 'should accept valid ensure values' do