Allow customizing api-paste.ini file
This change introduces a new resource type and the corresponding puppet parameter to allow managing records in api-paste.ini. Change-Id: I92df917887da3220dfb7c7ed10fac123f01af1aa
This commit is contained in:
parent
cb10781964
commit
10eda6e780
|
@ -0,0 +1,27 @@
|
||||||
|
Puppet::Type.type(:tacker_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/tacker/api-paste.ini'
|
||||||
|
end
|
||||||
|
|
||||||
|
# added for backwards compatibility with older versions of inifile
|
||||||
|
def file_path
|
||||||
|
self.class.file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
Puppet::Type.newtype(:tacker_api_paste_ini) do
|
||||||
|
|
||||||
|
ensurable
|
||||||
|
|
||||||
|
newparam(:name, :namevar => true) do
|
||||||
|
desc 'Section/setting name to manage from /etc/tacker/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
|
||||||
|
|
||||||
|
newparam(:key_val_separator) do
|
||||||
|
desc 'The separator string to use between each setting name and value.'
|
||||||
|
defaultto('=')
|
||||||
|
end
|
||||||
|
|
||||||
|
autorequire(:anchor) do
|
||||||
|
['tacker::install::end']
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -17,16 +17,22 @@
|
||||||
# DEFAULT/bar:
|
# DEFAULT/bar:
|
||||||
# value: barValue
|
# value: barValue
|
||||||
#
|
#
|
||||||
|
# [*tacker_api_paste_ini*]
|
||||||
|
# (optional) Allow configuration of /etc/tacker/api-paste.ini options.
|
||||||
|
#
|
||||||
# NOTE: The configuration MUST NOT be already handled by this module
|
# NOTE: The configuration MUST NOT be already handled by this module
|
||||||
# or Puppet catalog compilation will fail with duplicate resources.
|
# or Puppet catalog compilation will fail with duplicate resources.
|
||||||
#
|
#
|
||||||
class tacker::config (
|
class tacker::config (
|
||||||
$tacker_config = {},
|
$tacker_config = {},
|
||||||
|
$tacker_api_paste_ini = {},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include tacker::deps
|
include tacker::deps
|
||||||
|
|
||||||
validate_legacy(Hash, 'validate_hash', $tacker_config)
|
validate_legacy(Hash, 'validate_hash', $tacker_config)
|
||||||
|
validate_legacy(Hash, 'validate_hash', $tacker_api_paste_ini)
|
||||||
|
|
||||||
create_resources('tacker_config', $tacker_config)
|
create_resources('tacker_config', $tacker_config)
|
||||||
|
create_resources('tacker_api_paste_ini', $tacker_api_paste_ini)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,11 @@ class tacker::deps {
|
||||||
~> Service<| tag == 'tacker-service' |>
|
~> Service<| tag == 'tacker-service' |>
|
||||||
~> anchor { 'tacker::service::end': }
|
~> anchor { 'tacker::service::end': }
|
||||||
|
|
||||||
|
# paste-api.ini config should occur in the config block also.
|
||||||
|
Anchor['tacker::config::begin']
|
||||||
|
-> Tacker_api_paste_ini<||>
|
||||||
|
~> Anchor['tacker::config::end']
|
||||||
|
|
||||||
# all coordination settings should be applied and all packages should be
|
# all coordination settings should be applied and all packages should be
|
||||||
# installed before service startup
|
# installed before service startup
|
||||||
Oslo::Coordination<||> -> Anchor['tacker::service::begin']
|
Oslo::Coordination<||> -> Anchor['tacker::service::begin']
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The new ``tacker_api_paste_ini`` resource type has been added. This allows
|
||||||
|
customizing ``/etc/tacker/api-paste.ini``.
|
||||||
|
|
||||||
|
- |
|
||||||
|
The new ``tacker::config::tacker_api_paste_ini`` parameter has been added.
|
|
@ -0,0 +1,50 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'tacker::config' do
|
||||||
|
|
||||||
|
let(:config_hash) do {
|
||||||
|
'DEFAULT/foo' => { 'value' => 'fooValue' },
|
||||||
|
'DEFAULT/bar' => { 'value' => 'barValue' },
|
||||||
|
'DEFAULT/baz' => { 'ensure' => 'absent' }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'tacker_config' do
|
||||||
|
let :params do
|
||||||
|
{ :tacker_config => config_hash }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to contain_class('tacker::deps') }
|
||||||
|
|
||||||
|
it 'configures arbitrary tacker-config configurations' do
|
||||||
|
is_expected.to contain_tacker_config('DEFAULT/foo').with_value('fooValue')
|
||||||
|
is_expected.to contain_tacker_config('DEFAULT/bar').with_value('barValue')
|
||||||
|
is_expected.to contain_tacker_config('DEFAULT/baz').with_ensure('absent')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'tacker_api_paste_ini' do
|
||||||
|
let :params do
|
||||||
|
{ :tacker_api_paste_ini => config_hash }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures arbitrary tacker-api-paste-ini configurations' do
|
||||||
|
is_expected.to contain_tacker_api_paste_ini('DEFAULT/foo').with_value('fooValue')
|
||||||
|
is_expected.to contain_tacker_api_paste_ini('DEFAULT/bar').with_value('barValue')
|
||||||
|
is_expected.to contain_tacker_api_paste_ini('DEFAULT/baz').with_ensure('absent')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on_supported_os({
|
||||||
|
:supported_os => OSDefaults.get_supported_os
|
||||||
|
}).each do |os,facts|
|
||||||
|
context "on #{os}" do
|
||||||
|
let (:facts) do
|
||||||
|
facts.merge!(OSDefaults.get_facts())
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'tacker_config'
|
||||||
|
it_configures 'tacker_api_paste_ini'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
provider_class = Puppet::Type.type(:tacker_api_paste_ini).provider(:ini_setting)
|
||||||
|
describe provider_class do
|
||||||
|
|
||||||
|
it 'should allow setting to be set explicitly' do
|
||||||
|
resource = Puppet::Type::Tacker_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
|
|
@ -0,0 +1,24 @@
|
||||||
|
require 'puppet'
|
||||||
|
require 'puppet/type/tacker_api_paste_ini'
|
||||||
|
|
||||||
|
describe 'Puppet::Type.type(:tacker_api_paste_ini)' do
|
||||||
|
before :each do
|
||||||
|
@tacker_api_paste_ini = Puppet::Type.type(:tacker_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should accept a valid value' do
|
||||||
|
@tacker_api_paste_ini[:value] = 'bar'
|
||||||
|
expect(@tacker_api_paste_ini[:value]).to eq('bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should autorequire the package that install the file' do
|
||||||
|
catalog = Puppet::Resource::Catalog.new
|
||||||
|
anchor = Puppet::Type.type(:anchor).new(:name => 'tacker::install::end')
|
||||||
|
catalog.add_resource anchor, @tacker_api_paste_ini
|
||||||
|
dependency = @tacker_api_paste_ini.autorequire
|
||||||
|
expect(dependency.size).to eq(1)
|
||||||
|
expect(dependency[0].target).to eq(@tacker_api_paste_ini)
|
||||||
|
expect(dependency[0].source).to eq(anchor)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue