Fix retrieve auth_url and python 3 jobs
This commit is fixing problems with auth url retrieving when it have path inside. In order to merge this change also repaired python 3 jobs. Closes-bug: 1587755 Change-Id: I642e94854209d740f59a39257bd0153194b37a84
This commit is contained in:
parent
7116a3ec34
commit
2460408f44
@ -33,24 +33,14 @@ def retrieve_auth_url(endpoint_type="publicURL"):
|
||||
|
||||
Hadoop Swift library doesn't support keystone v3 api.
|
||||
"""
|
||||
auth_url = clients_base.retrieve_auth_url(endpoint_type=endpoint_type)
|
||||
info = urlparse.urlparse(auth_url)
|
||||
|
||||
if CONF.use_domain_for_proxy_users:
|
||||
url = 'v3/auth'
|
||||
version_suffix = 'v3/auth'
|
||||
else:
|
||||
url = 'v2.0'
|
||||
version_suffix = 'v2.0'
|
||||
|
||||
if info.port:
|
||||
returned_url = '{scheme}://{hostname}:{port}/{url}/'
|
||||
return returned_url.format(scheme=info.scheme,
|
||||
hostname=info.hostname,
|
||||
port=info.port,
|
||||
url=url)
|
||||
else:
|
||||
return '{scheme}://{hostname}/{url}/'.format(scheme=info.scheme,
|
||||
hostname=info.hostname,
|
||||
url=url)
|
||||
# return auth url with trailing slash
|
||||
return clients_base.retrieve_auth_url(
|
||||
endpoint_type=endpoint_type, version=version_suffix) + "/"
|
||||
|
||||
|
||||
def inject_swift_url_suffix(url):
|
||||
|
@ -24,8 +24,9 @@ class SwiftUtilsTest(testbase.SaharaTestCase):
|
||||
def setUp(self):
|
||||
super(SwiftUtilsTest, self).setUp()
|
||||
self.override_config('use_identity_api_v3', True)
|
||||
self.setup_context(service_catalog=True)
|
||||
|
||||
@mock.patch('sahara.utils.openstack.base.retrieve_auth_url')
|
||||
@mock.patch('sahara.utils.openstack.base.url_for')
|
||||
def test_retrieve_auth_url(self, url_for_mock):
|
||||
correct = "https://127.0.0.1:8080/v2.0/"
|
||||
|
||||
@ -38,10 +39,19 @@ class SwiftUtilsTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1:8080/")
|
||||
_assert("https://127.0.0.1:8080/v2.0")
|
||||
_assert("https://127.0.0.1:8080/v2.0/")
|
||||
_assert("https://127.0.0.1:8080/v42/")
|
||||
_assert("https://127.0.0.1:8080/foo")
|
||||
|
||||
@mock.patch('sahara.utils.openstack.base.retrieve_auth_url')
|
||||
@mock.patch('sahara.utils.openstack.base.url_for')
|
||||
def test_retrieve_auth_url_path_present(self, url_for_mock):
|
||||
correct = "https://127.0.0.1:8080/identity/v2.0/"
|
||||
|
||||
def _assert(uri):
|
||||
url_for_mock.return_value = uri
|
||||
self.assertEqual(correct, utils.retrieve_auth_url())
|
||||
|
||||
_assert("https://127.0.0.1:8080/identity")
|
||||
_assert("https://127.0.0.1:8080/identity/v2.0/")
|
||||
|
||||
@mock.patch('sahara.utils.openstack.base.url_for')
|
||||
def test_retrieve_auth_url_without_port(self, url_for_mock):
|
||||
correct = "https://127.0.0.1/v2.0/"
|
||||
|
||||
@ -54,5 +64,19 @@ class SwiftUtilsTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1/")
|
||||
_assert("https://127.0.0.1/v2.0")
|
||||
_assert("https://127.0.0.1/v2.0/")
|
||||
_assert("https://127.0.0.1/v42/")
|
||||
_assert("https://127.0.0.1/foo")
|
||||
|
||||
@mock.patch('sahara.utils.openstack.base.url_for')
|
||||
def test_retrieve_auth_url_v3(self, url_for_mock):
|
||||
self.override_config('use_domain_for_proxy_users', True)
|
||||
correct = "https://127.0.0.1/v3/auth/"
|
||||
|
||||
def _assert(uri):
|
||||
url_for_mock.return_value = uri
|
||||
self.assertEqual(correct, utils.retrieve_auth_url())
|
||||
|
||||
_assert("%s/" % correct)
|
||||
_assert("https://127.0.0.1/v3")
|
||||
_assert("https://127.0.0.1")
|
||||
_assert("https://127.0.0.1/")
|
||||
_assert("https://127.0.0.1/v2.0")
|
||||
_assert("https://127.0.0.1/v2.0/")
|
||||
|
@ -18,47 +18,28 @@ import mock
|
||||
from sahara import context
|
||||
from sahara.tests.unit import base
|
||||
from sahara.utils.notification import sender
|
||||
from sahara.utils import rpc as messaging
|
||||
|
||||
|
||||
class NotificationTest(base.SaharaTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NotificationTest, self).setUp()
|
||||
|
||||
def _make_sample(self):
|
||||
ctx = context.ctx()
|
||||
|
||||
self.ctx = ctx
|
||||
self.cluster_id = 'someId'
|
||||
self.cluster_name = 'someName'
|
||||
self.cluster_status = 'someStatus'
|
||||
|
||||
sender.status_notify(self.cluster_id, self.cluster_name,
|
||||
self.cluster_status, "update")
|
||||
|
||||
self.create_mock('update')
|
||||
|
||||
def create_mock(self, action):
|
||||
|
||||
self.expected = mock.call(self.ctx,
|
||||
'sahara.cluster.%s' % action,
|
||||
{'cluster_id': self.cluster_id,
|
||||
'cluster_name': self.cluster_name,
|
||||
'cluster_status': self.cluster_status,
|
||||
'project_id': self.ctx.tenant_id,
|
||||
'user_id': self.ctx.user_id})
|
||||
|
||||
@mock.patch('oslo_messaging.notify.notifier.Notifier.info')
|
||||
@mock.patch('sahara.utils.rpc.get_notifier')
|
||||
def test_update_cluster(self, mock_notify):
|
||||
class FakeNotifier(object):
|
||||
def info(self, *args):
|
||||
self.call = args
|
||||
|
||||
self.override_config("enable", True,
|
||||
group='oslo_messaging_notifications')
|
||||
messaging.setup()
|
||||
notifier = FakeNotifier()
|
||||
mock_notify.return_value = notifier
|
||||
ctx = context.ctx()
|
||||
sender.status_notify('someId', 'someName', 'someStatus', "update")
|
||||
self.expected_args = (ctx,
|
||||
'sahara.cluster.%s' % 'update',
|
||||
{'cluster_id': 'someId',
|
||||
'cluster_name': 'someName',
|
||||
'cluster_status': 'someStatus',
|
||||
'project_id': ctx.tenant_id,
|
||||
'user_id': ctx.user_id})
|
||||
|
||||
self._make_sample()
|
||||
self.assertEqual([self.expected],
|
||||
mock_notify.call_args_list)
|
||||
|
||||
if messaging.TRANSPORT:
|
||||
messaging.TRANSPORT.cleanup()
|
||||
messaging.TRANSPORT = messaging.NOTIFIER = None
|
||||
self.assertEqual(self.expected_args,
|
||||
notifier.call)
|
||||
|
@ -71,8 +71,6 @@ class AuthUrlTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1:8080/v2.0/")
|
||||
_assert("https://127.0.0.1:8080/v3")
|
||||
_assert("https://127.0.0.1:8080/v3/")
|
||||
_assert("https://127.0.0.1:8080/v42")
|
||||
_assert("https://127.0.0.1:8080/v42/")
|
||||
|
||||
@mock.patch("sahara.utils.openstack.base.url_for")
|
||||
def test_retrieve_auth_url_api_v3_without_port(self, mock_url_for):
|
||||
@ -91,8 +89,21 @@ class AuthUrlTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1/v2.0/")
|
||||
_assert("https://127.0.0.1/v3")
|
||||
_assert("https://127.0.0.1/v3/")
|
||||
_assert("https://127.0.0.1/v42")
|
||||
_assert("https://127.0.0.1/v42/")
|
||||
|
||||
@mock.patch("sahara.utils.openstack.base.url_for")
|
||||
def test_retrieve_auth_url_api_v3_path_present(self, mock_url_for):
|
||||
self.override_config('use_identity_api_v3', True)
|
||||
self.setup_context(service_catalog=True)
|
||||
correct = "https://127.0.0.1/identity/v3"
|
||||
|
||||
def _assert(uri):
|
||||
mock_url_for.return_value = uri
|
||||
self.assertEqual(correct, base.retrieve_auth_url())
|
||||
|
||||
_assert("%s" % correct)
|
||||
_assert("%s/" % correct)
|
||||
_assert("https://127.0.0.1/identity")
|
||||
_assert("https://127.0.0.1/identity/")
|
||||
|
||||
def test_retrieve_auth_url_api_v20(self):
|
||||
self.override_config('use_identity_api_v3', False)
|
||||
@ -109,8 +120,6 @@ class AuthUrlTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1:8080/v2.0/")
|
||||
_assert("https://127.0.0.1:8080/v3")
|
||||
_assert("https://127.0.0.1:8080/v3/")
|
||||
_assert("https://127.0.0.1:8080/v42")
|
||||
_assert("https://127.0.0.1:8080/v42/")
|
||||
|
||||
@mock.patch("sahara.utils.openstack.base.url_for")
|
||||
def test_retrieve_auth_url_api_v20_without_port(self, mock_url_for):
|
||||
@ -129,8 +138,6 @@ class AuthUrlTest(testbase.SaharaTestCase):
|
||||
_assert("https://127.0.0.1/v2.0/")
|
||||
_assert("https://127.0.0.1/v3")
|
||||
_assert("https://127.0.0.1/v3/")
|
||||
_assert("https://127.0.0.1/v42")
|
||||
_assert("https://127.0.0.1/v42/")
|
||||
|
||||
|
||||
class ExecuteWithRetryTest(testbase.SaharaTestCase):
|
||||
|
@ -27,48 +27,27 @@ _ALIASES = {
|
||||
|
||||
|
||||
class TestMessagingSetup(base.SaharaTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMessagingSetup, self).setUp()
|
||||
@mock.patch('oslo_messaging.set_transport_defaults')
|
||||
@mock.patch('oslo_messaging.get_transport')
|
||||
@mock.patch('oslo_messaging.Notifier')
|
||||
def test_set_defaults(self, notifier_init,
|
||||
get_transport, set_transport_def):
|
||||
self.override_config('enable', True,
|
||||
group='oslo_messaging_notifications')
|
||||
|
||||
def _install(self):
|
||||
messaging.setup()
|
||||
self.assertIsNotNone(messaging.TRANSPORT)
|
||||
self.assertIsNotNone(messaging.NOTIFIER)
|
||||
|
||||
def _remove_install(self):
|
||||
if messaging.TRANSPORT:
|
||||
messaging.TRANSPORT.cleanup()
|
||||
messaging.TRANSPORT = messaging.NOTIFIER = None
|
||||
|
||||
@mock.patch('oslo_messaging.set_transport_defaults')
|
||||
def test_set_defaults(self, mock_transport):
|
||||
self._install()
|
||||
|
||||
expected = [
|
||||
mock.call('sahara')
|
||||
]
|
||||
self.assertEqual(expected, mock_transport.call_args_list)
|
||||
self.assertEqual(expected, set_transport_def.call_args_list)
|
||||
self.assertEqual(
|
||||
[mock.call(main.CONF, aliases=_ALIASES)],
|
||||
get_transport.call_args_list)
|
||||
self.assertEqual(1, notifier_init.call_count)
|
||||
|
||||
self._remove_install()
|
||||
|
||||
@mock.patch('oslo_messaging.get_transport')
|
||||
def test_get_transport(self, mock_transport):
|
||||
self._install()
|
||||
|
||||
expected = [
|
||||
mock.call(main.CONF, aliases=_ALIASES)
|
||||
]
|
||||
self.assertEqual(expected, mock_transport.call_args_list)
|
||||
|
||||
self._remove_install()
|
||||
|
||||
@mock.patch('oslo_messaging.Notifier')
|
||||
def test_notifier(self, mock_init):
|
||||
self._install()
|
||||
|
||||
self.assertEqual(1, mock_init.call_count)
|
||||
|
||||
self._remove_install()
|
||||
if messaging.TRANSPORT:
|
||||
messaging.TRANSPORT.cleanup()
|
||||
messaging.TRANSPORT = messaging.NOTIFIER = None
|
||||
|
@ -13,6 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
|
||||
from keystoneauth1.access import service_catalog as keystone_service_catalog
|
||||
from keystoneauth1 import exceptions as keystone_ex
|
||||
from oslo_config import cfg
|
||||
@ -63,15 +65,24 @@ def url_for(service_catalog=None, service_type='identity',
|
||||
region_name=CONF.os_region_name)
|
||||
|
||||
|
||||
def retrieve_auth_url(endpoint_type="internalURL"):
|
||||
version = 'v3' if CONF.use_identity_api_v3 else 'v2.0'
|
||||
def prepare_auth_url(auth_url, version):
|
||||
info = urlparse.urlparse(auth_url)
|
||||
url_path = info.path.rstrip("/")
|
||||
# replacing current api version to empty string
|
||||
url_path = re.sub('/(v3/auth|v3|v2\.0)', '', url_path)
|
||||
url_path = (url_path + "/" + version).lstrip("/")
|
||||
return "%s://%s/%s" % (info[:2] + (url_path,))
|
||||
|
||||
|
||||
def retrieve_auth_url(endpoint_type="internalURL", version=None):
|
||||
if not version:
|
||||
version = 'v3' if CONF.use_identity_api_v3 else 'v2.0'
|
||||
ctx = context.current()
|
||||
if ctx.service_catalog:
|
||||
info = urlparse.urlparse(url_for(ctx.service_catalog, 'identity',
|
||||
endpoint_type))
|
||||
auth_url = url_for(ctx.service_catalog, 'identity', endpoint_type)
|
||||
else:
|
||||
info = urlparse.urlparse(CONF.keystone_authtoken.auth_uri)
|
||||
return "%s://%s/%s" % (info[:2] + (version,))
|
||||
auth_url = CONF.keystone_authtoken.auth_uri
|
||||
return prepare_auth_url(auth_url, version)
|
||||
|
||||
|
||||
def execute_with_retries(method, *args, **kwargs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user