From fbbcd892358d47f5734adcefd5406146a6f33d0e Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Thu, 29 Sep 2016 14:08:07 -0600 Subject: [PATCH] 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 --- manifests/proxy/cache.pp | 4 +- ...uire-for-proxy-cache-cbb2726d22b53d80.yaml | 5 +++ spec/classes/swift_proxy_cache_spec.rb | 40 ++++++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 releasenotes/notes/fix-memcached-require-for-proxy-cache-cbb2726d22b53d80.yaml diff --git a/manifests/proxy/cache.pp b/manifests/proxy/cache.pp index 7e5d67c0..877ccd84 100644 --- a/manifests/proxy/cache.pp +++ b/manifests/proxy/cache.pp @@ -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': diff --git a/releasenotes/notes/fix-memcached-require-for-proxy-cache-cbb2726d22b53d80.yaml b/releasenotes/notes/fix-memcached-require-for-proxy-cache-cbb2726d22b53d80.yaml new file mode 100644 index 00000000..95fd943b --- /dev/null +++ b/releasenotes/notes/fix-memcached-require-for-proxy-cache-cbb2726d22b53d80.yaml @@ -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 diff --git a/spec/classes/swift_proxy_cache_spec.rb b/spec/classes/swift_proxy_cache_spec.rb index 30b29073..715625ac 100644 --- a/spec/classes/swift_proxy_cache_spec.rb +++ b/spec/classes/swift_proxy_cache_spec.rb @@ -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