~corey.bryant/sahara/2014.2-merge

« back to all changes in this revision

Viewing changes to debian/patches/Use_auth_uri_parameter_from_config.patch

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-rzyyf1iduiof3bjx
Tags: 2014.2~b3-1
Initial release. (Closes: #762659)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
9
 
 
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
 
15
 
 
16
 AUTH_OPT_GROUP_NAME = 'keystone_authtoken'
 
17
 
 
18
-# Keystone auth uri that could be used in other places in Sahara
 
19
-AUTH_URI = None
 
20
-
 
21
 
 
22
 def wrap(app, conf):
 
23
     """Wrap wsgi application with ACL check."""
 
24
 
 
25
     auth_cfg = dict(conf.get(AUTH_OPT_GROUP_NAME))
 
26
-    auth_protocol = auth_token.AuthProtocol(app, conf=auth_cfg)
 
27
-
 
28
-    # store auth uri in global var to be able to use it in runtime
 
29
-    global AUTH_URI
 
30
-    AUTH_URI = auth_protocol._identity_server.auth_uri
 
31
-
 
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
 
41
 
 
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):
 
47
         if kwargs:
 
48
             LOG.warn(_LW('Arguments dropped when creating context: %s'),
 
49
                      kwargs)
 
50
+
 
51
         self.user_id = user_id
 
52
         self.tenant_id = tenant_id
 
53
         self.token = token
 
54
@@ -59,7 +59,10 @@ class Context(object):
 
55
         self.remote_semaphore = remote_semaphore or semaphore.Semaphore(
 
56
             CONF.cluster_remote_threshold)
 
57
         self.roles = roles
 
58
-        self.auth_uri = auth_uri or acl.AUTH_URI
 
59
+        if auth_uri:
 
60
+            self.auth_uri = auth_uri
 
61
+        else:
 
62
+            self.auth_uri = _get_auth_uri()
 
63
 
 
64
     def clone(self):
 
65
         return Context(
 
66
@@ -122,6 +125,28 @@ def set_ctx(new_ctx):
 
67
         setattr(_CTX_STORE, _CTX_KEY, new_ctx)
 
68
 
 
69
 
 
70
+def _get_auth_uri():
 
71
+    if CONF.keystone_authtoken.auth_uri is not None:
 
72
+        auth_uri = CONF.keystone_authtoken.auth_uri
 
73
+    else:
 
74
+        if CONF.keystone_authtoken.identity_uri is not None:
 
75
+            identity_uri = CONF.keystone_authtoken.identity_uri
 
76
+        else:
 
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)
 
81
+
 
82
+        if CONF.use_identity_api_v3 is False:
 
83
+            auth_version = 'v2.0'
 
84
+        else:
 
85
+            auth_version = 'v3'
 
86
+
 
87
+        auth_uri = '%s/%s' % (identity_uri, auth_version)
 
88
+
 
89
+    return auth_uri
 
90
+
 
91
+
 
92
 def _wrapper(ctx, thread_description, thread_group, func, *args, **kwargs):
 
93
     try:
 
94
         set_ctx(ctx)
 
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
 
99
@@ -13,6 +13,7 @@
 
100
 # See the License for the specific language governing permissions and
 
101
 # limitations under the License.
 
102
 
 
103
+import functools
 
104
 import random
 
105
 
 
106
 import fixtures
 
107
@@ -22,6 +23,7 @@ import testtools
 
108
 
 
109
 from sahara import context
 
110
 from sahara import exceptions as ex
 
111
+from sahara.tests.unit import base as test_base
 
112
 
 
113
 
 
114
 rnd = random.Random()
 
115
@@ -135,3 +137,31 @@ class ContextTest(testtools.TestCase):
 
116
 
 
117
 class TestException(Exception):
 
118
     pass
 
119
+
 
120
+
 
121
+class GetAuthURITest(test_base.SaharaTestCase):
 
122
+    def setUp(self):
 
123
+        super(GetAuthURITest, self).setUp()
 
124
+
 
125
+        self.override_auth_config = functools.partial(
 
126
+            self.override_config, group='keystone_authtoken')
 
127
+
 
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())
 
131
+
 
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())
 
135
+
 
136
+        self.override_config('use_identity_api_v3', False)
 
137
+        self.assertEqual('http://spam:35357/v2.0', context._get_auth_uri())
 
138
+
 
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())
 
144
+
 
145
+        self.override_config('use_identity_api_v3', False)
 
146
+        self.assertEqual('http://eggs:12345/v2.0', context._get_auth_uri())