Merge "Add support for MultiStrOpt"

This commit is contained in:
Zuul 2021-06-28 12:08:27 +00:00 committed by Gerrit Code Review
commit 4185722bf7
4 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,6 @@
Puppet::Type.type(:heat_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

View File

@ -7,14 +7,22 @@ Puppet::Type.newtype(:heat_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?

View File

@ -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(:heat_config).provider(:ini_setting)
provider_class = Puppet::Type.type(:heat_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Heat_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::Heat_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 +64,5 @@ describe provider_class do
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -6,7 +6,7 @@ describe 'Puppet::Type.type(:heat_config)' do
@heat_config = Puppet::Type.type(:heat_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
it 'should require a name' do
expect {
Puppet::Type.type(:heat_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
@ -30,12 +30,12 @@ describe 'Puppet::Type.type(:heat_config)' do
it 'should accept a valid value' do
@heat_config[:value] = 'bar'
expect(@heat_config[:value]).to eq('bar')
expect(@heat_config[:value]).to eq(['bar'])
end
it 'should not accept a value with whitespace' do
@heat_config[:value] = 'b ar'
expect(@heat_config[:value]).to eq('b ar')
expect(@heat_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@ -51,7 +51,6 @@ describe 'Puppet::Type.type(:heat_config)' do
}.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 => 'heat::install::end')