From 10107796ff2751da858a4616f97e6e3166ec40a8 Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Sun, 4 Aug 2013 17:09:06 +0800 Subject: [PATCH] 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 --- manifests/db/mysql.pp | 11 ++++- spec/classes/ceilometer_db_mysql_spec.rb | 59 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 93c2d9e..3b045a9 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -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, diff --git a/spec/classes/ceilometer_db_mysql_spec.rb b/spec/classes/ceilometer_db_mysql_spec.rb index f0c02b3..0424198 100644 --- a/spec/classes/ceilometer_db_mysql_spec.rb +++ b/spec/classes/ceilometer_db_mysql_spec.rb @@ -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 -- 2.45.2