Skip to content

Commit

Permalink
Raise Miq exceptions on connect
Browse files Browse the repository at this point in the history
The `raw_connect` method of providers is intended to check connection and authentication details.
This method should report errors throwing instances of `MiqEVMLoginError`, `MiqInvalidCredentialsError`, etc.

This fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1510374
  • Loading branch information
Boris Odnopozov committed Nov 30, 2017
1 parent 3c7ebee commit 51f4a49
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,26 @@ def verify_credentials_for_rhevm(options = {})
raise e
rescue RestClient::Unauthorized
raise MiqException::MiqInvalidCredentialsError, "Incorrect user name or password."
rescue OvirtSDK4::Error => e
rethrow_as_a_miq_error(e)
rescue
_log.error("Error while verifying credentials #{$ERROR_INFO}")
raise MiqException::MiqEVMLoginError, $ERROR_INFO
end

def rethrow_as_a_miq_error(e)
byebug
case e.message
when /The username or password is incorrect/
raise MiqException::MiqInvalidCredentialsError
when /Couldn't connect to server/, /Couldn't resolve host name/
raise MiqException::MiqUnreachableError, $ERROR_INFO
else
_log.error("Error while verifying credentials #{$ERROR_INFO}")
raise MiqException::MiqEVMLoginError, $ERROR_INFO
end
end

def rhevm_metrics_connect_options(options = {})
metrics_hostname = connection_configuration_by_role('metrics')
.try(:endpoint)
Expand Down

0 comments on commit 51f4a49

Please sign in to comment.