]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Reflect provider change in puppet-openstacklib
authorYanis Guenane <yguenane@redhat.com>
Thu, 6 Aug 2015 11:05:21 +0000 (13:05 +0200)
committerYanis Guenane <yguenane@redhat.com>
Wed, 19 Aug 2015 08:37:41 +0000 (10:37 +0200)
With the creation of the new openstack_config provider, some processing
that was done in ceilometer_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. '<SERVICE DEFAULT>' is the default value for
ensure_absent_val.

The use case is the following :

ceilometer_config { 'DEFAULT/foo' : value => 'bar' } # will work as usual

ceilometer_config { 'DEFAULT/foo' : value => '<SERVICE DEFAULT>' } # will mean absent

That means that all the current :

if $myvar {
  ceilometer_config { 'DEFAULT/foo' : value => $myvar }
} else {
  ceilometer_config { 'DEFAULT/foo' : ensure => absent }
}

can be removed in favor of :

ceilometer_config { 'DEFAULT/foo' : value => $myvar }

If for any reason '<SERVICE DEFAULT>' turns out to be a valid value for
a specific parameter. One could by pass that doing the following :

ceilometer_config { 'DEFAULT/foo' : value => '<SERVICE DEFAULT>',
ensure_absent_val => 'foo' }

Change-Id: Ia46f8ea1228caca85d6fe431922fa8229f4c4ade
Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218

README.md
lib/puppet/provider/ceilometer_config/ini_setting.rb
lib/puppet/type/ceilometer_config.rb
spec/unit/provider/ceilometer_config/ini_setting_spec.rb

index 6c724857465550f0369488d76d768c9e83db31c5..f94759b8a8dbbe6e318c6557f37f39481aa1da4c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -77,6 +77,36 @@ Implementation
 ceilometer is a combination of Puppet manifests and Ruby code to deliver configuration and
 extra functionality through types and providers.
 
+### Types
+
+#### ceilometer_config
+
+The `ceilometer_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/ceilometer/ceilometer.conf` file.
+
+```puppet
+ceilometer_config { 'DEFAULT/verbose' :
+  value => true,
+}
+```
+
+This will write `verbose=true` in the `[DEFAULT]` section.
+
+##### name
+
+Section/setting name to manage from `ceilometer.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 `<SERVICE DEFAULT>`
+
 Limitations
 -----------
 
index 10ae8fb0bfd32656b0b82ae5b0d137f07f6ffe05..db180a144d6d680f7b1d691a3186de3a069a430e 100644 (file)
@@ -1,20 +1,8 @@
 Puppet::Type.type(:ceilometer_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/ceilometer/ceilometer.conf'
   end
index cb03195065f13d71812c2cdad2d5865f6b4a53ba..88607734b508bd48638d35e2cdad25dbc4b43d5a 100644 (file)
@@ -41,6 +41,11 @@ Puppet::Type.newtype(:ceilometer_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('<SERVICE DEFAULT>')
+  end
+
   autorequire(:package) do
     'ceilometer-common'
   end
index 172766dc2e46131dbe33d1dde734834777bd2124..e69a3a919ec7ea7c65b558a99a6e88ecc9714199 100644 (file)
@@ -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 <SERVICE DEFAULT> is specified as a value' do
+    resource = Puppet::Type::Ceilometer_config.new(
+      {:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
+    )
+    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::Ceilometer_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