diff --git a/puppet-{{cookiecutter.project_name}}/lib/puppet/provider/{{cookiecutter.project_name}}_config/ini_setting.rb b/puppet-{{cookiecutter.project_name}}/lib/puppet/provider/{{cookiecutter.project_name}}_config/ini_setting.rb index d683ab2..e7208a4 100644 --- a/puppet-{{cookiecutter.project_name}}/lib/puppet/provider/{{cookiecutter.project_name}}_config/ini_setting.rb +++ b/puppet-{{cookiecutter.project_name}}/lib/puppet/provider/{{cookiecutter.project_name}}_config/ini_setting.rb @@ -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 diff --git a/puppet-{{cookiecutter.project_name}}/lib/puppet/type/{{cookiecutter.project_name}}_config.rb b/puppet-{{cookiecutter.project_name}}/lib/puppet/type/{{cookiecutter.project_name}}_config.rb index 25e9490..7299c27 100644 --- a/puppet-{{cookiecutter.project_name}}/lib/puppet/type/{{cookiecutter.project_name}}_config.rb +++ b/puppet-{{cookiecutter.project_name}}/lib/puppet/type/{{cookiecutter.project_name}}_config.rb @@ -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('') + end + + autorequire(:package) do + '{{cookiecutter.project_name}}' + end + end diff --git a/puppet-{{cookiecutter.project_name}}/spec/unit/provider/{{cookiecutter.project_name}}_config/ini_setting_spec.rb b/puppet-{{cookiecutter.project_name}}/spec/unit/provider/{{cookiecutter.project_name}}_config/ini_setting_spec.rb index 47d8679..8ddea48 100644 --- a/puppet-{{cookiecutter.project_name}}/spec/unit/provider/{{cookiecutter.project_name}}_config/ini_setting_spec.rb +++ b/puppet-{{cookiecutter.project_name}}/spec/unit/provider/{{cookiecutter.project_name}}_config/ini_setting_spec.rb @@ -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 is specified as a value' do + resource = Puppet::Type::{{cookiecutter.project_name|capitalize}}_config.new( + {:name => 'dude/foo', :value => ''} + ) + 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 diff --git a/puppet-{{cookiecutter.project_name}}/spec/unit/type/{{cookiecutter.project_name}}_config_spec.rb b/puppet-{{cookiecutter.project_name}}/spec/unit/type/{{cookiecutter.project_name}}_config_spec.rb index 1db93f1..55d61bb 100644 --- a/puppet-{{cookiecutter.project_name}}/spec/unit/type/{{cookiecutter.project_name}}_config_spec.rb +++ b/puppet-{{cookiecutter.project_name}}/spec/unit/type/{{cookiecutter.project_name}}_config_spec.rb @@ -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