Add a swift_drive_audit_config puppet type
This patch adds what's necessary to configure drive-audit.conf Change-Id: I9bee191412ead21f8fd765b8839b6d63f628bb9c
This commit is contained in:

committed by
Takashi Kajinami

parent
3ccb2cd44e
commit
4d92952345
10
lib/puppet/provider/swift_drive_audit_config/ini_setting.rb
Normal file
10
lib/puppet/provider/swift_drive_audit_config/ini_setting.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Puppet::Type.type(:swift_drive_audit_config).provide(
|
||||||
|
:ini_setting,
|
||||||
|
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
|
||||||
|
) do
|
||||||
|
|
||||||
|
def self.file_path
|
||||||
|
'/etc/swift/drive-audit.conf'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
53
lib/puppet/type/swift_drive_audit_config.rb
Normal file
53
lib/puppet/type/swift_drive_audit_config.rb
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
Puppet::Type.newtype(:swift_drive_audit_config) do
|
||||||
|
|
||||||
|
ensurable
|
||||||
|
|
||||||
|
newparam(:name, :namevar => true) do
|
||||||
|
desc 'Section/setting name to manage from /etc/swift/drive-audit.conf'
|
||||||
|
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
|
||||||
|
newvalues(/^[\S ]*$/)
|
||||||
|
|
||||||
|
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(:anchor) do
|
||||||
|
['swift::install::end']
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@@ -59,6 +59,12 @@ class swift::deps {
|
|||||||
-> Swift_container_uwsgi_config<||>
|
-> Swift_container_uwsgi_config<||>
|
||||||
~> Anchor['swift::config::end']
|
~> Anchor['swift::config::end']
|
||||||
|
|
||||||
|
# drive-audit.conf is not used by swift services, so any change in the file
|
||||||
|
# should not trigger restarting services.
|
||||||
|
Anchor['swift::config::begin']
|
||||||
|
-> Swift_drive_audit_config<||>
|
||||||
|
-> Anchor['swift::config::end']
|
||||||
|
|
||||||
# Support packages need to be installed in the install phase, but we don't
|
# Support packages need to be installed in the install phase, but we don't
|
||||||
# put them in the chain above because we don't want any false dependencies
|
# put them in the chain above because we don't want any false dependencies
|
||||||
# between packages with the swift-package tag and the swift-support-package
|
# between packages with the swift-package tag and the swift-support-package
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
$LOAD_PATH.push(
|
||||||
|
File.join(
|
||||||
|
File.dirname(__FILE__),
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'fixtures',
|
||||||
|
'modules',
|
||||||
|
'inifile',
|
||||||
|
'lib')
|
||||||
|
)
|
||||||
|
$LOAD_PATH.push(
|
||||||
|
File.join(
|
||||||
|
File.dirname(__FILE__),
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'..',
|
||||||
|
'fixtures',
|
||||||
|
'modules',
|
||||||
|
'openstacklib',
|
||||||
|
'lib')
|
||||||
|
)
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
provider_class = Puppet::Type.type(:swift_drive_audit_config).provider(:ini_setting)
|
||||||
|
|
||||||
|
describe provider_class do
|
||||||
|
|
||||||
|
it 'should default to the default setting when no other one is specified' do
|
||||||
|
resource = Puppet::Type::Swift_drive_audit_config.new(
|
||||||
|
{
|
||||||
|
:name => 'DEFAULT/foo',
|
||||||
|
:value => 'bar'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
provider = provider_class.new(resource)
|
||||||
|
expect(provider.section).to eq('DEFAULT')
|
||||||
|
expect(provider.setting).to eq('foo')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow setting to be set explicitly' do
|
||||||
|
resource = Puppet::Type::Swift_drive_audit_config.new(
|
||||||
|
{
|
||||||
|
:name => 'dude/foo',
|
||||||
|
:value => 'bar'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
provider = provider_class.new(resource)
|
||||||
|
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::Swift_drive_audit_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::Swift_drive_audit_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
|
19
spec/unit/type/swift_drive_audit_config_spec.rb
Normal file
19
spec/unit/type/swift_drive_audit_config_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
require 'puppet'
|
||||||
|
require 'puppet/type/swift_drive_audit_config'
|
||||||
|
|
||||||
|
describe 'Puppet::Type.type(:swift_drive_audit_config)' do
|
||||||
|
before :each do
|
||||||
|
@swift_drive_audit_config = Puppet::Type.type(:swift_drive_audit_config).new(:name => 'DEFAULT/foo', :value => 'bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should autorequire the package that install the file' do
|
||||||
|
catalog = Puppet::Resource::Catalog.new
|
||||||
|
anchor = Puppet::Type.type(:anchor).new(:name => 'swift::install::end')
|
||||||
|
catalog.add_resource anchor, @swift_drive_audit_config
|
||||||
|
dependency = @swift_drive_audit_config.autorequire
|
||||||
|
expect(dependency.size).to eq(1)
|
||||||
|
expect(dependency[0].target).to eq(@swift_drive_audit_config)
|
||||||
|
expect(dependency[0].source).to eq(anchor)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Reference in New Issue
Block a user