From e2bcbee7922b36bf53cda645f353232e63a3e209 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Thu, 6 Aug 2015 13:05:54 +0200 Subject: [PATCH] Reflect provider change in puppet-openstacklib With the creation of the new openstack_config provider, some processing that was done in manila_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 : manila_config { 'DEFAULT/foo' : value => 'bar' } # will work as usual manila_config { 'DEFAULT/foo' : value => '' } # will mean absent That means that all the current : if $myvar { manila_config { 'DEFAULT/foo' : value => $myvar } } else { manila_config { 'DEFAULT/foo' : ensure => absent } } can be removed in favor of : manila_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 : manila_config { 'DEFAULT/foo' : value => '', ensure_absent_val => 'foo' } Change-Id: I3c58ba14c8ddd6f20d7f97154f7c68bf12273e07 Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218 --- README.md | 30 ++++++++++ .../manila_api_paste_ini/ini_setting.rb | 19 +------ .../provider/manila_config/ini_setting.rb | 19 +------ lib/puppet/type/manila_api_paste_ini.rb | 5 ++ lib/puppet/type/manila_config.rb | 8 ++- spec/acceptance/manila_config_spec.rb | 55 +++++++++++++++++++ .../manila_config/ini_setting_spec.rb | 30 ++++++++++ 7 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 spec/acceptance/manila_config_spec.rb diff --git a/README.md b/README.md index 95b28f26..0fc8effc 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,36 @@ Implementation manila is a combination of Puppet manifests and ruby code to delivery configuration and extra functionality through types and providers. +### Types + +#### manila_config + +The `manila_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/manila/manila.conf` file. + +```puppet +manila_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `manila.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 `` + Beaker-Rspec ------------ diff --git a/lib/puppet/provider/manila_api_paste_ini/ini_setting.rb b/lib/puppet/provider/manila_api_paste_ini/ini_setting.rb index 0998a203..de4c35c8 100644 --- a/lib/puppet/provider/manila_api_paste_ini/ini_setting.rb +++ b/lib/puppet/provider/manila_api_paste_ini/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:manila_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/manila/api-paste.ini' end - # added for backwards compatibility with older versions of inifile - def file_path - self.class.file_path - end - end diff --git a/lib/puppet/provider/manila_config/ini_setting.rb b/lib/puppet/provider/manila_config/ini_setting.rb index de54844a..98896686 100644 --- a/lib/puppet/provider/manila_config/ini_setting.rb +++ b/lib/puppet/provider/manila_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:manila_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/manila/manila.conf' end - # added for backwards compatibility with older versions of inifile - def file_path - self.class.file_path - end - end diff --git a/lib/puppet/type/manila_api_paste_ini.rb b/lib/puppet/type/manila_api_paste_ini.rb index 5dc6b130..85c5db98 100644 --- a/lib/puppet/type/manila_api_paste_ini.rb +++ b/lib/puppet/type/manila_api_paste_ini.rb @@ -40,6 +40,11 @@ Puppet::Type.newtype(:manila_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 'manila' end diff --git a/lib/puppet/type/manila_config.rb b/lib/puppet/type/manila_config.rb index 6e959bb7..8fa8d089 100644 --- a/lib/puppet/type/manila_config.rb +++ b/lib/puppet/type/manila_config.rb @@ -3,7 +3,7 @@ Puppet::Type.newtype(:manila_config) do ensurable newparam(:name, :namevar => true) do - desc 'Section/setting name to manage from /etc/manila/manila.conf' + desc 'Section/setting name to manage from manila.conf' newvalues(/\S+\/\S+/) end @@ -14,6 +14,7 @@ Puppet::Type.newtype(:manila_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -40,6 +41,11 @@ Puppet::Type.newtype(:manila_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 'manila' end diff --git a/spec/acceptance/manila_config_spec.rb b/spec/acceptance/manila_config_spec.rb new file mode 100644 index 00000000..12488fdf --- /dev/null +++ b/spec/acceptance/manila_config_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper_acceptance' + +describe 'basic manila_config resource' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + Exec { logoutput => 'on_failure' } + + File <||> -> Manila_config <||> + + file { '/etc/manila' : + ensure => directory, + } + file { '/etc/manila/manila.conf' : + ensure => file, + } + + manila_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + manila_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + manila_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + manila_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/manila/manila.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/manila_config/ini_setting_spec.rb b/spec/unit/provider/manila_config/ini_setting_spec.rb index 7c5d2978..117bf163 100644 --- a/spec/unit/provider/manila_config/ini_setting_spec.rb +++ b/spec/unit/provider/manila_config/ini_setting_spec.rb @@ -9,6 +9,17 @@ $LOAD_PATH.push( 'inifile', 'lib') ) +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'openstacklib', + 'lib') +) require 'spec_helper' @@ -39,4 +50,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::Manila_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::Manila_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