From fa9218c4cd27a3256b8df1ad0ea8607b344be257 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 11 Feb 2016 13:58:42 -0500 Subject: [PATCH] Reflect provider change in puppet-openstacklib With the creation of the new openstack_config provider, some essing that was done in zaqar_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 : zaqar_config { 'DEFAULT/foo' : value => 'bar' } # will work as l zaqar_config { 'DEFAULT/foo' : value => '' } # mean absent That means that all the current : if $myvar { zaqar_config { 'DEFAULT/foo' : value => $myvar } } else { zaqar_config { 'DEFAULT/foo' : ensure => absent } } can be removed in favor of : zaqar_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 zaqar_config { 'DEFAULT/foo' : value => '', ensure_absent_val => 'foo' } Change-Id: Iaaf2e5755080ef32d7d585465aaea6fd408d0ece --- README.md | 30 +++++++++++++++++ .../provider/zaqar_config/ini_setting.rb | 19 +---------- lib/puppet/type/zaqar_config.rb | 11 +++++++ metadata.json | 2 +- .../provider/zaqar_config/ini_setting_spec.rb | 32 +++++++++++++++++++ 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a925976..ff44864 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,36 @@ Implementation zaqar is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers. +### Types + +#### zaqar_config + +The `zaqar_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/zaqar/zaqar.conf` file. + +```puppet +zaqar_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `zaqar.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/zaqar_config/ini_setting.rb b/lib/puppet/provider/zaqar_config/ini_setting.rb index 743fb1c..e92e4ab 100644 --- a/lib/puppet/provider/zaqar_config/ini_setting.rb +++ b/lib/puppet/provider/zaqar_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:zaqar_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/zaqar/zaqar.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/zaqar_config.rb b/lib/puppet/type/zaqar_config.rb index 65d3154..ab1ecbc 100644 --- a/lib/puppet/type/zaqar_config.rb +++ b/lib/puppet/type/zaqar_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:zaqar_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(:zaqar_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 + 'zaqar-common' + end + end diff --git a/metadata.json b/metadata.json index 88bd41d..49c87c6 100644 --- a/metadata.json +++ b/metadata.json @@ -29,6 +29,6 @@ "dependencies": [ { "name": "puppetlabs/inifile", "version_requirement": ">=1.0.0 <2.0.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.0.0 <5.0.0" }, - { "name": "openstack/openstacklib", "version_requirement": ">=6.0.0 <7.0.0" } + { "name": "openstack/openstacklib", "version_requirement": ">=7.0.0 <8.0.0" } ] } diff --git a/spec/unit/provider/zaqar_config/ini_setting_spec.rb b/spec/unit/provider/zaqar_config/ini_setting_spec.rb index 04239aa..928aad3 100644 --- a/spec/unit/provider/zaqar_config/ini_setting_spec.rb +++ b/spec/unit/provider/zaqar_config/ini_setting_spec.rb @@ -13,6 +13,18 @@ $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(:zaqar_config).provider(:ini_setting) describe provider_class do @@ -34,4 +46,24 @@ 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::Zaqar_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::Zaqar_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