From 49b248344f40d61ae7467f1f35547e39d66517ed Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Tue, 30 Jul 2013 18:03:22 +0800 Subject: [PATCH] Update allowed_hosts conditional statement In the origin keystone::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 keystone::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 keystone::db::mysql::host_access Fix bug 1206444 Change-Id: I8701aea9344a9151ce3d7ac8fa5792895a5aac6c --- manifests/db/mysql.pp | 11 ++++-- spec/classes/keystone_db_mysql_spec.rb | 48 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index de7713f50..b018994e8 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -54,8 +54,15 @@ require => Class['mysql::config'], } - if $allowed_hosts { - keystone::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 { + keystone::db::mysql::host_access { $real_allowed_hosts: user => $user, password => $password, database => $dbname, diff --git a/spec/classes/keystone_db_mysql_spec.rb b/spec/classes/keystone_db_mysql_spec.rb index c4256cd2c..8f62751f9 100644 --- a/spec/classes/keystone_db_mysql_spec.rb +++ b/spec/classes/keystone_db_mysql_spec.rb @@ -51,5 +51,53 @@ )} end + describe "overriding allowed_hosts param to array" do + let :params do + { + :password => 'keystonepass', + :allowed_hosts => ['127.0.0.1','%'] + } + end + + it {should_not contain_keystone__db__mysql__host_access("127.0.0.1").with( + :user => 'keystone_admin', + :password => 'keystonepass', + :database => 'keystone' + )} + it {should contain_keystone__db__mysql__host_access("%").with( + :user => 'keystone_admin', + :password => 'keystonepass', + :database => 'keystone' + )} + end + describe "overriding allowed_hosts param to string" do + let :params do + { + :password => 'keystonepass2', + :allowed_hosts => '192.168.1.1' + } + end + + it {should contain_keystone__db__mysql__host_access("192.168.1.1").with( + :user => 'keystone_admin', + :password => 'keystonepass2', + :database => 'keystone' + )} + end + + describe "overriding allowed_hosts param equals to host param " do + let :params do + { + :password => 'keystonepass2', + :allowed_hosts => '127.0.0.1' + } + end + + it {should_not contain_keystone__db__mysql__host_access("127.0.0.1").with( + :user => 'keystone_admin', + :password => 'keystonepass2', + :database => 'keystone' + )} + end end