Add support for MultiStrOpt

This replaces the provider implementation of aodh_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: I4baeeb5f8f65743a3edc01db69909cec5cd9b8e6
This commit is contained in:
Takashi Kajinami 2021-12-27 13:23:07 +09:00
parent f90f915599
commit 700c7dac77
16 changed files with 426 additions and 19 deletions

View File

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

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

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

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

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

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

@ -7,14 +7,22 @@ Puppet::Type.newtype(:trove_taskmanager_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?
@ -46,4 +54,7 @@ Puppet::Type.newtype(:trove_taskmanager_config) do
defaultto('<SERVICE DEFAULT>')
end
autorequire(:anchor) do
['trove::install::end']
end
end

View File

@ -0,0 +1,67 @@
# 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
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:trove_conductor_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Trove_conductor_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Trove_conductor_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Trove_conductor_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Trove_conductor_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -25,7 +25,7 @@ $LOAD_PATH.push(
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:trove_config).provider(:ini_setting)
provider_class = Puppet::Type.type(:trove_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do

View File

@ -0,0 +1,67 @@
# 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
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:trove_guestagent_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Trove_guestagent_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Trove_guestagent_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Trove_guestagent_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Trove_guestagent_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,67 @@
# 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
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:trove_taskmanager_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Trove_taskmanager_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Trove_taskmanager_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Trove_taskmanager_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Trove_taskmanager_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -6,6 +6,51 @@ describe 'Puppet::Type.type(:trove_conductor_config)' do
@trove_conductor_config = Puppet::Type.type(:trove_conductor_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:trove_conductor_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(:trove_conductor_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(:trove_conductor_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(:trove_conductor_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@trove_conductor_config[:value] = 'bar'
expect(@trove_conductor_config[:value]).to eq(['bar'])
end
it 'should not accept a value with whitespace' do
@trove_conductor_config[:value] = 'b ar'
expect(@trove_conductor_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@trove_conductor_config[:ensure] = :present
expect(@trove_conductor_config[:ensure]).to eq(:present)
@trove_conductor_config[:ensure] = :absent
expect(@trove_conductor_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@trove_conductor_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')

View File

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

View File

@ -0,0 +1,63 @@
require 'puppet'
require 'puppet/type/trove_guestagent_config'
describe 'Puppet::Type.type(:trove_guestagent_config)' do
before :each do
@trove_guestagent_config = Puppet::Type.type(:trove_guestagent_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:trove_guestagent_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(:trove_guestagent_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(:trove_guestagent_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(:trove_guestagent_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@trove_guestagent_config[:value] = 'bar'
expect(@trove_guestagent_config[:value]).to eq(['bar'])
end
it 'should not accept a value with whitespace' do
@trove_guestagent_config[:value] = 'b ar'
expect(@trove_guestagent_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@trove_guestagent_config[:ensure] = :present
expect(@trove_guestagent_config[:ensure]).to eq(:present)
@trove_guestagent_config[:ensure] = :absent
expect(@trove_guestagent_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@trove_guestagent_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')
catalog.add_resource anchor, @trove_guestagent_config
dependency = @trove_guestagent_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@trove_guestagent_config)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@ -0,0 +1,63 @@
require 'puppet'
require 'puppet/type/trove_taskmanager_config'
describe 'Puppet::Type.type(:trove_taskmanager_config)' do
before :each do
@trove_taskmanager_config = Puppet::Type.type(:trove_taskmanager_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:trove_taskmanager_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(:trove_taskmanager_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(:trove_taskmanager_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(:trove_taskmanager_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@trove_taskmanager_config[:value] = 'bar'
expect(@trove_taskmanager_config[:value]).to eq(['bar'])
end
it 'should not accept a value with whitespace' do
@trove_taskmanager_config[:value] = 'b ar'
expect(@trove_taskmanager_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@trove_taskmanager_config[:ensure] = :present
expect(@trove_taskmanager_config[:ensure]).to eq(:present)
@trove_taskmanager_config[:ensure] = :absent
expect(@trove_taskmanager_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@trove_taskmanager_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that installs the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'trove::install::end')
catalog.add_resource anchor, @trove_taskmanager_config
dependency = @trove_taskmanager_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@trove_taskmanager_config)
expect(dependency[0].source).to eq(anchor)
end
end