Use native hash for pool_target options

This commit allows the options parameter type from one long formatted
string to a native hash, which is rendered into the right format.

The change is backwards compatible with a deprecation notice.

It uses the join and join_keys_to_values functions provided by
puppetlabs' stdlib module.

Change-Id: Ia436aabf9d346424cb68136c0b47cdda46e762e8
This commit is contained in:
Andy Botting 2016-06-21 15:14:13 +10:00
parent 2c374867ae
commit bd2f0d3fbc
3 changed files with 23 additions and 7 deletions

View File

@ -6,9 +6,13 @@
#
# [*options*]
# Options to be passed to the backend DNS server. This should include host and
# port. For instance for a bind9
# target this could be:
# rndc_host: 192.168.27.100, rndc_port: 953, rndc_config_file: /etc/bind/rndc.conf, rndc_key_file: /etc/bind/rndc.key, port: 53, host: 192.168.27.100
# port. For instance for a bind9 target this could be:
# {'rndc_host' => '192.168.27.100',
# 'rndc_port' => 953,
# 'rndc_config_file' => '/etc/bind/rndc.conf',
# 'rndc_key_file' => '/etc/bind/rndc.key',
# 'port' => 53,
# 'host' => '192.168.27.100'}
#
# [*type*]
# Port number of the target DNS server.
@ -31,8 +35,15 @@ define designate::pool_target (
validate_re($name, '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
validate_array($masters)
if is_hash($options) {
$options_real = join(join_keys_to_values($options,':'),',')
} else {
warning('Passing a string to options is now deprecated, use a hash instead.')
$options_real = $options
}
designate_config {
"pool_target:${name}/options": value => $options;
"pool_target:${name}/options": value => $options_real;
"pool_target:${name}/type": value => $type;
"pool_target:${name}/masters": value => join($masters,',');
}

View File

@ -0,0 +1,4 @@
---
deprecations:
- Passing a string to pool_target::options is now deprecated. This parameter
should now be given as a hash.

View File

@ -7,7 +7,8 @@ describe 'designate::pool_target' do
let :params do
{
:options => 'rndc_host: 192.168.27.100, rndc_port: 953, rndc_config_file: /etc/bind/rndc.conf, rndc_key_file: /etc/bind/rndc.key, port: 53, host: 192.168.27.100',
:options => {'rndc_host' => '192.168.27.100', 'rndc_port' => 953, 'rndc_config_file' => '/etc/bind/rndc.conf',
'rndc_key_file' => '/etc/bind/rndc.key', 'port' => 53, 'host' => '192.168.27.100'},
:type => 'bind9',
:masters => ['127.0.0.1:5354'],
}
@ -25,7 +26,7 @@ describe 'designate::pool_target' do
it { is_expected.to contain_designate__pool_target('f26e0b32-736f-4f0a-831b-039a415c481e') }
it 'configures designate pool-manager pool with default parameters' do
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options])
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options].map{|k,v|"#{k}:#{v}"}.join(','))
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/type').with_value(params[:type])
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/masters').with_value(params[:masters])
end
@ -37,7 +38,7 @@ describe 'designate::pool_target' do
it { is_expected.to contain_designate__pool_target('f26e0b32-736f-4f0a-831b-039a415c481e') }
it 'configures designate pool-manager pool with default parameters' do
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options])
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options].map{|k,v|"#{k}:#{v}"}.join(','))
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/type').with_value(params[:type])
is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/masters').with_value(params[:masters])
end