From 4da17a9b8b2523cfe5fa0d25b65dd970f3988131 Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Thu, 12 Jul 2012 11:52:02 +0200 Subject: [PATCH] Display better message on Keystone failure Fixes #148 When there's something wrong with Keystone, Heat reported a rather cryptic message. Now it indicates that the problem is with Keystone and passes its response to the user. Change-Id: I791b5bdfa68faa1b17daa67b911253d8bf8a2bb8 Signed-off-by: Tomas Sedovic --- heat/common/auth.py | 7 ++++++- heat/common/exception.py | 9 +++++++++ heat/utils.py | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/heat/common/auth.py b/heat/common/auth.py index d934993d..c97c284d 100644 --- a/heat/common/auth.py +++ b/heat/common/auth.py @@ -243,7 +243,12 @@ class KeystoneStrategy(BaseStrategy): elif resp.status == 404: raise exception.AuthUrlNotFound(url=token_url) else: - raise Exception(_('Unexpected response: %s') % resp.status) + try: + body = json.loads(resp_body) + msg = body['error']['message'] + except: + msg = resp_body + raise exception.KeystoneError(resp.status, msg) @property def is_authenticated(self): diff --git a/heat/common/exception.py b/heat/common/exception.py index be718ecd..11775c1d 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -29,6 +29,15 @@ class RedirectException(Exception): self.url = urlparse.urlparse(url) +class KeystoneError(Exception): + def __init__(self, code, message): + self.code = code + self.message = message + + def __str__(self): + return "Code: %s, message: %s" % (self.code, self.message) + + def wrap_exception(notifier=None, publisher_id=None, event_type=None, level=None): """This decorator wraps a method to catch any exceptions that may diff --git a/heat/utils.py b/heat/utils.py index 482862e0..71770f77 100644 --- a/heat/utils.py +++ b/heat/utils.py @@ -45,6 +45,11 @@ def catch_error(action): return FAILURE except exception.ClientConfigurationError: raise + except exception.KeystoneError, e: + logging.error("Keystone did not finish the authentication and " + "returned the following message:\n\n%s" + % e.message) + return FAILURE except Exception, e: options = arguments[0] if options.debug: -- 2.45.2