Fix functest for IPv6 endpoints
Currently the functional tests fail if the storage_url contains a quoted IPv6 address because we try to split on ':'. But actually we don't need to split hostname and port only in order to combine it back together lateron. Use the standard urlparse() function instead and work with the 'netloc' part of the URL which keeps hostname and port together. Change-Id: I64589e5f2d6fb3cebc6768dc9e4de6264c09cbeb Partial-Bug: 1656329
This commit is contained in:
parent
ff23dcdf3a
commit
b4f08b6090
@ -122,8 +122,7 @@ class Connection(object):
|
||||
self.username = config['username']
|
||||
self.password = config['password']
|
||||
|
||||
self.storage_host = None
|
||||
self.storage_port = None
|
||||
self.storage_netloc = None
|
||||
self.storage_url = None
|
||||
|
||||
self.conn_class = None
|
||||
@ -134,9 +133,8 @@ class Connection(object):
|
||||
def authenticate(self, clone_conn=None):
|
||||
if clone_conn:
|
||||
self.conn_class = clone_conn.conn_class
|
||||
self.storage_host = clone_conn.storage_host
|
||||
self.storage_netloc = clone_conn.storage_netloc
|
||||
self.storage_url = clone_conn.storage_url
|
||||
self.storage_port = clone_conn.storage_port
|
||||
self.storage_token = clone_conn.storage_token
|
||||
return
|
||||
|
||||
@ -162,26 +160,23 @@ class Connection(object):
|
||||
if not (storage_url and storage_token):
|
||||
raise AuthenticationFailed()
|
||||
|
||||
x = storage_url.split('/')
|
||||
url = urllib.parse.urlparse(storage_url)
|
||||
|
||||
if x[0] == 'http:':
|
||||
if url.scheme == 'http':
|
||||
self.conn_class = http_client.HTTPConnection
|
||||
self.storage_port = 80
|
||||
elif x[0] == 'https:':
|
||||
elif url.scheme == 'https':
|
||||
self.conn_class = http_client.HTTPSConnection
|
||||
self.storage_port = 443
|
||||
else:
|
||||
raise ValueError('unexpected protocol %s' % (x[0]))
|
||||
raise ValueError('unexpected protocol %s' % (url.scheme))
|
||||
|
||||
self.storage_host = x[2].split(':')[0]
|
||||
if ':' in x[2]:
|
||||
self.storage_port = int(x[2].split(':')[1])
|
||||
self.storage_netloc = url.netloc
|
||||
# Make sure storage_url is a string and not unicode, since
|
||||
# keystoneclient (called by swiftclient) returns them in
|
||||
# unicode and this would cause troubles when doing
|
||||
# no_safe_quote query.
|
||||
self.storage_url = str('/%s/%s' % (x[3], x[4]))
|
||||
self.account_name = str(x[4])
|
||||
x = url.path.split('/')
|
||||
self.storage_url = str('/%s/%s' % (x[1], x[2]))
|
||||
self.account_name = str(x[2])
|
||||
self.auth_user = auth_user
|
||||
# With v2 keystone, storage_token is unicode.
|
||||
# We want it to be string otherwise this would cause
|
||||
@ -206,8 +201,7 @@ class Connection(object):
|
||||
return json.loads(self.response.read())
|
||||
|
||||
def http_connect(self):
|
||||
self.connection = self.conn_class(self.storage_host,
|
||||
port=self.storage_port)
|
||||
self.connection = self.conn_class(self.storage_netloc)
|
||||
# self.connection.set_debuglevel(3)
|
||||
|
||||
def make_path(self, path=None, cfg=None):
|
||||
@ -335,8 +329,7 @@ class Connection(object):
|
||||
for (x, y) in parms.items()]
|
||||
path = '%s?%s' % (path, '&'.join(query_args))
|
||||
|
||||
self.connection = self.conn_class(self.storage_host,
|
||||
port=self.storage_port)
|
||||
self.connection = self.conn_class(self.storage_netloc)
|
||||
# self.connection.set_debuglevel(3)
|
||||
self.connection.putrequest('PUT', path)
|
||||
for key, value in headers.items():
|
||||
|
Loading…
x
Reference in New Issue
Block a user