summaryrefslogtreecommitdiff
path: root/keystoneclient/client.py
diff options
context:
space:
mode:
authorDavanum Srinivas <dims@linux.vnet.ibm.com>2013-03-04 14:46:32 -0500
committerDavanum Srinivas <dims@linux.vnet.ibm.com>2013-03-04 14:47:49 -0500
commit06d9437e8388b369546d760607f17cb5022750e9 (patch)
tree443648d0d13b47d2d22784e06e01c01aba8cd67c /keystoneclient/client.py
parent3ce3fe80cb771c6d6082d9fac4986d7b5d09ab6a (diff)
downloadpython-keystoneclient-06d9437e8388b369546d760607f17cb5022750e9.tar.gz
Work better in server env with no keyrings
We should not try loading keyrings if we dont' have to. We certainly should not print messages if keyrings are not even needed Fix for LP# 1145071 Change-Id: I700a2b40620359f6f1fbe03c6a6239d162ddea61
Diffstat (limited to 'keystoneclient/client.py')
-rw-r--r--keystoneclient/client.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/keystoneclient/client.py b/keystoneclient/client.py
index b1d7dbc..fb5c6db 100644
--- a/keystoneclient/client.py
+++ b/keystoneclient/client.py
@@ -33,17 +33,17 @@ from keystoneclient import exceptions
_logger = logging.getLogger(__name__)
-# keyring init
-keyring_available = True
-try:
- import keyring
- import pickle
-except ImportError:
- if (hasattr(sys.stderr, 'isatty') and sys.stderr.isatty()):
- print >> sys.stderr, 'Failed to load keyring modules.'
- else:
- _logger.warning('Failed to load keyring modules.')
- keyring_available = False
+def try_import_keyring():
+ try:
+ import keyring
+ import pickle
+ return True
+ except ImportError:
+ if (hasattr(sys.stderr, 'isatty') and sys.stderr.isatty()):
+ print >> sys.stderr, 'Failed to load keyring modules.'
+ else:
+ _logger.warning('Failed to load keyring modules.')
+ return False
class HTTPClient(object):
@@ -121,7 +121,7 @@ class HTTPClient(object):
requests.logging.getLogger(requests.__name__).addHandler(ch)
# keyring setup
- self.use_keyring = use_keyring and keyring_available
+ self.use_keyring = use_keyring and try_import_keyring()
self.force_new_token = force_new_token
self.stale_duration = stale_duration or access.STALE_TOKEN_DURATION
self.stale_duration = int(self.stale_duration)