From cca1e40e50855d9d01a72c87013ef15a3c02bc0f Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 17 Jul 2014 16:30:35 +0200 Subject: [PATCH] Only conditionally import working keyring keyring is conditionally imported if available on your platform, however not all versions of keyring actually work. Specifically we have global-requirements of >=2.1,!=3.3, so we know those are the only versions we believe work. If you are on an older platform, using system installed python-keyring, python-keystoneclient won't install a new version, because it's optional, but then will use a terriblely old verison, which explodes with dbus errors. The fix is to be more explicit on import. Change-Id: I040f7b2311d7d5a450b8b12642752ac519b206fa Closes-Bug: #1242992 --- keystoneclient/httpclient.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/keystoneclient/httpclient.py b/keystoneclient/httpclient.py index 866e49303..48e12b7cf 100644 --- a/keystoneclient/httpclient.py +++ b/keystoneclient/httpclient.py @@ -20,14 +20,26 @@ OpenStack Client interface. Handles the REST calls and responses. """ import logging +import pkg_resources from six.moves.urllib import parse as urlparse try: import pickle - import keyring -except ImportError: + # NOTE(sdague): The conditional keyring import needs to only + # trigger if it's a version of keyring that's supported in global + # requirements. Update _min and _bad when that changes. + keyring_v = pkg_resources.parse_version( + pkg_resources.get_distribution("keyring").version) + keyring_min = pkg_resources.parse_version('2.1') + keyring_bad = (pkg_resources.parse_version('3.3'),) + + if keyring_v >= keyring_min and keyring_v not in keyring_bad: + import keyring + else: + keyring = None +except (ImportError, pkg_resources.DistributionNotFound): keyring = None pickle = None