Merge "Allow storage url override for both auth vers."

This commit is contained in:
Jenkins 2013-07-10 07:06:08 +00:00 committed by Gerrit Code Review
commit c460ebff0a
7 changed files with 62 additions and 25 deletions

View File

@ -1278,10 +1278,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 \\
@ -1358,8 +1358,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',

View File

@ -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

View File

@ -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.

View File

@ -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,

View File

@ -5,6 +5,7 @@ flake8==2.0
coverage
discover
mock>=0.8.0
python-keystoneclient
sphinx>=1.1.2
testrepository>=0.0.13

View File

@ -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)

View File

@ -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