Fix expected input to osnailyfacter::dnsmasq, ntp and ntp_available
The osnailyfacter::dnsmasq expects the external_dns parameter to be an array. This change adds validation to the dns server list as well as adding support for a single ip address provided as a string. If the list of dns servers is not an array or a single ip address (as string), try to convert input data to array from string. Also do the same for ntp_available function and ntp::init class. Change-Id: I6152b8d73a7b97b30d1d1fed9c8d1f055a9d933b Closes-Bug: #1547654
This commit is contained in:
parent
5dcc5d1598
commit
52dc229607
|
@ -41,6 +41,7 @@ class osnailyfacter::dnsmasq (
|
|||
}
|
||||
|
||||
ensure_packages($package_name)
|
||||
validate_array($external_dns)
|
||||
|
||||
file { '/etc/dnsmasq.d':
|
||||
ensure => directory,
|
||||
|
|
|
@ -7,11 +7,19 @@ $management_vrouter_vip = hiera('management_vrouter_vip')
|
|||
$network_metadata = hiera_hash('network_metadata', {})
|
||||
$vrouter_name = hiera('vrouter_name', 'pub')
|
||||
|
||||
if is_array($dns_servers['dns_list']) {
|
||||
$external_dns = $dns_servers['dns_list']
|
||||
} elsif is_ip_address($dns_servers['dns_list']) {
|
||||
$external_dns = any2array($dns_servers['dns_list'])
|
||||
} else {
|
||||
$external_dns = split($dns_servers['dns_list'], ',')
|
||||
}
|
||||
|
||||
# If VIP has namespace set to 'false' or 'undef' then we do not configure it
|
||||
# under corosync cluster. So we should not configure anything listening it.
|
||||
if $network_metadata['vips']["vrouter_${vrouter_name}"]['namespace'] {
|
||||
class { 'osnailyfacter::dnsmasq':
|
||||
external_dns => $dns_servers['dns_list'],
|
||||
external_dns => $external_dns,
|
||||
master_ip => $master_ip,
|
||||
management_vrouter_vip => $management_vrouter_vip,
|
||||
} ->
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
notice('MODULAR: ntp-check.pp')
|
||||
# get the ntp configuration from hiera
|
||||
$ntp_servers = hiera('external_ntp')
|
||||
|
||||
# take the comma seperated list and turn it into an array of servers and then
|
||||
# pass it to the ntp_available function to check that at least 1 server works
|
||||
ntp_available($ntp_servers['ntp_list'])
|
||||
if is_array($ntp_servers['ntp_list']) {
|
||||
$external_ntp = $ntp_servers['ntp_list']
|
||||
} else {
|
||||
$external_ntp = strip(split($ntp_servers['ntp_list'], ','))
|
||||
}
|
||||
ntp_available($external_ntp)
|
||||
|
|
|
@ -2,8 +2,14 @@ notice('MODULAR: ntp-server.pp')
|
|||
|
||||
$ntp_servers = hiera('external_ntp')
|
||||
|
||||
if is_array($ntp_servers['ntp_list']) {
|
||||
$external_ntp = $ntp_servers['ntp_list']
|
||||
} else {
|
||||
$external_ntp = strip(split($ntp_servers['ntp_list'], ','))
|
||||
}
|
||||
|
||||
class { 'ntp':
|
||||
servers => $ntp_servers['ntp_list'],
|
||||
servers => $external_ntp,
|
||||
service_enable => true,
|
||||
service_ensure => 'running',
|
||||
disable_monitor => true,
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'osnailyfacter::dnsmasq' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Ubuntu',
|
||||
:operatingsystemrelease => '14.04',
|
||||
:concat_basedir => '/var/lib/puppet/concat',
|
||||
:domain => 'example.com'
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
context 'with valid params' do
|
||||
let :params do
|
||||
{
|
||||
:external_dns => ['8.8.8.8', '4.4.4.4'],
|
||||
:master_ip => '10.20.0.2',
|
||||
:management_vrouter_vip => '10.20.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
it 'should ensure package' do
|
||||
should contain_package('dnsmasq-base')
|
||||
end
|
||||
|
||||
it 'should configure dnsmasq' do
|
||||
should contain_file('/etc/dnsmasq.d').with_ensure('directory')
|
||||
should contain_file('/etc/resolv.dnsmasq.conf').with(
|
||||
:ensure => 'present',
|
||||
:content => "nameserver 8.8.8.8\nnameserver 4.4.4.4\n"
|
||||
)
|
||||
should contain_file('/etc/dnsmasq.d/dns.conf').with(
|
||||
:ensure => 'present'
|
||||
).with(
|
||||
:content => /domain=example.com/
|
||||
).with(
|
||||
:content => /listen-address=10.20.0.1/
|
||||
).with(
|
||||
:content => /server=\/example.com\/10.20.0.2/
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid params' do
|
||||
let :params do
|
||||
{
|
||||
:external_dns => '8.8.8.8',
|
||||
:master_ip => '10.20.0.2',
|
||||
:management_vrouter_vip => '10.20.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
it 'should error with string passed to external dns' do
|
||||
expect { catalogue }.to raise_error(Puppet::Error, /is not an Array/)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue