Skip to content

Commit

Permalink
Translate exceptions from raw_connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam committed Oct 25, 2017
1 parent 3692df0 commit b45dd25
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions app/models/manageiq/providers/openstack/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,32 @@ def raw_connect(password, params, service = "Compute")
authentication = {:userid => user, :password => MiqPassword.try_decrypt(password), :save => false, :role => 'default', :authtype => 'default'}
ems.connection_configurations = [{:endpoint => endpoint,
:authentication => authentication}]
ems.connect(:service => service)

begin
ems.connect(:service => service)
rescue => err
miq_exception = translate_exception(err)
raise unless miq_exception

_log.error("Error Class=#{err.class.name}, Message=#{err.message}")
raise miq_exception
end
end

def translate_exception(err)
require 'excon'
case err
when Excon::Errors::Unauthorized
MiqException::MiqInvalidCredentialsError.new("Login failed due to a bad username or password.")
when Excon::Errors::Timeout
MiqException::MiqUnreachableError.new("Login attempt timed out")
when Excon::Errors::SocketError
MiqException::MiqHostError.new("Socket error: #{err.message}")
when MiqException::MiqInvalidCredentialsError, MiqException::MiqHostError
err
else
MiqException::MiqEVMLoginError.new("Unexpected response returned from system: #{err.message}")
end
end
end

Expand Down Expand Up @@ -132,19 +157,7 @@ def stop_event_monitor_queue_on_credential_change
end

def translate_exception(err)
require 'excon'
case err
when Excon::Errors::Unauthorized
MiqException::MiqInvalidCredentialsError.new "Login failed due to a bad username or password."
when Excon::Errors::Timeout
MiqException::MiqUnreachableError.new "Login attempt timed out"
when Excon::Errors::SocketError
MiqException::MiqHostError.new "Socket error: #{err.message}"
when MiqException::MiqInvalidCredentialsError, MiqException::MiqHostError
err
else
MiqException::MiqEVMLoginError.new "Unexpected response returned from system: #{err.message}"
end
self.class.translate_exception(err)
end

def verify_api_credentials(options = {})
Expand Down

0 comments on commit b45dd25

Please sign in to comment.