Reflect provider change in puppet-openstacklib

With the creation of the new openstack_config provider, some processing
that was done in keystone_config has been centralized in
openstack_config.

Impacted methods are :

  * section
  * setting
  * separator

Also, this commit adds the fact that, when passing a specific string
(ensure_absent_val) the provider will behave as if ensure => absent was
specified. '<SERVICE DEFAULT>' is the default value for
ensure_absent_val.

The use case is the following :

keystone_config { 'DEFAULT/foo' : value => 'bar' } # will work as usual

keystone_config { 'DEFAULT/foo' : value => '<SERVICE DEFAULT>' } # will mean absent

That means that all the current :

if $myvar {
  keystone_config { 'DEFAULT/foo' : value => $myvar }
} else {
  keystone_config { 'DEFAULT/foo' : ensure => absent }
}

can be removed in favor of :

keystone_config { 'DEFAULT/foo' : value => $myvar }

If for any reason '<SERVICE DEFAULT>' turns out to be a valid value for
a specific parameter. One could by pass that doing the following :

keystone_config { 'DEFAULT/foo' : value => '<SERVICE DEFAULT>',
ensure_absent_val => 'foo' }

Change-Id: I7c880518f0323e44e7c72f0ff5548482a0b1413c
Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218
This commit is contained in:
Yanis Guenane 2015-07-16 13:41:27 +02:00
parent 3294e1dfaf
commit d686122ce7
4 changed files with 54 additions and 18 deletions

View File

@ -138,6 +138,36 @@ Implementation
keystone is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers.
### Types
#### keystone_config
The `keystone_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/keystone/keystone.conf` file.
```puppet
keystone_config { 'DEFAULT/verbose' :
value => true,
}
```
This will write `verbose=true` in the `[DEFAULT]` section.
##### name
Section/setting name to manage from `keystone.conf`
##### value
The value of the setting to be defined.
##### secret
Whether to hide the value from Puppet logs. Defaults to `false`.
##### ensure_absent_val
If value is equal to ensure_absent_val then the resource will behave as if `ensure => absent` was specified. Defaults to `<SERVICE DEFAULT>`
Limitations
------------

View File

@ -1,27 +1,10 @@
Puppet::Type.type(:keystone_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def separator
'='
end
def self.file_path
'/etc/keystone/keystone.conf'
end
# added for backwards compatibility with older versions of inifile
def file_path
self.class.file_path
end
end

View File

@ -41,6 +41,11 @@ Puppet::Type.newtype(:keystone_config) do
defaultto false
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'keystone'
end

View File

@ -36,4 +36,22 @@ describe provider_class do
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Keystone_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::Keystone_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