Browse Source

Add support for MultiStrOpt

This replaces the provider implementation of glance_api_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: I6c0ea1276d16722c9908a20333890a4a17404b61
changes/52/790052/5
Takashi Kajinami 1 month ago
parent
commit
10872d13eb
4 changed files with 66 additions and 16 deletions
  1. +2
    -2
      lib/puppet/provider/glance_api_config/openstackconfig.rb
  2. +10
    -2
      lib/puppet/type/glance_api_config.rb
  3. +9
    -12
      spec/unit/provider/glance_api_config/openstackconfig_spec.rb
  4. +45
    -0
      spec/unit/type/glance_api_config_spec.rb

lib/puppet/provider/glance_api_config/ini_setting.rb → lib/puppet/provider/glance_api_config/openstackconfig.rb View File


+ 10
- 2
lib/puppet/type/glance_api_config.rb View File

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


spec/unit/provider/glance_api_config/ini_setting_spec.rb → spec/unit/provider/glance_api_config/openstackconfig_spec.rb View File


+ 45
- 0
spec/unit/type/glance_api_config_spec.rb View File

@ -6,6 +6,51 @@ describe 'Puppet::Type.type(:glance_api_config)' do
@glance_api_config = Puppet::Type.type(:glance_api_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:glance_api_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:glance_api_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:glance_api_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:glance_api_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@glance_api_config[:value] = 'bar'
expect(@glance_api_config[:value]).to eq(['bar'])
end
it 'should not accept a value with whitespace' do
@glance_api_config[:value] = 'b ar'
expect(@glance_api_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@glance_api_config[:ensure] = :present
expect(@glance_api_config[:ensure]).to eq(:present)
@glance_api_config[:ensure] = :absent
expect(@glance_api_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@glance_api_config[:ensure] = :latest
}.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 => 'glance::install::end')


Loading…
Cancel
Save