Skip to content

Commit

Permalink
Update mysql allowed_hosts conditional statement
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Xingchao Yu committed Aug 4, 2013
1 parent 9b17b8d commit 1010779
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
11 changes: 9 additions & 2 deletions manifests/db/mysql.pp
Expand Up @@ -46,8 +46,15 @@
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,
Expand Down
59 changes: 59 additions & 0 deletions spec/classes/ceilometer_db_mysql_spec.rb
Expand Up @@ -48,4 +48,63 @@

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

0 comments on commit 1010779

Please sign in to comment.