summaryrefslogtreecommitdiff
path: root/swiftclient/client.py
diff options
context:
space:
mode:
authorAlistair Coles <alistair.coles@hp.com>2014-09-22 11:52:44 +0100
committerAlistair Coles <alistair.coles@hp.com>2014-09-24 18:19:12 +0100
commitf90d7f28e504be045e59b395aee0abc057417f8f (patch)
tree0c6e81ec791dcc5e9f80070717fcfbe78854c449 /swiftclient/client.py
parent8f1b394325804c23ac18e7f9da6cb56a3b95eed2 (diff)
downloadpython-swiftclient-f90d7f28e504be045e59b395aee0abc057417f8f.tar.gz
Fix bug with some OS options not being passed to client
Fixes a regression that is preventing swiftclient from authenticating using keystone v3 options. swiftclient/shell.py processes the dict of command line options to set up a child dict ('os_options') of keystone auth specific options (line 960). The processing includes stripping --os- prefixes from the command line options before adding keys to os_options. A recent patch https://review.openstack.org/#/c/85453/ introduced a duplication of this option processing in service.py (line 79) which replaces the os_options created in shell.py, but omits keystone v3 related options. Consequently the keystone v3 options are not being passed to the client get_auth() method. This patch adds the keystone v3 related options to the option processing in service.py. For pragmatic reasons (i.e. fixing the bug quickly) the option processing code has not been removed from parse_args in shell.py. It is likely that the code in parse_args is now redundant, but all code paths between parse_args and process_options should be inspected and test coverage added before removing that code. Unit tests have been added in test_shell.py to verify that command line options are correctly passed to the client get_auth method. The MockHttpTest class is re-used in test_shell.py, so it is moved from test_swiftclient.py to tests/unit/utils.py Closes-bug: #1372465 Change-Id: I4fed013cdb8936509609d06093337cc147ade0d6
Diffstat (limited to 'swiftclient/client.py')
-rw-r--r--swiftclient/client.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index 7ce7218..3bc9c75 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -285,29 +285,36 @@ def get_keystoneclient_2_0(auth_url, user, key, os_options, **kwargs):
return get_auth_keystone(auth_url, user, key, os_options, **kwargs)
-def get_auth_keystone(auth_url, user, key, os_options, **kwargs):
- """
- Authenticate against a keystone server.
-
- We are using the keystoneclient library for authentication.
- """
-
- insecure = kwargs.get('insecure', False)
- auth_version = kwargs.get('auth_version', '2.0')
- debug = logger.isEnabledFor(logging.DEBUG) and True or False
-
+def _import_keystone_client(auth_version):
+ # the attempted imports are encapsulated in this function to allow
+ # mocking for tests
try:
if auth_version in AUTH_VERSIONS_V3:
from keystoneclient.v3 import client as ksclient
else:
from keystoneclient.v2_0 import client as ksclient
from keystoneclient import exceptions
+ return ksclient, exceptions
except ImportError:
sys.exit('''
Auth versions 2.0 and 3 require python-keystoneclient, install it or use Auth
version 1.0 which requires ST_AUTH, ST_USER, and ST_KEY environment
variables to be set or overridden with -A, -U, or -K.''')
+
+def get_auth_keystone(auth_url, user, key, os_options, **kwargs):
+ """
+ Authenticate against a keystone server.
+
+ We are using the keystoneclient library for authentication.
+ """
+
+ insecure = kwargs.get('insecure', False)
+ auth_version = kwargs.get('auth_version', '2.0')
+ debug = logger.isEnabledFor(logging.DEBUG) and True or False
+
+ ksclient, exceptions = _import_keystone_client(auth_version)
+
try:
_ksclient = ksclient.Client(
username=user,