Permalink
Browse files

Don't log an exception for an expected empty catalog.

Cleans up the code around exception handling and logging
when first authenticating (which often returns an unscoped token).
There's no need to be logging an exception on an expected empty
catalog and moreover the except block was a bare "except" which
could mask other errors.

Fixes bug 1070493

Change-Id: I5e791e95ce3f9ab77723a7f4698cb11b169dacfb
  • Loading branch information...
gabrielhurley committed Oct 23, 2012
1 parent e04b0e1 commit 0dfc69806d3767a7f6be91d9df18f20d31866c91
Showing with 12 additions and 5 deletions.
  1. +5 −0 keystoneclient/exceptions.py
  2. +3 −0 keystoneclient/service_catalog.py
  3. +4 −5 keystoneclient/v2_0/client.py
@@ -24,6 +24,11 @@ class EndpointNotFound(Exception):
pass
+class EmptyCatalog(Exception):
+ """ The service catalog is empty. """
+ pass
+
+
class ClientException(Exception):
"""
The base exception class for all exceptions this library raises.
@@ -61,6 +61,9 @@ def url_for(self, attr=None, filter_value=None,
"""
catalog = self.catalog.get('serviceCatalog', [])
+ if not catalog:
+ raise exceptions.EmptyCatalog('The service catalog is empty.')
+
for service in catalog:
if service['type'] != service_type:
continue
@@ -119,8 +119,6 @@ def _extract_service_catalog(self, url, body):
sc = self.service_catalog.get_token()
self.auth_token = sc['id']
# Save these since we have them and they'll be useful later
- # NOTE(termie): these used to be in the token and then were removed
- # ... why?
self.auth_tenant_id = sc.get('tenant_id')
self.auth_user_id = sc.get('user_id')
except KeyError:
@@ -133,6 +131,7 @@ def _extract_service_catalog(self, url, body):
self.management_url = self.service_catalog.url_for(
attr='region', filter_value=self.region_name,
endpoint_type='adminURL')
- except:
- # Unscoped tokens don't return a service catalog
- _logger.exception("unable to retrieve service catalog with token")
+ except exceptions.EmptyCatalog:
+ # Unscoped tokens don't return a service catalog;
+ # allow those to pass while any other errors bubble up.
+ pass

0 comments on commit 0dfc698

Please sign in to comment.