From e6e8c9d8368eb98ea374c623e8e07bbf28d610ed Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Thu, 6 Aug 2015 13:06:27 +0200 Subject: [PATCH] Reflect provider change in puppet-openstacklib With the creation of the new openstack_config provider, some processing that was done in swift_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 : swift_config { 'DEFAULT/foo' : value => 'bar' } # will work as usual swift_config { 'DEFAULT/foo' : value => '' } # will mean absent That means that all the current : if $myvar { swift_config { 'DEFAULT/foo' : value => $myvar } } else { swift_config { 'DEFAULT/foo' : ensure => absent } } can be removed in favor of : swift_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 : swift_config { 'DEFAULT/foo' : value => '', ensure_absent_val => 'foo' } Change-Id: I9281d2cae81f9799327f7f6e04498d6bc723f233 Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218 --- README.md | 55 ++++++ .../swift_account_config/ini_setting.rb | 19 +- .../swift_bench_config/ini_setting.rb | 19 +- .../provider/swift_config/ini_setting.rb | 19 +- .../swift_container_config/ini_setting.rb | 19 +- .../swift_dispersion_config/ini_setting.rb | 19 +- .../swift_object_config/ini_setting.rb | 19 +- .../swift_proxy_config/ini_setting.rb | 19 +- lib/puppet/type/swift_account_config.rb | 8 + lib/puppet/type/swift_bench_config.rb | 8 + lib/puppet/type/swift_config.rb | 8 + lib/puppet/type/swift_container_config.rb | 8 + lib/puppet/type/swift_dispersion_config.rb | 8 + lib/puppet/type/swift_object_config.rb | 8 + lib/puppet/type/swift_proxy_config.rb | 8 + spec/acceptance/swift_config_spec.rb | 187 ++++++++++++++++++ .../swift_account_config/ini_setting_spec.rb | 30 +++ .../swift_bench_config/ini_setting_spec.rb | 29 +++ .../provider/swift_config/ini_setting_spec.rb | 30 +++ .../ini_setting_spec.rb | 30 +++ .../ini_setting_spec.rb | 29 +++ .../swift_object_config/ini_setting_spec.rb | 29 +++ .../swift_proxy_config/ini_setting_spec.rb | 30 +++ 23 files changed, 512 insertions(+), 126 deletions(-) create mode 100644 spec/acceptance/swift_config_spec.rb diff --git a/README.md b/README.md index 8f06d1ad..416d828b 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,61 @@ Implementation swift is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers. +### Types + +#### swift_config + +The `swift_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/swift/swift.conf` file. + +```puppet +swift_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `swift.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 `` + +#### swift_account_config + +Same as `swift_config`, but path is `/etc/swift/account-server.conf` + +#### swift_bench_config + +Same as `swift_config`, but path is `/etc/swift/swift-bench.conf` + +#### swift_container_config + +Same as `swift_config`, but path is `/etc/swift/container-server.conf` + +#### swift_dispersion_config + +Same as `swift_config`, but path is `/etc/swift/dispersion.conf` + +#### swift_object_config + +Same as `swift_config`, but path is `/etc/swift/object-server.conf` + +#### swift_proxy_config + +Same as `swift_config`, but path is `/etc/swift/proxy-server.conf` + + Limitations ------------ diff --git a/lib/puppet/provider/swift_account_config/ini_setting.rb b/lib/puppet/provider/swift_account_config/ini_setting.rb index 5e1eabd4..0f9b4bce 100644 --- a/lib/puppet/provider/swift_account_config/ini_setting.rb +++ b/lib/puppet/provider/swift_account_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_account_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/swift/account-server.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/provider/swift_bench_config/ini_setting.rb b/lib/puppet/provider/swift_bench_config/ini_setting.rb index 12815a33..35b47e35 100644 --- a/lib/puppet/provider/swift_bench_config/ini_setting.rb +++ b/lib/puppet/provider/swift_bench_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_bench_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/swift/swift-bench.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/provider/swift_config/ini_setting.rb b/lib/puppet/provider/swift_config/ini_setting.rb index c3930371..8b3915ab 100644 --- a/lib/puppet/provider/swift_config/ini_setting.rb +++ b/lib/puppet/provider/swift_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_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/swift/swift.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/provider/swift_container_config/ini_setting.rb b/lib/puppet/provider/swift_container_config/ini_setting.rb index 849ec1d9..a0a62550 100644 --- a/lib/puppet/provider/swift_container_config/ini_setting.rb +++ b/lib/puppet/provider/swift_container_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_container_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/swift/container-server.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/provider/swift_dispersion_config/ini_setting.rb b/lib/puppet/provider/swift_dispersion_config/ini_setting.rb index 66fb7fdf..9ba9dd81 100644 --- a/lib/puppet/provider/swift_dispersion_config/ini_setting.rb +++ b/lib/puppet/provider/swift_dispersion_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_dispersion_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/swift/dispersion.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/provider/swift_object_config/ini_setting.rb b/lib/puppet/provider/swift_object_config/ini_setting.rb index 5d9e6eb5..a6156a18 100644 --- a/lib/puppet/provider/swift_object_config/ini_setting.rb +++ b/lib/puppet/provider/swift_object_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_object_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/swift/object-server.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/provider/swift_proxy_config/ini_setting.rb b/lib/puppet/provider/swift_proxy_config/ini_setting.rb index 95d3816e..12f5e5e9 100644 --- a/lib/puppet/provider/swift_proxy_config/ini_setting.rb +++ b/lib/puppet/provider/swift_proxy_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:swift_proxy_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/swift/proxy-server.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/swift_account_config.rb b/lib/puppet/type/swift_account_config.rb index 3a6da9b9..6977d6b5 100644 --- a/lib/puppet/type/swift_account_config.rb +++ b/lib/puppet/type/swift_account_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_account_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_account_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift-account' end diff --git a/lib/puppet/type/swift_bench_config.rb b/lib/puppet/type/swift_bench_config.rb index caa79c6b..9b9da321 100644 --- a/lib/puppet/type/swift_bench_config.rb +++ b/lib/puppet/type/swift_bench_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_bench_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_bench_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift' end diff --git a/lib/puppet/type/swift_config.rb b/lib/puppet/type/swift_config.rb index 2ded9cec..c8d3306b 100644 --- a/lib/puppet/type/swift_config.rb +++ b/lib/puppet/type/swift_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 + # Require the swift.conf to be present autorequire(:package) do 'swift' diff --git a/lib/puppet/type/swift_container_config.rb b/lib/puppet/type/swift_container_config.rb index ea241eb0..7335c152 100644 --- a/lib/puppet/type/swift_container_config.rb +++ b/lib/puppet/type/swift_container_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_container_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_container_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift-container' end diff --git a/lib/puppet/type/swift_dispersion_config.rb b/lib/puppet/type/swift_dispersion_config.rb index d4c0c8f2..8bc91eee 100644 --- a/lib/puppet/type/swift_dispersion_config.rb +++ b/lib/puppet/type/swift_dispersion_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_dispersion_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_dispersion_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift' end diff --git a/lib/puppet/type/swift_object_config.rb b/lib/puppet/type/swift_object_config.rb index 1bedc667..c8aa1063 100644 --- a/lib/puppet/type/swift_object_config.rb +++ b/lib/puppet/type/swift_object_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_object_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_object_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift-object' end diff --git a/lib/puppet/type/swift_proxy_config.rb b/lib/puppet/type/swift_proxy_config.rb index 5f8932ea..151a5813 100644 --- a/lib/puppet/type/swift_proxy_config.rb +++ b/lib/puppet/type/swift_proxy_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:swift_proxy_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -34,10 +35,17 @@ Puppet::Type.newtype(:swift_proxy_config) do newparam(:secret, :boolean => true) do desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + newvalues(:true, :false) + 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 'swift-proxy' end diff --git a/spec/acceptance/swift_config_spec.rb b/spec/acceptance/swift_config_spec.rb new file mode 100644 index 00000000..dd672a3d --- /dev/null +++ b/spec/acceptance/swift_config_spec.rb @@ -0,0 +1,187 @@ +require 'spec_helper_acceptance' + +describe 'basic swift_config resource' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + Exec { logoutput => 'on_failure' } + + File <||> -> Swift_config <||> + File <||> -> Swift_account_config <||> + File <||> -> Swift_bench_config <||> + File <||> -> Swift_container_config <||> + File <||> -> Swift_dispersion_config <||> + File <||> -> Swift_object_config <||> + File <||> -> Swift_proxy_config <||> + + file { '/etc/swift' : + ensure => directory, + } + + $swift_files = [ '/etc/swift/swift.conf', + '/etc/swift/account-server.conf', + '/etc/swift/swift-bench.conf', + '/etc/swift/container-server.conf', + '/etc/swift/dispersion.conf', + '/etc/swift/object-server.conf', + '/etc/swift/proxy-server.conf'] + + file { $swift_files : + ensure => file, + } + + swift_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_account_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_account_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_account_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_account_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_bench_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_bench_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_bench_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_bench_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_container_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_container_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_container_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_container_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_dispersion_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_dispersion_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_dispersion_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_dispersion_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_object_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_object_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_object_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_object_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + swift_proxy_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + swift_proxy_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + swift_proxy_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + swift_proxy_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 + + $swift_files = [ '/etc/swift/swift.conf', + '/etc/swift/account-server.conf', + '/etc/swift/swift-bench.conf', + '/etc/swift/container-server.conf', + '/etc/swift/dispersion.conf', + '/etc/swift/object-server.conf', + '/etc/swift/proxy-server.conf'] + + $swift_files.each do |swift_conf_file| + describe file(swift_conf_file) do + it { should exist } + it { should contain('thisshouldexist=foo') } + it { should contain('thisshouldexist2=') } + + its(:content) { should_not match /thisshouldnotexist/ } + end + end + + end +end diff --git a/spec/unit/provider/swift_account_config/ini_setting_spec.rb b/spec/unit/provider/swift_account_config/ini_setting_spec.rb index cfdbdb0e..d44a759c 100644 --- a/spec/unit/provider/swift_account_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_account_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::Swift_account_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::Swift_account_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/spec/unit/provider/swift_bench_config/ini_setting_spec.rb b/spec/unit/provider/swift_bench_config/ini_setting_spec.rb index 7aa55031..ea13fbbd 100644 --- a/spec/unit/provider/swift_bench_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_bench_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,22 @@ 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::Swift_bench_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::Swift_bench_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/spec/unit/provider/swift_config/ini_setting_spec.rb b/spec/unit/provider/swift_config/ini_setting_spec.rb index 4500680b..daaa69e6 100644 --- a/spec/unit/provider/swift_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_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::Swift_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::Swift_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/spec/unit/provider/swift_container_config/ini_setting_spec.rb b/spec/unit/provider/swift_container_config/ini_setting_spec.rb index dd6752b4..7a78f05e 100644 --- a/spec/unit/provider/swift_container_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_container_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::Swift_container_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::Swift_container_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/spec/unit/provider/swift_dispersion_config/ini_setting_spec.rb b/spec/unit/provider/swift_dispersion_config/ini_setting_spec.rb index 992e9a5a..7a9f555b 100644 --- a/spec/unit/provider/swift_dispersion_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_dispersion_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,22 @@ 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::Swift_dispersion_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::Swift_dispersion_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/spec/unit/provider/swift_object_config/ini_setting_spec.rb b/spec/unit/provider/swift_object_config/ini_setting_spec.rb index c356bcd0..f9847390 100644 --- a/spec/unit/provider/swift_object_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_object_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,22 @@ 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::Swift_object_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::Swift_object_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/spec/unit/provider/swift_proxy_config/ini_setting_spec.rb b/spec/unit/provider/swift_proxy_config/ini_setting_spec.rb index 7893b1b3..81bf09bd 100644 --- a/spec/unit/provider/swift_proxy_config/ini_setting_spec.rb +++ b/spec/unit/provider/swift_proxy_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::Swift_proxy_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::Swift_proxy_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