Allow to configure container_sync middleware

Add possibility to configure container_sync middleware. Also
allow to configure swift container-sync-realms, which specifying
the allowable clusters and their information, which is required
for container_sync.

Change-Id: I183841cca3daf72a30db160b88c9e3a9335ad7dc
This commit is contained in:
Denis Egorenko 2016-05-23 16:53:23 +03:00
parent a94df7b02a
commit ec4db849c8
11 changed files with 235 additions and 3 deletions

View File

@ -420,6 +420,17 @@ Same as `swift_config`, but path is `/etc/swift/object-server.conf`
Same as `swift_config`, but path is `/etc/swift/proxy-server.conf`
#### swift_container_sync_realms_config
Same as `swift_config`, but path is `/etc/swift/container-sync-realms.conf'
Use this file for specifying the allowable clusters and their information.
```puppet
swift_container_sync_realms_config { 'realm1/cluster_clustername1':
value => 'https://host1/v1/'
}
```
Limitations
------------

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:swift_container_sync_realms_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/swift/container-sync-realms.conf'
end
end

View File

@ -0,0 +1,53 @@
Puppet::Type.newtype(:swift_container_sync_realms_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from /etc/swift/container-sync-realms.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(:package) do
'swift'
end
end

View File

@ -20,11 +20,18 @@
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
# [*swift_container_sync_realms_config*]
# (optional) Allow configuration for specifying the allowable
# clusters and their information.
#
class swift::config (
$swift_config = {},
$swift_config = {},
$swift_container_sync_realms_config = {}
) {
validate_hash($swift_config)
validate_hash($swift_container_sync_realms_config)
create_resources('swift_config', $swift_config)
create_resources('swift_container_sync_realms_config', $swift_container_sync_realms_config)
}

View File

@ -0,0 +1,14 @@
#
# Configure Swift Container Sync
#
# == Authors
#
# Denis Egorenko <degorenko@mirantis.com>
#
class swift::proxy::container_sync() {
concat::fragment { 'swift_container_sync':
target => '/etc/swift/proxy-server.conf',
content => template('swift/proxy/container_sync.conf.erb'),
order => '82',
}
}

View File

@ -0,0 +1,5 @@
---
features:
- Add ability to configure container_sync middleware.
- Add ability to manage swift container-sync-realms config for
specifying the allowable clusters and their information.

View File

@ -15,6 +15,7 @@ describe 'basic swift_config resource' do
File <||> -> Swift_dispersion_config <||>
File <||> -> Swift_object_config <||>
File <||> -> Swift_proxy_config <||>
File <||> -> Swift_container_sync_realms_config <||>
file { '/etc/swift' :
ensure => directory,
@ -26,7 +27,8 @@ describe 'basic swift_config resource' do
'/etc/swift/container-server.conf',
'/etc/swift/dispersion.conf',
'/etc/swift/object-server.conf',
'/etc/swift/proxy-server.conf']
'/etc/swift/proxy-server.conf',
'/etc/swift/container-sync-realms.conf']
file { $swift_files :
ensure => file,
@ -157,6 +159,24 @@ describe 'basic swift_config resource' do
value => 'toto',
ensure_absent_val => 'toto',
}
swift_container_sync_realms_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
swift_container_sync_realms_config { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
swift_container_sync_realms_config { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
swift_container_sync_realms_config { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
EOS
@ -171,7 +191,8 @@ describe 'basic swift_config resource' do
'/etc/swift/container-server.conf',
'/etc/swift/dispersion.conf',
'/etc/swift/object-server.conf',
'/etc/swift/proxy-server.conf']
'/etc/swift/proxy-server.conf',
'/etc/swift/container-sync-realms.conf']
$swift_files.each do |swift_conf_file|
describe file(swift_conf_file) do

View File

@ -0,0 +1,17 @@
#
# Author: Denis Egorenko <degorenko@mirantis.com>
#
# Tests for swift::proxy::container_sync
#
require 'spec_helper'
describe 'swift::proxy::container_sync' do
let :facts do
{}
end
it { is_expected.to contain_concat_fragment('swift_container_sync').with_content(/\[filter:container_sync\]/) }
it { is_expected.to contain_concat_fragment('swift_container_sync').with_content(/use = egg:swift#container_sync/) }
end

View File

@ -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_container_sync_realms_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_container_sync_realms_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_container_sync_realms_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_container_sync_realms_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_container_sync_realms_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

View File

@ -0,0 +1,19 @@
require 'puppet'
require 'puppet/type/swift_container_sync_realms_config'
describe 'Puppet::Type.type(:swift_container_sync_realms_config)' do
before :each do
@swift_container_sync_realms_config = Puppet::Type.type(:swift_container_sync_realms_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'swift-container')
catalog.add_resource package, @swift_container_sync_realms_config
dependency = @swift_container_sync_realms_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@swift_container_sync_realms_config)
expect(dependency[0].source).to eq(package)
end
end

View File

@ -0,0 +1,3 @@
[filter:container_sync]
use = egg:swift#container_sync