]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Display better message on Keystone failure
authorTomas Sedovic <tomas@sedovic.cz>
Thu, 12 Jul 2012 09:52:02 +0000 (11:52 +0200)
committerTomas Sedovic <tomas@sedovic.cz>
Thu, 12 Jul 2012 09:55:52 +0000 (11:55 +0200)
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 <tomas@sedovic.cz>
heat/common/auth.py
heat/common/exception.py
heat/utils.py

index d934993dd6a09789ac1d0c5a741bad7f03527dde..c97c284d6c90d7ef8f638d79d394ea259d29c58d 100644 (file)
@@ -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):
index be718ecd1094bc474612f8e2f360a0ceef214f6b..11775c1d9a33866813d58b87d89fa559ef06f833 100644 (file)
@@ -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
index 482862e030ea685eb4e564702de92e978e099424..71770f7769862d13b624693637774b9925d5b9d7 100644 (file)
@@ -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: