From 86225d7bee29203f789580aa0584611e81aacd8a Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Fri, 6 Nov 2015 20:07:15 +0300 Subject: [PATCH] Fix handling Unauthorized exception Added class of exceptions - InvalidCredentials Change-Id: Ic8250b138210e544b6194f59accdfe653f36667e Closes-bug: #1428129 --- fuel_health/config.py | 8 ++++++-- fuel_health/exceptions.py | 8 ++++++++ fuel_health/nmanager.py | 18 ++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/fuel_health/config.py b/fuel_health/config.py index a2b17a08..ff434c12 100644 --- a/fuel_health/config.py +++ b/fuel_health/config.py @@ -782,9 +782,13 @@ class NailgunConfig(object): insecure=False, timeout=10) return ip - except Exception: + except (keystoneclient.exceptions.AuthorizationFailure, + keystoneclient.exceptions.Unauthorized): + raise exceptions.InvalidCredentials + except Exception as e: LOG.warning('Can not pass authorization ' - 'with proxy on {0}'.format(ip)) + 'with proxy on {0}, error: {1}' + .format(ip, e)) LOG.debug(traceback.format_exc()) def set_proxy(self): diff --git a/fuel_health/exceptions.py b/fuel_health/exceptions.py index 858c3d0d..0ca15612 100644 --- a/fuel_health/exceptions.py +++ b/fuel_health/exceptions.py @@ -51,6 +51,14 @@ class InvalidConfiguration(FuelException): message = "Invalid Configuration" +class InvalidCredentials(InvalidConfiguration): + message = ( + "Authorization failure. " + "Please provide the valid credentials for your OpenStack environment, " + "and reattempt." + ) + + class SetProxy(InvalidConfiguration): message = ("Can not set proxy for Health Check." "Make sure that network configuration " diff --git a/fuel_health/nmanager.py b/fuel_health/nmanager.py index a485f6c6..6f39623a 100644 --- a/fuel_health/nmanager.py +++ b/fuel_health/nmanager.py @@ -84,17 +84,15 @@ class OfficialClientManager(fuel_health.manager.Manager): self.identity_client = self._get_identity_client() self.identity_v3_client = self._get_identity_client(version=3) self.clients_initialized = True + except (keystoneclient.exceptions.AuthorizationFailure, + keystoneclient.exceptions.Unauthorized): + self.keystone_error_message = \ + exceptions.InvalidCredentials.message except Exception as e: - if e.__class__.__name__ == 'Unauthorized': - self.keystone_error_message = ('Unable to run test: OpenStack' - ' Authorization Failure. ' - 'If login or ' - 'password was changed, ' - 'please update ' - 'environment settings. ' - 'Please refer to Mirantis ' - 'OpenStack documentation ' - 'for more details.') + LOG.error( + "Unexpected error durring intialize keystoneclient: {0}" + .format(e) + ) LOG.debug(traceback.format_exc()) self.traceback = traceback.format_exc()