Merge "Unify auth_host/port/ssl/prefix func test options into auth_uri"

This commit is contained in:
Zuul 2019-05-05 00:04:08 +00:00 committed by Gerrit Code Review
commit 506d0fa821
3 changed files with 36 additions and 40 deletions

View File

@ -16,7 +16,7 @@
from __future__ import print_function from __future__ import print_function
import mock import mock
import os import os
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse, urlsplit, urlunsplit
import sys import sys
import pickle import pickle
import socket import socket
@ -574,10 +574,7 @@ def in_process_setup(the_object_server=object_server):
"Content-Language, Expires, X-Robots-Tag", "Content-Language, Expires, X-Robots-Tag",
# Below are values used by the functional test framework, as well as # Below are values used by the functional test framework, as well as
# by the various in-process swift servers # by the various in-process swift servers
'auth_host': '127.0.0.1', 'auth_uri': 'http://127.0.0.1:%d/auth/v1.0' % prolis.getsockname()[1],
'auth_port': str(prolis.getsockname()[1]),
'auth_ssl': 'no',
'auth_prefix': '/auth/',
# Primary functional test account (needs admin access to the # Primary functional test account (needs admin access to the
# account) # account)
'account': 'test', 'account': 'test',
@ -844,23 +841,39 @@ def setup_package():
if config: if config:
swift_test_auth_version = str(config.get('auth_version', '1')) swift_test_auth_version = str(config.get('auth_version', '1'))
swift_test_auth = 'http' if 'auth_uri' in config:
swift_test_auth = config['auth_uri']
# Back-fill the individual parts -- really, we should just need
# host and port for s3_test_client, and that's only until we
# improve it to take a s3_storage_url option
parsed = urlsplit(config['auth_uri'])
config.update({
'auth_ssl': parsed.scheme == 'https',
'auth_host': parsed.hostname,
'auth_port': (parsed.port if parsed.port is not None else
443 if parsed.scheme == 'https' else 80),
'auth_prefix': parsed.path,
})
elif 'auth_host' in config:
scheme = 'http'
if config_true_value(config.get('auth_ssl', 'no')): if config_true_value(config.get('auth_ssl', 'no')):
swift_test_auth = 'https' scheme = 'https'
if 'auth_prefix' not in config: netloc = config['auth_host']
config['auth_prefix'] = '/' if 'auth_port' in config:
try: netloc += ':' + config['auth_port']
suffix = '://%(auth_host)s:%(auth_port)s%(auth_prefix)s' % config auth_prefix = config.get('auth_prefix', '/')
swift_test_auth += suffix if swift_test_auth_version == "1":
except KeyError: auth_prefix += 'v1.0'
pass # skip config['auth_uri'] = swift_test_auth = urlunsplit(
(scheme, netloc, auth_prefix, None, None))
# else, neither auth_uri nor auth_host; swift_test_auth will be unset
# and we'll skip everything later
if 'service_prefix' in config: if 'service_prefix' in config:
swift_test_service_prefix = utils.append_underscore( swift_test_service_prefix = utils.append_underscore(
config['service_prefix']) config['service_prefix'])
if swift_test_auth_version == "1": if swift_test_auth_version == "1":
swift_test_auth += 'v1.0'
try: try:
if 'account' in config: if 'account' in config:

View File

@ -198,16 +198,13 @@ def putrequest(self, method, url, skip_host=False, skip_accept_encoding=False):
class Connection(object): class Connection(object):
def __init__(self, config): def __init__(self, config):
for key in 'auth_host auth_port auth_ssl username password'.split(): for key in 'auth_uri username password'.split():
if key not in config: if key not in config:
raise SkipTest( raise SkipTest(
"Missing required configuration parameter: %s" % key) "Missing required configuration parameter: %s" % key)
self.auth_host = config['auth_host'] self.auth_url = config['auth_uri']
self.auth_port = int(config['auth_port'])
self.auth_ssl = config['auth_ssl'] in ('on', 'true', 'yes', '1')
self.insecure = config_true_value(config.get('insecure', 'false')) self.insecure = config_true_value(config.get('insecure', 'false'))
self.auth_prefix = config.get('auth_prefix', '/')
self.auth_version = str(config.get('auth_version', '1')) self.auth_version = str(config.get('auth_version', '1'))
self.account = config.get('account') self.account = config.get('account')
@ -256,18 +253,10 @@ class Connection(object):
return Account(self, self.account) return Account(self, self.account)
def authenticate(self): def authenticate(self):
if self.auth_version == "1": if self.auth_version == "1" and self.account:
auth_path = '%sv1.0' % (self.auth_prefix)
if self.account:
auth_user = '%s:%s' % (self.account, self.username) auth_user = '%s:%s' % (self.account, self.username)
else: else:
auth_user = self.username auth_user = self.username
else:
auth_user = self.username
auth_path = self.auth_prefix
auth_scheme = 'https://' if self.auth_ssl else 'http://'
auth_netloc = "%s:%d" % (self.auth_host, self.auth_port)
auth_url = auth_scheme + auth_netloc + auth_path
if self.insecure: if self.insecure:
try: try:
@ -283,7 +272,7 @@ class Connection(object):
auth_version=self.auth_version, os_options={}, auth_version=self.auth_version, os_options={},
insecure=self.insecure) insecure=self.insecure)
(storage_url, storage_token) = get_auth( (storage_url, storage_token) = get_auth(
auth_url, auth_user, self.password, **authargs) self.auth_url, auth_user, self.password, **authargs)
if not (storage_url and storage_token): if not (storage_url and storage_token):
raise AuthenticationFailed() raise AuthenticationFailed()

View File

@ -1,17 +1,11 @@
[func_test] [func_test]
# Sample config for Swift with tempauth # Sample config for Swift with tempauth
auth_host = 127.0.0.1 auth_uri = http://127.0.0.1:8080/auth/v1.0
auth_port = 8080
auth_ssl = no
auth_prefix = /auth/
# Sample config for Swift with Keystone v2 API. # Sample config for Swift with Keystone v2 API.
# For keystone v2 change auth_version to 2 and auth_prefix to /v2.0/. # For keystone v2 change auth_version to 2 and auth_prefix to /v2.0/.
# And "allow_account_management" should not be set "true". # And "allow_account_management" should not be set "true".
#auth_version = 3 #auth_version = 3
#auth_host = localhost #auth_uri = http://localhost:5000/v3/
#auth_port = 5000
#auth_ssl = no
#auth_prefix = /v3/
# Primary functional test account (needs admin access to the account) # Primary functional test account (needs admin access to the account)
account = test account = test