From 4a70f08a6da882fed1b6e132048f2c3b17e75bb3 Mon Sep 17 00:00:00 2001 From: Boris Odnopozov Date: Thu, 30 Nov 2017 13:38:24 +0200 Subject: [PATCH] Raise Miq exceptions on connect 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 --- .../redhat/infra_manager/api_integration.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb b/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb index 2d7242f51..4bb30701b 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/api_integration.rb @@ -114,11 +114,25 @@ 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) + 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)