Add type/provider for paste configs
Co-Authored-By: Denis Egorenko <degorenko@mirantis.com> Change-Id: I2ea1e2ee0eed241544d6e006306990d1db995ac7 Closes-bug: #1483371
This commit is contained in:
parent
b898edf90a
commit
28426bab08
27
lib/puppet/provider/heat_api_paste_ini/ini_setting.rb
Normal file
27
lib/puppet/provider/heat_api_paste_ini/ini_setting.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Puppet::Type.type(:heat_api_paste_ini).provide(
|
||||||
|
:ini_setting,
|
||||||
|
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
|
||||||
|
) 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/heat/api-paste.ini'
|
||||||
|
end
|
||||||
|
|
||||||
|
# added for backwards compatibility with older versions of inifile
|
||||||
|
def file_path
|
||||||
|
self.class.file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
52
lib/puppet/type/heat_api_paste_ini.rb
Normal file
52
lib/puppet/type/heat_api_paste_ini.rb
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
Puppet::Type.newtype(:heat_api_paste_ini) do
|
||||||
|
|
||||||
|
ensurable
|
||||||
|
|
||||||
|
newparam(:name, :namevar => true) do
|
||||||
|
desc 'Section/setting name to manage from /etc/heat/api-paste.ini'
|
||||||
|
newvalues(/\S+\/\S+/)
|
||||||
|
end
|
||||||
|
|
||||||
|
newproperty(:value) do
|
||||||
|
desc 'The value of the setting to be defined.'
|
||||||
|
munge do |value|
|
||||||
|
value = value.to_s.strip
|
||||||
|
value.capitalize! if value =~ /^(true|false)$/i
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_to_s( currentvalue )
|
||||||
|
if resource.secret?
|
||||||
|
return '[old secret redacted]'
|
||||||
|
else
|
||||||
|
return currentvalue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def should_to_s( newvalue )
|
||||||
|
if resource.secret?
|
||||||
|
return '[new secret redacted]'
|
||||||
|
else
|
||||||
|
return newvalue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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('<SERVICE DEFAULT>')
|
||||||
|
end
|
||||||
|
|
||||||
|
autorequire(:package) do
|
||||||
|
'heat-common'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
29
spec/unit/provider/heat_api_paste_ini/ini_setting_spec.rb
Normal file
29
spec/unit/provider/heat_api_paste_ini/ini_setting_spec.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#
|
||||||
|
# these tests are a little concerning b/c they are hacking around the
|
||||||
|
# modulepath, so these tests will not catch issues that may eventually arise
|
||||||
|
# related to loading these plugins.
|
||||||
|
# I could not, for the life of me, figure out how to programatcally set the modulepath
|
||||||
|
$LOAD_PATH.push(
|
||||||
|
File.join(
|
||||||
|
File.dirname(__FILE__),
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'fixtures',
|
||||||
|
'modules',
|
||||||
|
'inifile',
|
||||||
|
'lib')
|
||||||
|
)
|
||||||
|
require 'spec_helper'
|
||||||
|
provider_class = Puppet::Type.type(:heat_api_paste_ini).provider(:ini_setting)
|
||||||
|
describe provider_class do
|
||||||
|
|
||||||
|
it 'should allow setting to be set explicitly' do
|
||||||
|
resource = Puppet::Type::Heat_api_paste_ini.new(
|
||||||
|
{:name => 'dude/foo', :value => 'bar'}
|
||||||
|
)
|
||||||
|
provider = provider_class.new(resource)
|
||||||
|
expect(provider.section).to eq('dude')
|
||||||
|
expect(provider.setting).to eq('foo')
|
||||||
|
end
|
||||||
|
end
|
34
spec/unit/type/heat_api_paste_ini_spec.rb
Normal file
34
spec/unit/type/heat_api_paste_ini_spec.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
# this hack is required for now to ensure that the path is set up correctly
|
||||||
|
# to retrive the parent provider
|
||||||
|
$LOAD_PATH.push(
|
||||||
|
File.join(
|
||||||
|
File.dirname(__FILE__),
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'fixtures',
|
||||||
|
'modules',
|
||||||
|
'inifile',
|
||||||
|
'lib')
|
||||||
|
)
|
||||||
|
require 'puppet/type/heat_api_paste_ini'
|
||||||
|
describe 'Puppet::Type.type(:heat_api_paste_ini)' do
|
||||||
|
before :each do
|
||||||
|
@heat_api_paste_ini = Puppet::Type.type(:heat_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
|
||||||
|
end
|
||||||
|
it 'should accept a valid value' do
|
||||||
|
@heat_api_paste_ini[:value] = 'bar'
|
||||||
|
expect(@heat_api_paste_ini[:value]).to eq('bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should autorequire the package that install the file' do
|
||||||
|
catalog = Puppet::Resource::Catalog.new
|
||||||
|
package = Puppet::Type.type(:package).new(:name => 'heat-common')
|
||||||
|
catalog.add_resource package, @heat_api_paste_ini
|
||||||
|
dependency = @heat_api_paste_ini.autorequire
|
||||||
|
expect(dependency.size).to eq(1)
|
||||||
|
expect(dependency[0].target).to eq(@heat_api_paste_ini)
|
||||||
|
expect(dependency[0].source).to eq(package)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user