Update allowed_hosts conditional statement
In the origin nova::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 nova::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 nova::db::mysql::host_access Fix bug 1206444 Change-Id: If018321095e62e1196e0c2e6b623b30acb535020
This commit is contained in:
@@ -24,8 +24,15 @@ class nova::db::mysql(
|
||||
require => Class['mysql::config'],
|
||||
}
|
||||
|
||||
if $allowed_hosts {
|
||||
nova::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 {
|
||||
nova::db::mysql::host_access { $real_allowed_hosts:
|
||||
user => $user,
|
||||
password => $password,
|
||||
database => $dbname,
|
||||
|
@@ -63,4 +63,63 @@ describe 'nova::db::mysql' do
|
||||
it { should contain_mysql__db('nova').with_charset(params[:charset]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to array" do
|
||||
let :facts do
|
||||
{ :osfamily => "Debian" }
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass',
|
||||
:allowed_hosts => ['127.0.0.1','%']
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_nova__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'nova',
|
||||
:password => 'novapass',
|
||||
:database => 'nova'
|
||||
)}
|
||||
it {should contain_nova__db__mysql__host_access("%").with(
|
||||
:user => 'nova',
|
||||
:password => 'novapass',
|
||||
:database => 'nova'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param to string" do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass2',
|
||||
:allowed_hosts => '192.168.1.1'
|
||||
}
|
||||
end
|
||||
|
||||
it {should contain_nova__db__mysql__host_access("192.168.1.1").with(
|
||||
:user => 'nova',
|
||||
:password => 'novapass2',
|
||||
:database => 'nova'
|
||||
)}
|
||||
end
|
||||
|
||||
describe "overriding allowed_hosts param equals to host param " do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:password => 'novapass2',
|
||||
:allowed_hosts => '127.0.0.1'
|
||||
}
|
||||
end
|
||||
|
||||
it {should_not contain_nova__db__mysql__host_access("127.0.0.1").with(
|
||||
:user => 'nova',
|
||||
:password => 'novapass2',
|
||||
:database => 'nova'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user