Merge "Use swift_dispersion_config"

This commit is contained in:
Jenkins 2013-09-20 07:47:24 +00:00 committed by Gerrit Code Review
commit 5a655f8694
3 changed files with 91 additions and 98 deletions

View File

@ -55,29 +55,43 @@
# #
class swift::dispersion ( class swift::dispersion (
$auth_url = 'http://127.0.0.1:5000/v2.0/', $auth_url = 'http://127.0.0.1:5000/v2.0/',
$auth_user = 'dispersion', $auth_user = 'dispersion',
$auth_tenant = 'services', $auth_tenant = 'services',
$auth_pass = 'dispersion_password', $auth_pass = 'dispersion_password',
$auth_version = '2.0', $auth_version = '2.0',
$swift_dir = '/etc/swift', $swift_dir = '/etc/swift',
$coverage = 1, $coverage = 1,
$retries = 5, $retries = 5,
$concurrency = 25, $concurrency = 25,
$dump_json = 'no' $dump_json = 'no'
) { ) {
include swift::params include swift::params
Package['swift'] -> Swift_dispersion_config<||>
Swift_dispersion_config<||> ~> Exec['swift-dispersion-populate']
file { '/etc/swift/dispersion.conf': file { '/etc/swift/dispersion.conf':
ensure => present, ensure => present,
content => template('swift/dispersion.conf.erb'),
owner => 'swift', owner => 'swift',
group => 'swift', group => 'swift',
mode => '0660', mode => '0660',
require => Package['swift'], require => Package['swift'],
} }
swift_dispersion_config {
'dispersion/auth_url': value => $auth_url;
'dispersion/auth_user': value => "${auth_tenant}:${auth_user}";
'dispersion/auth_key': value => $auth_pass;
'dispersion/auth_version': value => $auth_version;
'dispersion/swift_dir': value => $swift_dir;
'dispersion/dispersion_coverage': value => $coverage;
'dispersion/retries': value => $retries;
'dispersion/concurrency': value => $concurrency;
'dispersion/dump_json': value => $dump_json;
}
exec { 'swift-dispersion-populate': exec { 'swift-dispersion-populate':
path => ['/bin', '/usr/bin'], path => ['/bin', '/usr/bin'],
subscribe => File['/etc/swift/dispersion.conf'], subscribe => File['/etc/swift/dispersion.conf'],

View File

@ -2,10 +2,31 @@ require 'spec_helper'
describe 'swift::dispersion' do describe 'swift::dispersion' do
let :default_params do
{ :auth_url => 'http://127.0.0.1:5000/v2.0/',
:auth_user => 'dispersion',
:auth_tenant => 'services',
:auth_pass => 'dispersion_password',
:auth_version => '2.0',
:swift_dir => '/etc/swift',
:coverage => 1,
:retries => 5,
:concurrency => 25,
:dump_json => 'no' }
end
let :pre_condition do
"class { 'swift': swift_hash_suffix => 'string' }"
end
let :facts do let :facts do
{ :osfamily => 'Debian' } { :osfamily => 'Debian' }
end end
let :params do
{}
end
it { should contain_file('/etc/swift/dispersion.conf').with( it { should contain_file('/etc/swift/dispersion.conf').with(
:ensure => 'present', :ensure => 'present',
:owner => 'swift', :owner => 'swift',
@ -14,50 +35,53 @@ describe 'swift::dispersion' do
:require => 'Package[swift]') :require => 'Package[swift]')
} }
shared_examples 'swift::dispersion' do
let (:p) { default_params.merge!(params) }
it 'depends on swift package' do
should contain_package('swift').with_before(/Swift_dispersion_config\[.+\]/)
end
it 'configures dispersion.conf' do
should contain_swift_dispersion_config(
'dispersion/auth_url').with_value(p[:auth_url])
should contain_swift_dispersion_config(
'dispersion/auth_version').with_value(p[:auth_version])
should contain_swift_dispersion_config(
'dispersion/auth_user').with_value("#{p[:auth_tenant]}:#{p[:auth_user]}")
should contain_swift_dispersion_config(
'dispersion/auth_key').with_value(p[:auth_pass])
should contain_swift_dispersion_config(
'dispersion/swift_dir').with_value(p[:swift_dir])
should contain_swift_dispersion_config(
'dispersion/dispersion_coverage').with_value(p[:coverage])
should contain_swift_dispersion_config(
'dispersion/retries').with_value(p[:retries])
should contain_swift_dispersion_config(
'dispersion/concurrency').with_value(p[:concurrency])
should contain_swift_dispersion_config(
'dispersion/dump_json').with_value(p[:dump_json])
end
it 'triggers swift-dispersion-populate' do
should contain_exec('swift-dispersion-populate').with(
:path => ['/bin', '/usr/bin'],
:subscribe => 'File[/etc/swift/dispersion.conf]',
:onlyif => "swift -A #{p[:auth_url]} -U #{p[:auth_tenant]}:#{p[:auth_user]} -K #{p[:auth_pass]} -V #{p[:auth_version]} stat | grep 'Account: '",
:unless => "swift -A #{p[:auth_url]} -U #{p[:auth_tenant]}:#{p[:auth_user]} -K #{p[:auth_pass]} -V #{p[:auth_version]} list | grep dispersion_",
:require => 'Package[swiftclient]'
)
end
end
describe 'with default parameters' do describe 'with default parameters' do
it { should contain_file('/etc/swift/dispersion.conf') \ include_examples 'swift::dispersion'
.with_content(/^\[dispersion\]$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_url = http:\/\/127.0.0.1:5000\/v2.0\/$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_version = 2.0$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_user = services:dispersion$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_key = dispersion_password$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^swift_dir = \/etc\/swift$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^dispersion_coverage = 1$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^retries = 5$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^concurrency = 25$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^dump_json = no$/)
}
it { should contain_exec('swift-dispersion-populate').with(
:path => ['/bin', '/usr/bin'],
:subscribe => 'File[/etc/swift/dispersion.conf]',
:onlyif => "swift -A http://127.0.0.1:5000/v2.0/ -U services:dispersion -K dispersion_password -V 2.0 stat | grep 'Account: '",
:unless => "swift -A http://127.0.0.1:5000/v2.0/ -U services:dispersion -K dispersion_password -V 2.0 list | grep dispersion_",
:require => 'Package[swiftclient]'
)}
end end
describe 'when parameters are overriden' do describe 'when parameters are overriden' do
let :params do before do
{ params.merge!(
:auth_url => 'https://169.254.0.1:7000/auth/v8.0/', :auth_url => 'https://10.0.0.10:7000/auth/v8.0/',
:auth_user => 'foo', :auth_user => 'foo',
:auth_tenant => 'bar', :auth_tenant => 'bar',
:auth_pass => 'dummy', :auth_pass => 'dummy',
@ -67,43 +91,9 @@ describe 'swift::dispersion' do
:retries => 51, :retries => 51,
:concurrency => 4682, :concurrency => 4682,
:dump_json => 'yes' :dump_json => 'yes'
} )
end end
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^\[dispersion\]$/) include_examples 'swift::dispersion'
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_url = https:\/\/169.254.0.1:7000\/auth\/v8.0\/$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_version = 1.0$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_user = bar:foo$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^auth_key = dummy$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^swift_dir = \/usr\/local\/etc\/swift$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^dispersion_coverage = 42$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^retries = 51$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^concurrency = 4682$/)
}
it { should contain_file('/etc/swift/dispersion.conf') \
.with_content(/^dump_json = yes$/)
}
it { should contain_exec('swift-dispersion-populate').with(
:path => ['/bin', '/usr/bin'],
:subscribe => 'File[/etc/swift/dispersion.conf]',
:onlyif => "swift -A https://169.254.0.1:7000/auth/v8.0/ -U bar:foo -K dummy -V 1.0 stat | grep 'Account: '",
:unless => "swift -A https://169.254.0.1:7000/auth/v8.0/ -U bar:foo -K dummy -V 1.0 list | grep dispersion_"
)}
end end
end end

View File

@ -1,11 +0,0 @@
[dispersion]
auth_url = <%= @auth_url %>
auth_version = <%= @auth_version %>
auth_user = <%= @auth_tenant %>:<%= @auth_user %>
auth_key = <%= @auth_pass %>
swift_dir = <%= @swift_dir %>
dispersion_coverage = <%= @coverage %>
retries = <%= @retries %>
concurrency = <%= @concurrency %>
dump_json = <%= @dump_json %>