From c2525c6e63c236b470bd935496875545f91e2b26 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 17 Mar 2022 23:51:38 +0900 Subject: [PATCH] Ensure inet6: formatting for a comma-separated list string Currently the inet6_prefix function recognizes a comma-separated list as a single string, thus the format is not applied. This change ensures the value is converted to an array and the format conversion is properly enforced. Change-Id: I9a1f452c3797ccbda25865ca78f1e3a24103d070 --- manifests/resource/authtoken.pp | 7 +++- .../keystone_resource_authtoken_spec.rb | 39 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/manifests/resource/authtoken.pp b/manifests/resource/authtoken.pp index 3e106e1a5..2f9da6bef 100644 --- a/manifests/resource/authtoken.pp +++ b/manifests/resource/authtoken.pp @@ -294,7 +294,12 @@ define keystone::resource::authtoken( } if !is_service_default($memcached_servers) and !empty($memcached_servers){ - $memcached_servers_real = join(any2array(inet6_prefix($memcached_servers)), ',') + $memcached_servers_array = $memcached_servers ? { + String => split($memcached_servers, ','), + default => $memcached_servers + } + $memcached_servers_real = join(any2array(inet6_prefix($memcached_servers_array)), ',') + if $manage_memcache_package { ensure_packages('python-memcache', { ensure => present, diff --git a/spec/defines/keystone_resource_authtoken_spec.rb b/spec/defines/keystone_resource_authtoken_spec.rb index cd7ffdfb8..9fb3e4a4b 100644 --- a/spec/defines/keystone_resource_authtoken_spec.rb +++ b/spec/defines/keystone_resource_authtoken_spec.rb @@ -180,13 +180,40 @@ describe 'keystone::resource::authtoken' do end context 'when specifying IPv6 memcached_servers params' do - before do - params.merge! ({ - :memcached_servers => '[fd12:3456:789a:1::1]:11211', - }) + context 'by a string' do + before do + params.merge! ({ + :memcached_servers => '[fd12:3456:789a:1::1]:11211', + }) + end + it 'configures memcache severs with inet6: prefix in keystone authtoken' do + is_expected.to contain_keystone_config('keystone_authtoken/memcached_servers')\ + .with_value('inet6:[fd12:3456:789a:1::1]:11211') + end end - it 'configures memcache severs with inet6: prefix in keystone authtoken' do - is_expected.to contain_keystone_config('keystone_authtoken/memcached_servers').with_value('inet6:[fd12:3456:789a:1::1]:11211') + + context 'by a commma-separated string' do + before do + params.merge! ({ + :memcached_servers => '[fd12:3456:789a:1::1]:11211,[fd12:3456:789a:1::2]:11211', + }) + end + it 'configures memcache severs with inet6: prefix in keystone authtoken' do + is_expected.to contain_keystone_config('keystone_authtoken/memcached_servers')\ + .with_value('inet6:[fd12:3456:789a:1::1]:11211,inet6:[fd12:3456:789a:1::2]:11211') + end + end + + context 'by an array' do + before do + params.merge! ({ + :memcached_servers => ['[fd12:3456:789a:1::1]:11211', '[fd12:3456:789a:1::2]:11211'] + }) + end + it 'configures memcache severs with inet6: prefix in keystone authtoken' do + is_expected.to contain_keystone_config('keystone_authtoken/memcached_servers')\ + .with_value('inet6:[fd12:3456:789a:1::1]:11211,inet6:[fd12:3456:789a:1::2]:11211') + end end end