Make OS_AUTH_URL work in DevStack by default

An earlier change added support for versionless authurls, but the
huristic to detect them didn't work for some configurations I've
encountered.

Now we use a little bit tighter pattern matching and support auth_url
values with more than one path component.

Change-Id: I5a99c7b4e957ee7c8a5b5470477db49ab2ddba4b
Related-Change-Id: If7ecb67776cb77828f93ad8278cc5040015216b7
This commit is contained in:
Clay Gerrard 2017-06-13 11:14:52 -07:00 committed by Luigi Toscano
parent 2312182241
commit 1190825054
2 changed files with 53 additions and 1 deletions

View File

@ -17,6 +17,7 @@
OpenStack Swift client library used internally OpenStack Swift client library used internally
""" """
import socket import socket
import re
import requests import requests
import logging import logging
import warnings import warnings
@ -38,6 +39,7 @@ from swiftclient.utils import (
# Default is 100, increase to 256 # Default is 100, increase to 256
http_client._MAXHEADERS = 256 http_client._MAXHEADERS = 256
VERSIONFUL_AUTH_PATH = re.compile('v[2-3](?:\.0)?$')
AUTH_VERSIONS_V1 = ('1.0', '1', 1) AUTH_VERSIONS_V1 = ('1.0', '1', 1)
AUTH_VERSIONS_V2 = ('2.0', '2', 2) AUTH_VERSIONS_V2 = ('2.0', '2', 2)
AUTH_VERSIONS_V3 = ('3.0', '3', 3) AUTH_VERSIONS_V3 = ('3.0', '3', 3)
@ -555,7 +557,10 @@ def get_auth_keystone(auth_url, user, key, os_options, **kwargs):
# Add the version suffix in case of versionless Keystone endpoints. If # Add the version suffix in case of versionless Keystone endpoints. If
# auth_version is also unset it is likely that it is v3 # auth_version is also unset it is likely that it is v3
if len(urlparse(auth_url).path) <= 1: if not VERSIONFUL_AUTH_PATH.match(
urlparse(auth_url).path.rstrip('/').rsplit('/', 1)[-1]):
# Normalize auth_url to end in a slash because urljoin
auth_url = auth_url.rstrip('/') + '/'
if auth_version and auth_version in AUTH_VERSIONS_V2: if auth_version and auth_version in AUTH_VERSIONS_V2:
auth_url = urljoin(auth_url, "v2.0") auth_url = urljoin(auth_url, "v2.0")
else: else:

View File

@ -597,6 +597,53 @@ class TestGetAuth(MockHttpTest):
self.assertEqual('http://auth_url/v2.0', self.assertEqual('http://auth_url/v2.0',
fake_ks.calls[0].get('auth_url')) fake_ks.calls[0].get('auth_url'))
def test_get_auth_keystone_versionful(self):
fake_ks = FakeKeystone(endpoint='http://some_url', token='secret')
with mock.patch('swiftclient.client._import_keystone_client',
_make_fake_import_keystone_client(fake_ks)):
c.get_auth_keystone('http://auth_url/v3', 'user', 'key',
{}, auth_version='3')
self.assertEqual(1, len(fake_ks.calls))
self.assertEqual('http://auth_url/v3',
fake_ks.calls[0].get('auth_url'))
def test_get_auth_keystone_devstack_versionful(self):
fake_ks = FakeKeystone(
endpoint='http://storage.example.com/v1/AUTH_user', token='secret')
with mock.patch('swiftclient.client._import_keystone_client',
_make_fake_import_keystone_client(fake_ks)):
c.get_auth_keystone('https://192.168.8.8/identity/v3',
'user', 'key', {}, auth_version='3')
self.assertEqual(1, len(fake_ks.calls))
self.assertEqual('https://192.168.8.8/identity/v3',
fake_ks.calls[0].get('auth_url'))
def test_get_auth_keystone_devstack_versionless(self):
fake_ks = FakeKeystone(
endpoint='http://storage.example.com/v1/AUTH_user', token='secret')
with mock.patch('swiftclient.client._import_keystone_client',
_make_fake_import_keystone_client(fake_ks)):
c.get_auth_keystone('https://192.168.8.8/identity',
'user', 'key', {}, auth_version='3')
self.assertEqual(1, len(fake_ks.calls))
self.assertEqual('https://192.168.8.8/identity/v3',
fake_ks.calls[0].get('auth_url'))
def test_auth_keystone_url_some_junk_nonsense(self):
fake_ks = FakeKeystone(
endpoint='http://storage.example.com/v1/AUTH_user',
token='secret')
with mock.patch('swiftclient.client._import_keystone_client',
_make_fake_import_keystone_client(fake_ks)):
c.get_auth_keystone('http://blah.example.com/v2moo',
'user', 'key', {}, auth_version='3')
self.assertEqual(1, len(fake_ks.calls))
# v2 looks sorta version-y, but it's not an exact match, so this is
# probably about just as bad as anything else we might guess at
self.assertEqual('http://blah.example.com/v2moo/v3',
fake_ks.calls[0].get('auth_url'))
def test_auth_with_session(self): def test_auth_with_session(self):
mock_session = mock.MagicMock() mock_session = mock.MagicMock()
mock_session.get_endpoint.return_value = 'http://storagehost/v1/acct' mock_session.get_endpoint.return_value = 'http://storagehost/v1/acct'