Allow storage url override for both auth vers.
When --os-storage-url is specified on the command-line to bin/swift, it will override the used storage URL regardless of authentication for both authentication version 1 and version 2. This can be used to bypass a load-balancer to hit a specific proxy server for testing/debugging purposes. Within the client library, this feature is accessed by passing the desired storage URL into swiftclient.client.Conection.__init__() via the os_options keyword argument. For example: conn = Connection(auth_url, user, key, os_options={ 'object_storage_url': 'http://overridden.storage.url/AUTH_foo'}) This patch also adds a dependency on mock>=0.8.0, which is the same as openstack/swift. Change-Id: Id2a36ed6abffd65e7762b6beea5bbfc6c036e848
This commit is contained in:
parent
6f7458a290
commit
1d4d51b218
@ -1277,10 +1277,10 @@ Commands:
|
||||
%(st_delete_help)s
|
||||
|
||||
Examples:
|
||||
%%prog -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat
|
||||
%%prog -A https://auth.api.rackspacecloud.com/v1.0 -U user -K key stat -v
|
||||
|
||||
%%prog --os-auth-url https://api.example.com/v2.0 --os-tenant-name tenant \\
|
||||
--os-usernameuser --os-password password list
|
||||
--os-username user --os-password password list
|
||||
|
||||
%%prog --os-auth-token 6ee5eb33efad4e45ab46806eac010566 \\
|
||||
--os-storage-url https://10.1.5.2:8080/v1/AUTH_ced809b6a4baea7aeab61a \\
|
||||
@ -1357,8 +1357,9 @@ Examples:
|
||||
default=environ.get('OS_STORAGE_URL'),
|
||||
help='Openstack storage URL. '
|
||||
'Defaults to env[OS_STORAGE_URL]. '
|
||||
'Used with --os-auth-token to bypass the '
|
||||
'usual username/password authentication.')
|
||||
'Overrides the storage url returned during auth. '
|
||||
'Will bypass authentication when used with '
|
||||
'--os-auth-token.')
|
||||
parser.add_option('--os_storage_url',
|
||||
help=SUPPRESS_HELP)
|
||||
parser.add_option('--os-region-name',
|
||||
|
@ -105,6 +105,7 @@ will be deleted as well, unless you specify the --leave-segments option.
|
||||
.IP "-U USER, --user=USER User name for obtaining an auth token"
|
||||
.IP "-V 1|2 Authentication protocol version"
|
||||
.IP "-K KEY, --key=KEY Key for obtaining an auth token"
|
||||
.IP "--os-storage-url=URL Use this instead of URL returned from auth"
|
||||
|
||||
.PD
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
SwiftClient Web
|
||||
***************
|
||||
|
||||
Copyright 2012 OpenStack, LLC.
|
||||
Copyright 2013 OpenStack, LLC.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -290,20 +290,19 @@ def get_auth(auth_url, user, key, **kwargs):
|
||||
auth_version = kwargs.get('auth_version', '1')
|
||||
os_options = kwargs.get('os_options', {})
|
||||
|
||||
storage_url, token = None, None
|
||||
if auth_version in ['1.0', '1', 1]:
|
||||
return get_auth_1_0(auth_url,
|
||||
user,
|
||||
key,
|
||||
kwargs.get('snet'))
|
||||
|
||||
if auth_version in ['2.0', '2', 2]:
|
||||
|
||||
storage_url, token = get_auth_1_0(auth_url,
|
||||
user,
|
||||
key,
|
||||
kwargs.get('snet'))
|
||||
elif auth_version in ['2.0', '2', 2]:
|
||||
# We are allowing to specify a token/storage-url to re-use
|
||||
# without having to re-authenticate.
|
||||
if (os_options.get('object_storage_url') and
|
||||
os_options.get('auth_token')):
|
||||
return(os_options.get('object_storage_url'),
|
||||
os_options.get('auth_token'))
|
||||
return (os_options.get('object_storage_url'),
|
||||
os_options.get('auth_token'))
|
||||
|
||||
# We are handling a special use case here when we were
|
||||
# allowing specifying the account/tenant_name with the -U
|
||||
@ -322,14 +321,19 @@ def get_auth(auth_url, user, key, **kwargs):
|
||||
|
||||
insecure = kwargs.get('insecure', False)
|
||||
cacert = kwargs.get('cacert', None)
|
||||
(auth_url, token) = get_keystoneclient_2_0(auth_url, user,
|
||||
key, os_options,
|
||||
cacert=cacert,
|
||||
insecure=insecure)
|
||||
return (auth_url, token)
|
||||
storage_url, token = get_keystoneclient_2_0(auth_url, user,
|
||||
key, os_options,
|
||||
cacert=cacert,
|
||||
insecure=insecure)
|
||||
else:
|
||||
raise ClientException('Unknown auth_version %s specified.'
|
||||
% auth_version)
|
||||
|
||||
raise ClientException('Unknown auth_version %s specified.'
|
||||
% auth_version)
|
||||
# Override storage url, if necessary
|
||||
if os_options.get('object_storage_url'):
|
||||
return os_options['object_storage_url'], token
|
||||
else:
|
||||
return storage_url, token
|
||||
|
||||
|
||||
def store_response(resp, response_dict):
|
||||
@ -1086,9 +1090,7 @@ class Connection(object):
|
||||
self.ssl_compression = ssl_compression
|
||||
|
||||
def get_auth(self):
|
||||
return get_auth(self.authurl,
|
||||
self.user,
|
||||
self.key,
|
||||
return get_auth(self.authurl, self.user, self.key,
|
||||
snet=self.snet,
|
||||
auth_version=self.auth_version,
|
||||
os_options=self.os_options,
|
||||
|
@ -5,6 +5,7 @@ flake8==2.0
|
||||
|
||||
coverage
|
||||
discover
|
||||
mock>=0.8.0
|
||||
python-keystoneclient
|
||||
sphinx>=1.1.2
|
||||
testrepository>=0.0.13
|
||||
|
@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
# TODO: More tests
|
||||
import mock
|
||||
import httplib
|
||||
import socket
|
||||
import StringIO
|
||||
@ -123,8 +124,12 @@ class MockHttpTest(testtools.TestCase):
|
||||
_orig_http_connection = c.http_connection
|
||||
return_read = kwargs.get('return_read')
|
||||
query_string = kwargs.get('query_string')
|
||||
storage_url = kwargs.get('storage_url')
|
||||
|
||||
def wrapper(url, proxy=None, ssl_compression=True):
|
||||
if storage_url:
|
||||
self.assertEqual(storage_url, url)
|
||||
|
||||
parsed, _conn = _orig_http_connection(url, proxy=proxy)
|
||||
conn = fake_http_connect(*args, **kwargs)()
|
||||
|
||||
@ -649,6 +654,33 @@ class TestConnection(MockHttpTest):
|
||||
conn = c.Connection(**args)
|
||||
self.assertEquals(type(conn), c.Connection)
|
||||
|
||||
def test_storage_url_override(self):
|
||||
static_url = 'http://overridden.storage.url'
|
||||
c.http_connection = self.fake_http_connection(
|
||||
200, body='[]', storage_url=static_url)
|
||||
conn = c.Connection('http://auth.url/', 'some_user', 'some_key',
|
||||
os_options={
|
||||
'object_storage_url': static_url})
|
||||
method_signatures = (
|
||||
(conn.head_account, []),
|
||||
(conn.get_account, []),
|
||||
(conn.head_container, ('asdf',)),
|
||||
(conn.get_container, ('asdf',)),
|
||||
(conn.put_container, ('asdf',)),
|
||||
(conn.delete_container, ('asdf',)),
|
||||
(conn.head_object, ('asdf', 'asdf')),
|
||||
(conn.get_object, ('asdf', 'asdf')),
|
||||
(conn.put_object, ('asdf', 'asdf', 'asdf')),
|
||||
(conn.post_object, ('asdf', 'asdf', {})),
|
||||
(conn.delete_object, ('asdf', 'asdf')),
|
||||
)
|
||||
|
||||
with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth:
|
||||
mock_get_auth.return_value = ('http://auth.storage.url', 'tToken')
|
||||
|
||||
for method, args in method_signatures:
|
||||
method(*args)
|
||||
|
||||
def test_retry(self):
|
||||
c.http_connection = self.fake_http_connection(500)
|
||||
|
||||
|
@ -38,7 +38,7 @@ def fake_get_keystoneclient_2_0(os_options, exc=None, **kwargs):
|
||||
from swiftclient import client as c
|
||||
raise c.ClientException("unverified-certificate")
|
||||
|
||||
return ("http://url/", "token")
|
||||
return "http://url/", "token"
|
||||
return fake_get_keystoneclient_2_0
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user