catch NoKeyringDaemonError from gnomekeyring

Looks like we need to add more exceptions, start to maintain
a tuple of exceptions

Change-Id: I3a027f5d2d8f82fe397e3096ff82358040f3729e
This commit is contained in:
Davanum Srinivas 2013-03-18 12:02:25 -04:00 committed by Gerrit Code Review
parent 593adf229a
commit adb5941df9
1 changed files with 8 additions and 7 deletions

View File

@ -31,17 +31,18 @@ import pkgutil
import sys
HAS_KEYRING = False
all_errors = ValueError
try:
import keyring
HAS_KEYRING = True
try:
if isinstance(keyring.get_keyring(), keyring.backend.GnomeKeyring):
import gnomekeyring
KeyringIOError = gnomekeyring.IOError
else:
KeyringIOError = IOError
all_errors = (ValueError,
gnomekeyring.IOError,
gnomekeyring.NoKeyringDaemonError)
except Exception:
KeyringIOError = IOError
pass
except ImportError:
pass
@ -156,7 +157,7 @@ class SecretsHelper(object):
block = keyring.get_password('novaclient_auth', self._make_key())
if block:
_token, management_url, _tenant_id = block.split('|', 2)
except (KeyringIOError, ValueError):
except all_errors:
pass
return management_url
@ -173,7 +174,7 @@ class SecretsHelper(object):
block = keyring.get_password('novaclient_auth', self._make_key())
if block:
token, _management_url, _tenant_id = block.split('|', 2)
except (KeyringIOError, ValueError):
except all_errors:
pass
return token
@ -186,7 +187,7 @@ class SecretsHelper(object):
block = keyring.get_password('novaclient_auth', self._make_key())
if block:
_token, _management_url, tenant_id = block.split('|', 2)
except (KeyringIOError, ValueError):
except all_errors:
pass
return tenant_id