3 class PostgresqlValidator
6 def initialize(resource)
13 cmd_init = "#{@resource[:psql_path]} --tuples-only --quiet --no-psqlrc"
15 final_cmd.push cmd_init
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]}'"
25 cmd_parts.each do |k,v|
26 final_cmd.push v if @resource[k]
32 def parse_connect_settings
33 c_settings = @resource[:connect_settings] || {}
34 c_settings.merge! ({ 'PGPASSWORD' => @resource[:db_password] }) if @resource[:db_password]
35 return c_settings.map { |k,v| "#{k}=#{v}" }
38 def attempt_connection(sleep_length, tries)
39 (0..tries-1).each do |try|
40 Puppet.debug "PostgresqlValidator.attempt_connection: Attempting connection to #{@resource[:db_name]}"
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!"
47 Puppet.warning "PostgresqlValidator.attempt_connection: Sleeping for #{sleep_length} seconds"
57 Execution.execute(build_validate_cmd, :uid => @resource[:run_as])
60 def build_validate_cmd
61 "#{parse_connect_settings.join(' ')} #{build_psql_cmd} "