Skip to content

Commit d51730c

Browse files
committed
(maint) fix for connection validator
last fix for postgres 8 ever. postgres 8 does not support the CONNECT privilege or equals signs in the command. --no-password doesn't seem to be required. Also cleaned up conditional in the util script.
1 parent 4dac726 commit d51730c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/puppet/util/postgresql_validator.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ def build_psql_cmd
1515
final_cmd.push cmd_init
1616

1717
cmd_parts = {
18-
:host => "--host=#{@resource[:host]}",
19-
:port => "--port=#{@resource[:port]}",
20-
:db_username => "--username=#{@resource[:db_username]}",
21-
:db_name => "--dbname=#{@resource[:db_name]}",
22-
:command => "--command='#{@resource[:command]}'"
18+
:host => "--host #{@resource[:host]}",
19+
:port => "--port #{@resource[:port]}",
20+
:db_username => "--username #{@resource[:db_username]}",
21+
:db_name => "--dbname #{@resource[:db_name]}",
22+
:command => "--command '#{@resource[:command]}'"
2323
}
2424

25-
cmd_parts[:db_password] = "--no-password " if @resource[:db_password]
26-
2725
cmd_parts.each do |k,v|
2826
final_cmd.push v if @resource[k]
2927
end
@@ -40,8 +38,10 @@ def parse_connect_settings
4038
def attempt_connection(sleep_length, tries)
4139
(0..tries-1).each do |try|
4240
Puppet.debug "PostgresqlValidator.attempt_connection: Attempting connection to #{@resource[:db_name]}"
43-
if execute_command =~ /1/
44-
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name]} successful!"
41+
Puppet.debug "PostgresqlValidator.attempt_connection: #{build_validate_cmd}"
42+
result = execute_command
43+
if result && result.length > 0
44+
Puppet.debug "PostgresqlValidator.attempt_connection: Connection to #{@resource[:db_name] || parse_connect_settings.select { |elem| elem.match /PGDATABASE/ }} successful!"
4545
return true
4646
else
4747
Puppet.warning "PostgresqlValidator.attempt_connection: Sleeping for #{sleep_length} seconds"

spec/acceptance/postgresql_conn_validator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class { 'postgresql::server':
1414
require => Postgresql::Server::Role['testuser']
1515
}->
1616
postgresql::server::database_grant { 'allow connect for testuser':
17-
privilege => 'CONNECT',
17+
privilege => 'ALL',
1818
db => 'testdb',
1919
role => 'testuser',
2020
}

spec/unit/puppet/provider/postgresql_conn_validator/ruby_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
describe '#build_psql_cmd' do
2121
it 'contains expected commandline options' do
22-
expect(provider.validator.build_psql_cmd).to match /\/usr\/bin\/psql.*--host=.*--port=.*--username=.*/
22+
expect(provider.validator.build_psql_cmd).to match /\/usr\/bin\/psql.*--host.*--port.*--username.*/
2323
end
2424
end
2525

0 commit comments

Comments
 (0)