Browse Source

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. '<SERVICE DEFAULT>' 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 => '<SERVICE DEFAULT>' } # 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 '<SERVICE DEFAULT>' turns out to be a valid value for
a specific parameter. One could by pass that doing the following :

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

Change-Id: I16873c60bfce5b2f432f034755b7bfa3f1383dc5
Depends-On: I0eeebde3aac2662cc7e69bfad7f8d2481463a218
tags/7.0.0
Yanis Guenane 4 years ago
parent
commit
aa4184a043

+ 30
- 0
README.md View File

@@ -36,6 +36,36 @@ Implementation
36 36
 
37 37
 designate is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers.
38 38
 
39
+### Types
40
+
41
+#### designate_config
42
+
43
+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.
44
+
45
+```puppet
46
+designate_config { 'DEFAULT/verbose' :
47
+  value => true,
48
+}
49
+```
50
+
51
+This will write `verbose=true` in the `[DEFAULT]` section.
52
+
53
+##### name
54
+
55
+Section/setting name to manage from `designate.conf`
56
+
57
+##### value
58
+
59
+The value of the setting to be defined.
60
+
61
+##### secret
62
+
63
+Whether to hide the value from Puppet logs. Defaults to `false`.
64
+
65
+##### ensure_absent_val
66
+
67
+If value is equal to ensure_absent_val then the resource will behave as if `ensure => absent` was specified. Defaults to `<SERVICE DEFAULT>`
68
+
39 69
 Limitations
40 70
 -----------
41 71
 

+ 1
- 13
lib/puppet/provider/designate_api_paste_ini/ini_setting.rb View File

@@ -1,20 +1,8 @@
1 1
 Puppet::Type.type(:designate_api_paste_ini).provide(
2 2
   :ini_setting,
3
-  :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3
+  :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
4 4
 ) do
5 5
 
6
-  def section
7
-    resource[:name].split('/', 2).first
8
-  end
9
-
10
-  def setting
11
-    resource[:name].split('/', 2).last
12
-  end
13
-
14
-  def separator
15
-    '='
16
-  end
17
-
18 6
   def self.file_path
19 7
     '/etc/designate/api-paste.ini'
20 8
   end

+ 2
- 14
lib/puppet/provider/designate_config/ini_setting.rb View File

@@ -1,21 +1,9 @@
1 1
 Puppet::Type.type(:designate_config).provide(
2 2
   :ini_setting,
3
-  :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
3
+  :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
4 4
 ) do
5 5
 
6
-  def section
7
-    resource[:name].split('/', 2).first
8
-  end
9
-
10
-  def setting
11
-    resource[:name].split('/', 2).last
12
-  end
13
-
14
-  def separator
15
-    '='
16
-  end
17
-
18
-  def file_path
6
+  def self.file_path
19 7
     '/etc/designate/designate.conf'
20 8
   end
21 9
 

+ 6
- 0
lib/puppet/type/designate_api_paste_ini.rb View File

@@ -40,6 +40,12 @@ Puppet::Type.newtype(:designate_api_paste_ini) do
40 40
     defaultto false
41 41
   end
42 42
 
43
+  newparam(:ensure_absent_val) do
44
+    desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
45
+    defaultto('<SERVICE DEFAULT>')
46
+  end
47
+
48
+
43 49
   autorequire(:package) do
44 50
     'designate-common'
45 51
   end

+ 5
- 0
lib/puppet/type/designate_config.rb View File

@@ -41,6 +41,11 @@ Puppet::Type.newtype(:designate_config) do
41 41
     defaultto false
42 42
   end
43 43
 
44
+  newparam(:ensure_absent_val) do
45
+    desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
46
+    defaultto('<SERVICE DEFAULT>')
47
+  end
48
+
44 49
   autorequire(:package) do
45 50
     'designate-common'
46 51
   end

+ 55
- 0
spec/acceptance/designate_config_spec.rb View File

@@ -0,0 +1,55 @@
1
+require 'spec_helper_acceptance'
2
+
3
+describe 'basic designate_config resource' do
4
+
5
+  context 'default parameters' do
6
+
7
+    it 'should work with no errors' do
8
+      pp= <<-EOS
9
+      Exec { logoutput => 'on_failure' }
10
+
11
+      File <||> -> Designate_config <||>
12
+
13
+      file { '/etc/designate' :
14
+        ensure => directory,
15
+      }
16
+      file { '/etc/designate/designate.conf' :
17
+        ensure => file,
18
+      }
19
+
20
+      designate_config { 'DEFAULT/thisshouldexist' :
21
+        value => 'foo',
22
+      }
23
+
24
+      designate_config { 'DEFAULT/thisshouldnotexist' :
25
+        value => '<SERVICE DEFAULT>',
26
+      }
27
+
28
+      designate_config { 'DEFAULT/thisshouldexist2' :
29
+        value             => '<SERVICE DEFAULT>',
30
+        ensure_absent_val => 'toto',
31
+      }
32
+
33
+      designate_config { 'DEFAULT/thisshouldnotexist2' :
34
+        value             => 'toto',
35
+        ensure_absent_val => 'toto',
36
+      }
37
+      EOS
38
+
39
+
40
+      # Run it twice and test for idempotency
41
+      apply_manifest(pp, :catch_failures => true)
42
+      apply_manifest(pp, :catch_changes => true)
43
+    end
44
+
45
+    describe file('/etc/designate/designate.conf') do
46
+      it { should exist }
47
+      it { should contain('thisshouldexist=foo') }
48
+      it { should contain('thisshouldexist2=<SERVICE DEFAULT>') }
49
+
50
+      its(:content) { should_not match /thisshouldnotexist/ }
51
+    end
52
+
53
+
54
+  end
55
+end

+ 29
- 0
spec/unit/provider/designate_config/ini_setting_spec.rb View File

@@ -14,6 +14,17 @@ $LOAD_PATH.push(
14 14
     'inifile',
15 15
     'lib')
16 16
 )
17
+$LOAD_PATH.push(
18
+  File.join(
19
+    File.dirname(__FILE__),
20
+    '..',
21
+    '..',
22
+    '..',
23
+    'fixtures',
24
+    'modules',
25
+    'openstacklib',
26
+    'lib')
27
+)
17 28
 require 'spec_helper'
18 29
 provider_class = Puppet::Type.type(:designate_config).provider(:ini_setting)
19 30
 describe provider_class do
@@ -35,4 +46,22 @@ describe provider_class do
35 46
     expect(provider.section).to  eq('boo')
36 47
     expect(provider.setting).to eq('zoo')
37 48
   end
49
+
50
+  it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
51
+    resource = Puppet::Type::Designate_config.new(
52
+      {:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
53
+    )
54
+    provider = provider_class.new(resource)
55
+    provider.exists?
56
+    expect(resource[:ensure]).to eq :absent
57
+  end
58
+
59
+  it 'should ensure absent when value matches ensure_absent_val' do
60
+    resource = Puppet::Type::Designate_config.new(
61
+      {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
62
+    )
63
+    provider = provider_class.new(resource)
64
+    provider.exists?
65
+    expect(resource[:ensure]).to eq :absent
66
+  end
38 67
 end

Loading…
Cancel
Save