Update mysql allowed_hosts conditional statement

In the origin ceilometer::db::mysql, if the value of $allowed_hosts
contains or equals to $host, then puppet will complain duplicate
declaration error. This patch is aim to update the allowed_hosts
conditonal statement in ceilometer::db::mysql.

There are two cases to pass $allowed_hosts to $real_allowed_hosts:

   - If $allowed_hosts is array,then remove $host from $allowed_hosts;
   - elsif $allowed_hosts is string and not equivalent to $host;

At last, if $real_allowed_hosts is not undef, then run
ceilometer::db::mysql::host_access

Fix bug 1206444

Change-Id: Ib6c33e6a27113d01326bee32c105fea4003059ce
This commit is contained in:
Xingchao Yu 2013-08-04 17:09:06 +08:00
parent 9b17b8dadc
commit 10107796ff
2 changed files with 68 additions and 2 deletions

View File

@ -46,8 +46,15 @@ class ceilometer::db::mysql(
require => Class['mysql::config'],
}
if $allowed_hosts {
ceilometer::db::mysql::host_access { $allowed_hosts:
# Check allowed_hosts to avoid duplicate resource declarations
if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] {
$real_allowed_hosts = delete($allowed_hosts,$host)
} elsif is_string($allowed_hosts) and ($allowed_hosts != $host) {
$real_allowed_hosts = $allowed_hosts
}
if $real_allowed_hosts {
ceilometer::db::mysql::host_access { $real_allowed_hosts:
user => $user,
password => $password,
database => $dbname,

View File

@ -48,4 +48,63 @@ describe 'ceilometer::db::mysql' do
it_configures 'ceilometer mysql database'
end
describe "overriding allowed_hosts param to array" do
let :facts do
{ :osfamily => "Debian" }
end
let :params do
{
:password => 'ceilometerpass',
:allowed_hosts => ['localhost','%']
}
end
it {should_not contain_ceilometer__db__mysql__host_access("localhost").with(
:user => 'ceilometer',
:password => 'ceilometerpass',
:database => 'ceilometer'
)}
it {should contain_ceilometer__db__mysql__host_access("%").with(
:user => 'ceilometer',
:password => 'ceilometerpass',
:database => 'ceilometer'
)}
end
describe "overriding allowed_hosts param to string" do
let :facts do
{ :osfamily => 'RedHat' }
end
let :params do
{
:password => 'ceilometerpass2',
:allowed_hosts => '192.168.1.1'
}
end
it {should contain_ceilometer__db__mysql__host_access("192.168.1.1").with(
:user => 'ceilometer',
:password => 'ceilometerpass2',
:database => 'ceilometer'
)}
end
describe "overriding allowed_hosts param equals to host param " do
let :facts do
{ :osfamily => 'RedHat' }
end
let :params do
{
:password => 'ceilometerpass2',
:allowed_hosts => 'localhost'
}
end
it {should_not contain_ceilometer__db__mysql__host_access("localhost").with(
:user => 'ceilometer',
:password => 'ceilometerpass2',
:database => 'ceilometer'
)}
end
end