diff --git a/README.md b/README.md index 5cce937c..21f63ccc 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/lib/puppet/provider/swift_container_sync_realms_config/ini_setting.rb b/lib/puppet/provider/swift_container_sync_realms_config/ini_setting.rb new file mode 100644 index 00000000..3d215ee6 --- /dev/null +++ b/lib/puppet/provider/swift_container_sync_realms_config/ini_setting.rb @@ -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 diff --git a/lib/puppet/type/swift_container_sync_realms_config.rb b/lib/puppet/type/swift_container_sync_realms_config.rb new file mode 100644 index 00000000..9960921c --- /dev/null +++ b/lib/puppet/type/swift_container_sync_realms_config.rb @@ -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('') + end + + autorequire(:package) do + 'swift' + end + +end diff --git a/manifests/config.pp b/manifests/config.pp index 50f2b22e..089e12f8 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -20,12 +20,19 @@ # 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 = {} ) { include ::swift::deps 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) } diff --git a/manifests/proxy/container_sync.pp b/manifests/proxy/container_sync.pp new file mode 100644 index 00000000..a5d1eda7 --- /dev/null +++ b/manifests/proxy/container_sync.pp @@ -0,0 +1,14 @@ +# +# Configure Swift Container Sync +# +# == Authors +# +# Denis Egorenko +# +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', + } +} diff --git a/releasenotes/notes/container_sync-5869bca433355047.yaml b/releasenotes/notes/container_sync-5869bca433355047.yaml new file mode 100644 index 00000000..d11722ef --- /dev/null +++ b/releasenotes/notes/container_sync-5869bca433355047.yaml @@ -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. diff --git a/spec/acceptance/swift_config_spec.rb b/spec/acceptance/swift_config_spec.rb index 41342bbf..692258f3 100644 --- a/spec/acceptance/swift_config_spec.rb +++ b/spec/acceptance/swift_config_spec.rb @@ -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 => '', + } + + swift_container_sync_realms_config { 'DEFAULT/thisshouldexist2' : + value => '', + 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 diff --git a/spec/classes/swift_proxy_container_sync_spec.rb b/spec/classes/swift_proxy_container_sync_spec.rb new file mode 100644 index 00000000..1a24b014 --- /dev/null +++ b/spec/classes/swift_proxy_container_sync_spec.rb @@ -0,0 +1,17 @@ +# +# Author: Denis Egorenko +# +# 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 diff --git a/spec/unit/provider/swift_container_sync_realms_config/ini_setting_spec.rb b/spec/unit/provider/swift_container_sync_realms_config/ini_setting_spec.rb new file mode 100644 index 00000000..32b7dd1d --- /dev/null +++ b/spec/unit/provider/swift_container_sync_realms_config/ini_setting_spec.rb @@ -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 is specified as a value' do + resource = Puppet::Type::Swift_container_sync_realms_config.new( + {:name => 'dude/foo', :value => ''} + ) + 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 diff --git a/spec/unit/type/swift_container_sync_realms_config.rb b/spec/unit/type/swift_container_sync_realms_config.rb new file mode 100644 index 00000000..758be84c --- /dev/null +++ b/spec/unit/type/swift_container_sync_realms_config.rb @@ -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 diff --git a/templates/proxy/container_sync.conf.erb b/templates/proxy/container_sync.conf.erb new file mode 100644 index 00000000..e1d2fc0f --- /dev/null +++ b/templates/proxy/container_sync.conf.erb @@ -0,0 +1,3 @@ + +[filter:container_sync] +use = egg:swift#container_sync