Merge "Allow to configure container_sync middleware"
This commit is contained in:
		
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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`
 | 
					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
 | 
					Limitations
 | 
				
			||||||
------------
 | 
					------------
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
				
			||||||
							
								
								
									
										53
									
								
								lib/puppet/type/swift_container_sync_realms_config.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								lib/puppet/type/swift_container_sync_realms_config.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -20,12 +20,19 @@
 | 
				
			|||||||
#   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.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					# [*swift_container_sync_realms_config*]
 | 
				
			||||||
 | 
					#   (optional) Allow configuration for specifying the allowable
 | 
				
			||||||
 | 
					#   clusters and their information.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
class swift::config (
 | 
					class swift::config (
 | 
				
			||||||
  $swift_config                       = {},
 | 
					  $swift_config                       = {},
 | 
				
			||||||
 | 
					  $swift_container_sync_realms_config = {}
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  include ::swift::deps
 | 
					  include ::swift::deps
 | 
				
			||||||
  validate_hash($swift_config)
 | 
					  validate_hash($swift_config)
 | 
				
			||||||
 | 
					  validate_hash($swift_container_sync_realms_config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  create_resources('swift_config', $swift_config)
 | 
					  create_resources('swift_config', $swift_config)
 | 
				
			||||||
 | 
					  create_resources('swift_container_sync_realms_config', $swift_container_sync_realms_config)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								manifests/proxy/container_sync.pp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								manifests/proxy/container_sync.pp
									
									
									
									
									
										Normal 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',
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								releasenotes/notes/container_sync-5869bca433355047.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								releasenotes/notes/container_sync-5869bca433355047.yaml
									
									
									
									
									
										Normal 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.
 | 
				
			||||||
@@ -15,6 +15,7 @@ describe 'basic swift_config resource' do
 | 
				
			|||||||
      File <||> -> Swift_dispersion_config <||>
 | 
					      File <||> -> Swift_dispersion_config <||>
 | 
				
			||||||
      File <||> -> Swift_object_config <||>
 | 
					      File <||> -> Swift_object_config <||>
 | 
				
			||||||
      File <||> -> Swift_proxy_config <||>
 | 
					      File <||> -> Swift_proxy_config <||>
 | 
				
			||||||
 | 
					      File <||> -> Swift_container_sync_realms_config <||>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      file { '/etc/swift' :
 | 
					      file { '/etc/swift' :
 | 
				
			||||||
        ensure => directory,
 | 
					        ensure => directory,
 | 
				
			||||||
@@ -26,7 +27,8 @@ describe 'basic swift_config resource' do
 | 
				
			|||||||
                       '/etc/swift/container-server.conf',
 | 
					                       '/etc/swift/container-server.conf',
 | 
				
			||||||
                       '/etc/swift/dispersion.conf',
 | 
					                       '/etc/swift/dispersion.conf',
 | 
				
			||||||
                       '/etc/swift/object-server.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  :
 | 
					      file { $swift_files  :
 | 
				
			||||||
        ensure => file,
 | 
					        ensure => file,
 | 
				
			||||||
@@ -157,6 +159,24 @@ describe 'basic swift_config resource' do
 | 
				
			|||||||
        value             => 'toto',
 | 
					        value             => 'toto',
 | 
				
			||||||
        ensure_absent_val => '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
 | 
					      EOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -171,7 +191,8 @@ describe 'basic swift_config resource' do
 | 
				
			|||||||
                     '/etc/swift/container-server.conf',
 | 
					                     '/etc/swift/container-server.conf',
 | 
				
			||||||
                     '/etc/swift/dispersion.conf',
 | 
					                     '/etc/swift/dispersion.conf',
 | 
				
			||||||
                     '/etc/swift/object-server.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|
 | 
					    $swift_files.each do |swift_conf_file|
 | 
				
			||||||
      describe file(swift_conf_file) do
 | 
					      describe file(swift_conf_file) do
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								spec/classes/swift_proxy_container_sync_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								spec/classes/swift_proxy_container_sync_spec.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -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
 | 
				
			||||||
							
								
								
									
										19
									
								
								spec/unit/type/swift_container_sync_realms_config.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								spec/unit/type/swift_container_sync_realms_config.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
							
								
								
									
										3
									
								
								templates/proxy/container_sync.conf.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								templates/proxy/container_sync.conf.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					[filter:container_sync]
 | 
				
			||||||
 | 
					use = egg:swift#container_sync
 | 
				
			||||||
		Reference in New Issue
	
	Block a user