IBM Db2 connection failure fix for error Reason Code 3

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
Vasu1105 2021-08-11 14:58:37 +05:30
parent 65852c2970
commit 39432f29e5
2 changed files with 14 additions and 5 deletions

View file

@ -29,13 +29,18 @@ module Inspec::Resources
private
def run_command
cmd = inspec.command("#{@db2_executable_file_path} attach to #{@db_instance}\;")
out = cmd.stdout + "\n" + cmd.stderr
if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 instance/ || out.downcase =~ /^error:.*/
# check if following specific error is there. Sourcing the db2profile to resolve the error.
if cmd.exit_status != 0 && out =~ /SQL10007N Message "-1390" could not be retrieved. Reason code: "3"/
cmd = inspec.command(". ~/sqllib/db2profile\; #{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} get database manager configuration")
elsif cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 instance/ || out.downcase =~ /^error:.*/
raise Inspec::Exceptions::ResourceFailed, "IBM Db2 connection error: #{out}"
else
cmd = inspec.command("#{@db2_executable_file_path} get database manager configuration")
end
cmd = inspec.command("#{@db2_executable_file_path} get database manager configuration")
out = cmd.stdout + "\n" + cmd.stderr
if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 server/ || out.downcase =~ /^error:.*/
raise Inspec::Exceptions::ResourceFailed, "IBM Db2 query with error: #{out}"

View file

@ -38,12 +38,16 @@ module Inspec::Resources
# connect to the db
cmd = inspec.command("#{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} connect to #{@db_name}\;")
out = cmd.stdout + "\n" + cmd.stderr
if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 / || out.downcase =~ /^error:.*/
# check if following specific error is there. Sourcing the db2profile to resolve the error.
if cmd.exit_status != 0 && out =~ /SQL10007N Message "-1390" could not be retrieved. Reason code: "3"/
cmd = inspec.command(". ~/sqllib/db2profile\; #{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} connect to #{@db_name}\; #{@db2_executable_file_path} #{q}\;")
elsif cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 / || out.downcase =~ /^error:.*/
raise Inspec::Exceptions::ResourceFailed, "IBM Db2 connection error: #{out}"
end
else
# query on the database
cmd = inspec.command("#{@db2_executable_file_path} #{q}\;")
end
out = cmd.stdout + "\n" + cmd.stderr
if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 server/ || out.downcase =~ /^error:.*/
raise Inspec::Exceptions::ResourceFailed, "IBM Db2 query with error: #{out}"