Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 57e93a4

Browse files
committed
Fix #46 mysql::queryfile should be execute on remote server only when remote_host is specified
1 parent 4e3f810 commit 57e93a4

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

manifests/grant.pp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
default => any2bool($mysql_create_db)
9191
}
9292

93+
$manage_remote_host = $remote_host ? {
94+
'' => 'localhost',
95+
default => $remote_host,
96+
}
97+
9398
if (!defined(File[$mysql_grant_filepath])) {
9499
file { $mysql_grant_filepath:
95100
ensure => directory,
@@ -125,7 +130,6 @@
125130
default => undef,
126131
}
127132

128-
129133
exec { "mysqlgrant-${mysql_user}-${nice_mysql_host}-${dbname}":
130134
command => $exec_command,
131135
require => $exec_require,
@@ -137,10 +141,10 @@
137141
if $mysql_db_init_query_file != '' and $mysql_create_db == true {
138142
mysql::queryfile { "mysql_db_init_query_file-${nice_mysql_host}-${dbname}":
139143
mysql_file => $mysql_db_init_query_file,
140-
mysql_user => $mysql_user,
141-
mysql_password => $mysql_password,
144+
mysql_user => $remote_user,
145+
mysql_password => $remote_password,
142146
mysql_db => $mysql_db,
143-
mysql_host => $mysql_host,
147+
mysql_host => $manage_remote_host,
144148
subscribe => Exec["mysqlgrant-${mysql_user}-${nice_mysql_host}-${dbname}"],
145149
}
146150
}

spec/defines/grant_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,50 @@
127127
it { should contain_file('mysqlgrant-someuser-10.42.42.0_255.255.255.0-all.sql').with_content(/REVOKE ALL ON \*\.\* FROM 'someuser'@'10.42.42.0\/255.255.255.0';/) }
128128
it { should contain_file('mysqlgrant-someuser-10.42.42.0_255.255.255.0-all.sql').with_content(/FLUSH PRIVILEGES;/) }
129129
end
130+
131+
describe 'Test grant with initial data' do
132+
let(:params) { {
133+
:name => 'sample1',
134+
:mysql_db => 'example_db',
135+
:mysql_user => 'someuser',
136+
:mysql_password => 'somepassword',
137+
:mysql_db_init_query_file => '/example/42.sql',
138+
} }
139+
140+
it { should contain_mysql__queryfile('mysql_db_init_query_file-localhost-example_db').with_mysql_file('/example/42.sql') }
141+
it { should contain_mysql__queryfile('mysql_db_init_query_file-localhost-example_db').with_mysql_host('localhost') }
142+
end
143+
144+
describe 'Test grant with initial data' do
145+
let(:params) { {
146+
:name => 'sample1',
147+
:mysql_db => 'example_db',
148+
:mysql_host => '10.42.42.0/255.255.255.0',
149+
:mysql_user => 'someuser',
150+
:mysql_password => 'somepassword',
151+
:mysql_db_init_query_file => '/example/42.sql',
152+
} }
153+
154+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_file('/example/42.sql') }
155+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_host('localhost') }
156+
end
157+
158+
describe 'Test grant with initial data' do
159+
let(:params) { {
160+
:name => 'sample1',
161+
:mysql_db => 'example_db',
162+
:mysql_host => '10.42.42.0/255.255.255.0',
163+
:mysql_user => 'someuser',
164+
:mysql_password => 'somepassword',
165+
:mysql_db_init_query_file => '/example/42.sql',
166+
:remote_host => '10.42.42.42',
167+
:remote_user => 'user42',
168+
:remote_password => 'pass42',
169+
} }
170+
171+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_file('/example/42.sql') }
172+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_host('10.42.42.42') }
173+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_user('user42') }
174+
it { should contain_mysql__queryfile('mysql_db_init_query_file-10.42.42.0_255.255.255.0-example_db').with_mysql_password('pass42') }
175+
end
130176
end

0 commit comments

Comments
 (0)