Updates on config provider

* Use openstack_config
* Autorequire the package in the type
* Update unit tests

Change-Id: I14b9c1a69c19fc4f825f99ccabb876df6bffe59e
This commit is contained in:
Emilien Macchi 2015-09-30 09:53:06 -04:00
parent 128a19999c
commit b416f9c681
4 changed files with 56 additions and 19 deletions

View File

@ -1,27 +1,10 @@
Puppet::Type.type(:{{cookiecutter.project_name}}_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/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}.conf'
end
# added for backwards compatibility with older versions of inifile
def file_path
self.class.file_path
end
end

View File

@ -3,7 +3,7 @@ Puppet::Type.newtype(:{{cookiecutter.project_name}}_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}.conf'
desc 'Section/setting name to manage from {{cookiecutter.project_name}}.conf'
newvalues(/\S+\/\S+/)
end
@ -14,6 +14,7 @@ Puppet::Type.newtype(:{{cookiecutter.project_name}}_config) do
value.capitalize! if value =~ /^(true|false)$/i
value
end
newvalues(/^[\S ]*$/)
def is_to_s( currentvalue )
if resource.secret?
@ -39,4 +40,14 @@ Puppet::Type.newtype(:{{cookiecutter.project_name}}_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
'{{cookiecutter.project_name}}'
end
end

View File

@ -1,3 +1,4 @@
#
# 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.
@ -13,6 +14,17 @@ $LOAD_PATH.push(
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:{{cookiecutter.project_name}}_config).provider(:ini_setting)
describe provider_class do
@ -34,4 +46,23 @@ describe provider_class do
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::{{cookiecutter.project_name|capitalize}}_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::{{cookiecutter.project_name|capitalize}}_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

@ -49,4 +49,16 @@ describe 'Puppet::Type.type(:{{cookiecutter.project_name}}_config)' do
@{{cookiecutter.project_name}}_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
package = Puppet::Type.type(:package).new(:name => '{{cookiecutter.project_name}}-common')
catalog.add_resource package, @{{cookiecutter.project_name}}_config
dependency = @{{cookiecutter.project_name}}_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@{{cookiecutter.project_name}}_config)
expect(dependency[0].source).to eq(package)
end
end