From aa4184a043550536318a05a613e515168879e144 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Thu, 6 Aug 2015 13:05:36 +0200 Subject: [PATCH] Reflect provider change in puppet-openstacklib With the creation of the new openstack_config provider, some processing that was done in designate_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. '' is the default value for ensure_absent_val. The use case is the following : designate_config { 'DEFAULT/foo' : value => 'bar' } # will work as usual designate_config { 'DEFAULT/foo' : value => '' } # will mean absent That means that all the current : if $myvar { designate_config { 'DEFAULT/foo' : value => $myvar } } else { designate_config { 'DEFAULT/foo' : ensure => absent } } can be removed in favor of : designate_config { 'DEFAULT/foo' : value => $myvar } If for any reason '' turns out to be a valid value for a specific parameter. One could by pass that doing the following : designate_config { 'DEFAULT/foo' : value => '', ensure_absent_val => 'foo' } Change-Id: I16873c60bfce5b2f432f034755b7bfa3f1383dc5 Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218 --- README.md | 30 ++++++++++ .../designate_api_paste_ini/ini_setting.rb | 14 +---- .../provider/designate_config/ini_setting.rb | 16 +----- lib/puppet/type/designate_api_paste_ini.rb | 6 ++ lib/puppet/type/designate_config.rb | 5 ++ spec/acceptance/designate_config_spec.rb | 55 +++++++++++++++++++ .../designate_config/ini_setting_spec.rb | 29 ++++++++++ 7 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 spec/acceptance/designate_config_spec.rb diff --git a/README.md b/README.md index 6eca7e4d..41343066 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,36 @@ Implementation designate is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers. +### Types + +#### designate_config + +The `designate_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/designate/designate.conf` file. + +```puppet +designate_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `designate.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 `` + Limitations ----------- diff --git a/lib/puppet/provider/designate_api_paste_ini/ini_setting.rb b/lib/puppet/provider/designate_api_paste_ini/ini_setting.rb index 440466f5..d48ba9ca 100644 --- a/lib/puppet/provider/designate_api_paste_ini/ini_setting.rb +++ b/lib/puppet/provider/designate_api_paste_ini/ini_setting.rb @@ -1,20 +1,8 @@ Puppet::Type.type(:designate_api_paste_ini).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/designate/api-paste.ini' end diff --git a/lib/puppet/provider/designate_config/ini_setting.rb b/lib/puppet/provider/designate_config/ini_setting.rb index 85a8b8e0..53c0d4e3 100644 --- a/lib/puppet/provider/designate_config/ini_setting.rb +++ b/lib/puppet/provider/designate_config/ini_setting.rb @@ -1,21 +1,9 @@ Puppet::Type.type(:designate_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 file_path + def self.file_path '/etc/designate/designate.conf' end diff --git a/lib/puppet/type/designate_api_paste_ini.rb b/lib/puppet/type/designate_api_paste_ini.rb index 21ed823b..1d175dbb 100644 --- a/lib/puppet/type/designate_api_paste_ini.rb +++ b/lib/puppet/type/designate_api_paste_ini.rb @@ -40,6 +40,12 @@ Puppet::Type.newtype(:designate_api_paste_ini) 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 'designate-common' end diff --git a/lib/puppet/type/designate_config.rb b/lib/puppet/type/designate_config.rb index 0e15a8e9..d584b496 100644 --- a/lib/puppet/type/designate_config.rb +++ b/lib/puppet/type/designate_config.rb @@ -41,6 +41,11 @@ Puppet::Type.newtype(:designate_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 'designate-common' end diff --git a/spec/acceptance/designate_config_spec.rb b/spec/acceptance/designate_config_spec.rb new file mode 100644 index 00000000..f9e6c626 --- /dev/null +++ b/spec/acceptance/designate_config_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper_acceptance' + +describe 'basic designate_config resource' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + Exec { logoutput => 'on_failure' } + + File <||> -> Designate_config <||> + + file { '/etc/designate' : + ensure => directory, + } + file { '/etc/designate/designate.conf' : + ensure => file, + } + + designate_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + designate_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + designate_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + designate_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + EOS + + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe file('/etc/designate/designate.conf') do + it { should exist } + it { should contain('thisshouldexist=foo') } + it { should contain('thisshouldexist2=') } + + its(:content) { should_not match /thisshouldnotexist/ } + end + + + end +end diff --git a/spec/unit/provider/designate_config/ini_setting_spec.rb b/spec/unit/provider/designate_config/ini_setting_spec.rb index 6e7b2178..fb83d3a0 100644 --- a/spec/unit/provider/designate_config/ini_setting_spec.rb +++ b/spec/unit/provider/designate_config/ini_setting_spec.rb @@ -14,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(:designate_config).provider(:ini_setting) describe provider_class do @@ -35,4 +46,22 @@ describe provider_class do expect(provider.section).to eq('boo') expect(provider.setting).to eq('zoo') end + + it 'should ensure absent when is specified as a value' do + resource = Puppet::Type::Designate_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::Designate_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