Fixed swift::proxy::cache requirement on memcached

Fixed the incorrect inclusion of a requirement for the memcached class
to be in the catalog for swift::proxy::cache due to a bad grep of
the memcached server list. The grep command will return an array of
matching values. Unfortunately this includes if nothing is found so the
if condition was always matching. Now if you are not using a local
memcache server on 127.0.0.1, the memcached class is not required to
be in the catalog.

Change-Id: I79b92dc67e46dfa0b62ba07b00633de6fb17bf1e
Closes-Bug: #1628967
This commit is contained in:
Alex Schultz 2016-09-29 14:08:07 -06:00
parent 5e5aa7fa88
commit fbbcd89235
3 changed files with 32 additions and 17 deletions

View File

@ -25,8 +25,8 @@ class swift::proxy::cache(
include ::swift::deps
# require the memcached class if its on the same machine
if grep(any2array($memcache_servers), '^127\.0\.0\.1') {
Class['memcached'] -> Class['swift::proxy::cache']
if !empty(grep(any2array($memcache_servers), '127.0.0.1')) {
Class['::memcached'] -> Class['::swift::proxy::cache']
}
concat::fragment { 'swift_cache':

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed the incorrect inclusion of a requirement for the memcached class
to be in the catalog for swift::proxy::cache due to a bad grep of the
memcached server list. LP#1628967

View File

@ -10,37 +10,47 @@ describe 'swift::proxy::cache' do
}
end
let :pre_condition do
'class { "memcached": max_memory => 1 }'
describe 'with defaults' do
let :pre_condition do
'class { "memcached": max_memory => 1 }'
end
it 'should have the required classes' do
is_expected.to contain_class('swift::deps')
is_expected.to contain_class('swift::proxy::cache')
end
it 'should properly configure the swift_cache fragment' do
is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/)
is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 127\.0\.0\.1:11211/)
end
end
it { is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/) }
describe 'with defaults' do
it { is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 127\.0\.0\.1:11211/) }
describe 'without memcached being included' do
it 'should raise an error' do
expect { catalogue }.to raise_error(Puppet::Error)
end
end
describe 'with overridden memcache server' do
let :params do
{:memcache_servers => '10.0.0.1:1'}
end
it { is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1/) }
it 'should properly configure the swift_cache fragment' do
is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/)
is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1/)
end
end
describe 'with overridden memcache server array' do
let :params do
{:memcache_servers => ['10.0.0.1:1', '10.0.0.2:2']}
end
it { is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1,10\.0\.0\.2:2/) }
it 'should properly configure the swift_cache fragment' do
is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/)
is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1,10\.0\.0\.2:2/)
end
end
end