Add support for rootwrap.conf

Change-Id: Ib28c3f1a8b46c439a16874c5695f121bf63c3bb9
changes/61/849161/13
Takashi Kajinami 7 months ago
parent a002cad4d3
commit 1473037e7f

@ -0,0 +1,10 @@
Puppet::Type.type(:glance_rootwrap_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/glance/rootwrap.conf'
end
end

@ -0,0 +1,29 @@
Puppet::Type.newtype(:glance_rootwrap_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/glance/rootwrap.conf'
newvalues(/\S+\/\S+/)
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
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 ]*$/)
end
autorequire(:anchor) do
['glance::install::end']
end
end

@ -29,14 +29,18 @@
# [*image_import_config*]
# (optional) Allow configuration of glance-image-import.conf configurations.
#
# [*rootwrap_config*]
# (optional) Allow configuration of rootwrap.conf configurations.
#
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
class glance::config (
$api_config = {},
$api_paste_ini_config = {},
$cache_config = {},
$image_import_config = {},
$api_config = {},
$api_paste_ini_config = {},
$cache_config = {},
$image_import_config = {},
$rootwrap_config = {},
) {
include glance::deps
@ -45,9 +49,11 @@ class glance::config (
validate_legacy(Hash, 'validate_hash', $api_paste_ini_config)
validate_legacy(Hash, 'validate_hash', $cache_config)
validate_legacy(Hash, 'validate_hash', $image_import_config)
validate_legacy(Hash, 'validate_hash', $rootwrap_config)
create_resources('glance_api_config', $api_config)
create_resources('glance_api_paste_ini', $api_paste_ini_config)
create_resources('glance_cache_config', $cache_config)
create_resources('glance_image_import_config', $image_import_config)
create_resources('glance_rootwrap_config', $rootwrap_config)
}

@ -43,6 +43,7 @@ class glance::deps {
Anchor['glance::config::begin'] -> Glance_cache_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_image_import_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_swift_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_rootwrap_config<||> ~> Anchor['glance::config::end']
# 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

@ -0,0 +1,9 @@
---
features:
- |
The new ``glance_rootwrap_config`` resource has been added. This resource
can be used to manage contents of ``rootwrap.conf``
- |
The new ``glance::config::rootwrap_config`` parameter has been added. This
parameter accepts arbitrary configuration of ``rootwrap.conf``.

@ -13,6 +13,7 @@ describe 'basic glance config resource' do
File <||> -> Glance_image_import_config <||>
File <||> -> Glance_swift_config <||>
File <||> -> Glance_api_paste_ini <||>
File <||> -> Glance_rootwrap_config <||>
file { '/etc/glance' :
ensure => directory,
@ -29,6 +30,9 @@ describe 'basic glance config resource' do
file { '/etc/glance/glance-api-paste.ini' :
ensure => file,
}
file { '/etc/glance/rootwrap.conf' :
ensure => file,
}
glance_api_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
@ -132,6 +136,24 @@ describe 'basic glance config resource' do
value => 'foo',
key_val_separator => ':'
}
glance_rootwrap_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
glance_rootwrap_config { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
glance_rootwrap_config { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
glance_rootwrap_config { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
EOS
@ -199,5 +221,16 @@ describe 'basic glance config resource' do
it { is_expected.not_to match /thisshouldnotexist/ }
end
end
describe file('/etc/glance/rootwrap.conf') do
it { is_expected.to exist }
it { is_expected.to contain('thisshouldexist=foo') }
it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
describe '#content' do
subject { super().content }
it { is_expected.not_to match /thisshouldnotexist/ }
end
end
end
end

@ -54,6 +54,18 @@ describe 'glance::config' do
end
end
shared_examples_for 'glance_rootwrap_config' do
let :params do
{ :rootwrap_config => config_hash }
end
it 'configures arbitrary glance-rootwrap configurations' do
is_expected.to contain_glance_rootwrap_config('DEFAULT/foo').with_value('fooValue')
is_expected.to contain_glance_rootwrap_config('DEFAULT/bar').with_value('barValue')
is_expected.to contain_glance_rootwrap_config('DEFAULT/baz').with_ensure('absent')
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
@ -65,6 +77,7 @@ describe 'glance::config' do
it_configures 'glance_api_config'
it_configures 'glance_cache_config'
it_configures 'glance_image_import_config'
it_configures 'glance_rootwrap_config'
end
end
end

@ -0,0 +1,42 @@
require 'spec_helper'
provider_class = Puppet::Type.type(:glance_rootwrap_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::Glance_rootwrap_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::Glance_rootwrap_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::Glance_rootwrap_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::Glance_rootwrap_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

@ -0,0 +1,64 @@
require 'puppet'
require 'puppet/type/glance_rootwrap_config'
describe 'Puppet::Type.type(:glance_rootwrap_config)' do
before :each do
@glance_rootwrap_config = Puppet::Type.type(:glance_rootwrap_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:glance_rootwrap_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:glance_rootwrap_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:glance_rootwrap_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:glance_rootwrap_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@glance_rootwrap_config[:value] = 'bar'
expect(@glance_rootwrap_config[:value]).to eq('bar')
end
it 'should accept a value with whitespace' do
@glance_rootwrap_config[:value] = 'b ar'
expect(@glance_rootwrap_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@glance_rootwrap_config[:ensure] = :present
expect(@glance_rootwrap_config[:ensure]).to eq(:present)
@glance_rootwrap_config[:ensure] = :absent
expect(@glance_rootwrap_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@glance_rootwrap_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'glance::install::end')
catalog.add_resource anchor, @glance_rootwrap_config
dependency = @glance_rootwrap_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@glance_rootwrap_config)
expect(dependency[0].source).to eq(anchor)
end
end
Loading…
Cancel
Save