1
Subject: Use 'auth_uri' parameter from config
2
From: Sergey Reshetnyak <sreshetniak@mirantis.com>
3
Date: Thu, 18 Sep 2014 11:49:34 +0000 (+0400)
4
X-Git-Url: https://review.openstack.org/gitweb?p=openstack%2Fsahara.git;a=commitdiff_plain;h=d2058585160a99b7e7908fcf1066bbb9ef4102a6
5
Change-Id: I0276d30d8e142dca120915a8c91a500159a353d3
6
Bug-Ubuntu:: https://bugs.launchpad.net/sahara/+bug/1371012
7
Origin: upstream, https://review.openstack.org/#/c/122392/
8
Last-Update: 2014-09-25
10
diff --git a/sahara/api/acl.py b/sahara/api/acl.py
11
index e404827..8891f5a 100644
12
--- a/sahara/api/acl.py
13
+++ b/sahara/api/acl.py
14
@@ -23,18 +23,9 @@ CONF = cfg.CONF
16
AUTH_OPT_GROUP_NAME = 'keystone_authtoken'
18
-# Keystone auth uri that could be used in other places in Sahara
23
"""Wrap wsgi application with ACL check."""
25
auth_cfg = dict(conf.get(AUTH_OPT_GROUP_NAME))
26
- auth_protocol = auth_token.AuthProtocol(app, conf=auth_cfg)
28
- # store auth uri in global var to be able to use it in runtime
30
- AUTH_URI = auth_protocol._identity_server.auth_uri
32
- return auth_protocol
33
+ return auth_token.AuthProtocol(app, conf=auth_cfg)
34
diff --git a/sahara/context.py b/sahara/context.py
35
index 9db3233..3f4bf3b 100644
36
--- a/sahara/context.py
37
+++ b/sahara/context.py
38
@@ -20,7 +20,6 @@ from eventlet import greenpool
39
from eventlet import semaphore
40
from oslo.config import cfg
42
-from sahara.api import acl
43
from sahara import exceptions as ex
44
from sahara.i18n import _
45
from sahara.i18n import _LE
46
@@ -49,6 +48,7 @@ class Context(object):
48
LOG.warn(_LW('Arguments dropped when creating context: %s'),
51
self.user_id = user_id
52
self.tenant_id = tenant_id
54
@@ -59,7 +59,10 @@ class Context(object):
55
self.remote_semaphore = remote_semaphore or semaphore.Semaphore(
56
CONF.cluster_remote_threshold)
58
- self.auth_uri = auth_uri or acl.AUTH_URI
60
+ self.auth_uri = auth_uri
62
+ self.auth_uri = _get_auth_uri()
66
@@ -122,6 +125,28 @@ def set_ctx(new_ctx):
67
setattr(_CTX_STORE, _CTX_KEY, new_ctx)
71
+ if CONF.keystone_authtoken.auth_uri is not None:
72
+ auth_uri = CONF.keystone_authtoken.auth_uri
74
+ if CONF.keystone_authtoken.identity_uri is not None:
75
+ identity_uri = CONF.keystone_authtoken.identity_uri
77
+ host = CONF.keystone_authtoken.auth_host
78
+ port = CONF.keystone_authtoken.auth_port
79
+ protocol = CONF.keystone_authtoken.auth_protocol
80
+ identity_uri = '%s://%s:%s' % (protocol, host, port)
82
+ if CONF.use_identity_api_v3 is False:
83
+ auth_version = 'v2.0'
87
+ auth_uri = '%s/%s' % (identity_uri, auth_version)
92
def _wrapper(ctx, thread_description, thread_group, func, *args, **kwargs):
95
diff --git a/sahara/tests/unit/test_context.py b/sahara/tests/unit/test_context.py
96
index decaa8f..04bcbe6 100644
97
--- a/sahara/tests/unit/test_context.py
98
+++ b/sahara/tests/unit/test_context.py
100
# See the License for the specific language governing permissions and
101
# limitations under the License.
107
@@ -22,6 +23,7 @@ import testtools
109
from sahara import context
110
from sahara import exceptions as ex
111
+from sahara.tests.unit import base as test_base
114
rnd = random.Random()
115
@@ -135,3 +137,31 @@ class ContextTest(testtools.TestCase):
117
class TestException(Exception):
121
+class GetAuthURITest(test_base.SaharaTestCase):
123
+ super(GetAuthURITest, self).setUp()
125
+ self.override_auth_config = functools.partial(
126
+ self.override_config, group='keystone_authtoken')
128
+ def test_get_auth_url_from_auth_uri_param(self):
129
+ self.override_auth_config('auth_uri', 'http://pony:5000/v2.0')
130
+ self.assertEqual('http://pony:5000/v2.0', context._get_auth_uri())
132
+ def test_get_auth_uri_from_identity_uri(self):
133
+ self.override_auth_config('identity_uri', 'http://spam:35357')
134
+ self.assertEqual('http://spam:35357/v3', context._get_auth_uri())
136
+ self.override_config('use_identity_api_v3', False)
137
+ self.assertEqual('http://spam:35357/v2.0', context._get_auth_uri())
139
+ def test_get_auth_uri_from_auth_params(self):
140
+ self.override_auth_config('auth_host', 'eggs')
141
+ self.override_auth_config('auth_port', 12345)
142
+ self.override_auth_config('auth_protocol', 'http')
143
+ self.assertEqual('http://eggs:12345/v3', context._get_auth_uri())
145
+ self.override_config('use_identity_api_v3', False)
146
+ self.assertEqual('http://eggs:12345/v2.0', context._get_auth_uri())