diff --git a/README.md b/README.md index ed3f5143..981c3545 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,92 @@ class { 'glance::notify::rabbitmq': } ``` +### Types + +#### glance_api_config + +The `glance_api_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/glance/glance-api.conf` file. + +```puppet +glance_api_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `glance-api.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 `` + +#### glance_registry_config + +The `glance_registry_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/glance/glance-registry.conf` file. + +```puppet +glance_registry_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `glance-registry.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 `` + +#### glance_cache_config + +The `glance_cache_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/glance/glance-cache.conf` file. + +```puppet +glance_cache_config { 'DEFAULT/verbose' : + value => true, +} +``` + +This will write `verbose=true` in the `[DEFAULT]` section. + +##### name + +Section/setting name to manage from `glance-cache.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 `` + Implementation -------------- diff --git a/lib/puppet/provider/glance_api_config/ini_setting.rb b/lib/puppet/provider/glance_api_config/ini_setting.rb index 4323ae8c..7762142d 100644 --- a/lib/puppet/provider/glance_api_config/ini_setting.rb +++ b/lib/puppet/provider/glance_api_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:glance_api_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/glance/glance-api.conf' end - # this needs to be removed. This has been replaced with the class method - def file_path - self.class.file_path - end - end diff --git a/lib/puppet/provider/glance_api_paste_ini/ini_setting.rb b/lib/puppet/provider/glance_api_paste_ini/ini_setting.rb index d624d64b..ae31fac5 100644 --- a/lib/puppet/provider/glance_api_paste_ini/ini_setting.rb +++ b/lib/puppet/provider/glance_api_paste_ini/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:glance_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/glance/glance-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/glance_cache_config/ini_setting.rb b/lib/puppet/provider/glance_cache_config/ini_setting.rb index 579dfb46..0b44ec33 100644 --- a/lib/puppet/provider/glance_cache_config/ini_setting.rb +++ b/lib/puppet/provider/glance_cache_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:glance_cache_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/glance/glance-cache.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/glance_registry_config/ini_setting.rb b/lib/puppet/provider/glance_registry_config/ini_setting.rb index 5f843b5e..8e9c54a7 100644 --- a/lib/puppet/provider/glance_registry_config/ini_setting.rb +++ b/lib/puppet/provider/glance_registry_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:glance_registry_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/glance/glance-registry.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/glance_registry_paste_ini/ini_setting.rb b/lib/puppet/provider/glance_registry_paste_ini/ini_setting.rb index 36cb7e12..619eaee2 100644 --- a/lib/puppet/provider/glance_registry_paste_ini/ini_setting.rb +++ b/lib/puppet/provider/glance_registry_paste_ini/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:glance_registry_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/glance/glance-registry-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/type/glance_api_config.rb b/lib/puppet/type/glance_api_config.rb index 0ccee169..10681bcc 100644 --- a/lib/puppet/type/glance_api_config.rb +++ b/lib/puppet/type/glance_api_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:glance_api_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(:glance_api_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 'glance-api' end diff --git a/lib/puppet/type/glance_api_paste_ini.rb b/lib/puppet/type/glance_api_paste_ini.rb index b97c08b1..a2ca7e50 100644 --- a/lib/puppet/type/glance_api_paste_ini.rb +++ b/lib/puppet/type/glance_api_paste_ini.rb @@ -40,6 +40,11 @@ Puppet::Type.newtype(:glance_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 'glance-api' end diff --git a/lib/puppet/type/glance_cache_config.rb b/lib/puppet/type/glance_cache_config.rb index f4650019..87d4951e 100644 --- a/lib/puppet/type/glance_cache_config.rb +++ b/lib/puppet/type/glance_cache_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:glance_cache_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(:glance_cache_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 'glance-api' end diff --git a/lib/puppet/type/glance_registry_config.rb b/lib/puppet/type/glance_registry_config.rb index 31ece0e7..9fa6dd2c 100644 --- a/lib/puppet/type/glance_registry_config.rb +++ b/lib/puppet/type/glance_registry_config.rb @@ -14,6 +14,7 @@ Puppet::Type.newtype(:glance_registry_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(:glance_registry_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 'glance-registry' end diff --git a/lib/puppet/type/glance_registry_paste_ini.rb b/lib/puppet/type/glance_registry_paste_ini.rb index d6292fbb..4134c38f 100644 --- a/lib/puppet/type/glance_registry_paste_ini.rb +++ b/lib/puppet/type/glance_registry_paste_ini.rb @@ -40,6 +40,11 @@ Puppet::Type.newtype(:glance_registry_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 'glance-registry' end diff --git a/spec/acceptance/glance_config_spec.rb b/spec/acceptance/glance_config_spec.rb new file mode 100644 index 00000000..b8bc9967 --- /dev/null +++ b/spec/acceptance/glance_config_spec.rb @@ -0,0 +1,113 @@ +require 'spec_helper_acceptance' + +describe 'basic glance config resource' do + + context 'default parameters' do + + it 'should work with no errors' do + pp= <<-EOS + Exec { logoutput => 'on_failure' } + + File <||> -> Glance_api_config <||> + File <||> -> Glance_registry_config <||> + File <||> -> Glance_cache_config <||> + + file { '/etc/glance' : + ensure => directory, + } + file { '/etc/glance/glance-api.conf' : + ensure => file, + } + file { '/etc/glance/glance-registry.conf' : + ensure => file, + } + file { '/etc/glance/glance-cache.conf' : + ensure => file, + } + + glance_api_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + glance_api_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + glance_api_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + glance_api_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + glance_registry_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + glance_registry_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + glance_registry_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + glance_registry_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + + glance_cache_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + glance_cache_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + glance_cache_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + glance_cache_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/glance/glance-api.conf') do + it { should exist } + it { should contain('thisshouldexist=foo') } + it { should contain('thisshouldexist2=') } + + its(:content) { should_not match /thisshouldnotexist/ } + end + + describe file('/etc/glance/glance-registry.conf') do + it { should exist } + it { should contain('thisshouldexist=foo') } + it { should contain('thisshouldexist2=') } + + its(:content) { should_not match /thisshouldnotexist/ } + end + + describe file('/etc/glance/glance-cache.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/glance_api_config/ini_setting_spec.rb b/spec/unit/provider/glance_api_config/ini_setting_spec.rb index 7e805d00..14c97ee6 100644 --- a/spec/unit/provider/glance_api_config/ini_setting_spec.rb +++ b/spec/unit/provider/glance_api_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::Glance_api_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::Glance_api_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/glance_cache_config/ini_setting_spec.rb b/spec/unit/provider/glance_cache_config/ini_setting_spec.rb index 9a9a324f..6fcfd7c0 100644 --- a/spec/unit/provider/glance_cache_config/ini_setting_spec.rb +++ b/spec/unit/provider/glance_cache_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::Glance_cache_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::Glance_cache_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/glance_registry_config/ini_setting_spec.rb b/spec/unit/provider/glance_registry_config/ini_setting_spec.rb index 505be658..a05e0f2a 100644 --- a/spec/unit/provider/glance_registry_config/ini_setting_spec.rb +++ b/spec/unit/provider/glance_registry_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::Glance_registry_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::Glance_registry_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