Simplify url_for in client_plugin
This simplifies url_for in client_plugin to use generic identity plugin and has_service_catalog method. Change-Id: I96033aae54e03bf4dbbaad8bd16a2c93c73e41d6 Related-Bug: #1554533
This commit is contained in:
parent
44862d9ac4
commit
0f6d61e735
|
@ -17,8 +17,7 @@ import sys
|
|||
import weakref
|
||||
|
||||
from keystoneauth1 import exceptions
|
||||
from keystoneauth1.identity import v2
|
||||
from keystoneauth1.identity import v3
|
||||
from keystoneauth1.identity import generic
|
||||
from keystoneauth1 import plugin
|
||||
from keystoneauth1 import session
|
||||
from oslo_config import cfg
|
||||
|
@ -27,7 +26,6 @@ import six
|
|||
|
||||
from heat.common import config
|
||||
from heat.common import exception as heat_exception
|
||||
from heat.common.i18n import _
|
||||
|
||||
cfg.CONF.import_opt('client_retry_limit', 'heat.common.config')
|
||||
|
||||
|
@ -198,31 +196,13 @@ class ClientPlugin(object):
|
|||
try:
|
||||
url = get_endpoint()
|
||||
except exceptions.EmptyCatalog:
|
||||
kc = self.clients.client('keystone').client
|
||||
|
||||
auth_plugin = self.context.auth_plugin
|
||||
endpoint = auth_plugin.get_endpoint(
|
||||
None, interface=plugin.AUTH_INTERFACE)
|
||||
token = auth_plugin.get_token(None)
|
||||
project_id = auth_plugin.get_project_id(None)
|
||||
|
||||
if kc.version == 'v3':
|
||||
token_obj = v3.Token(endpoint, token, project_id=project_id)
|
||||
catalog_key = 'catalog'
|
||||
access_key = 'token'
|
||||
elif kc.version == 'v2.0':
|
||||
endpoint = endpoint.replace('v3', 'v2.0')
|
||||
token_obj = v2.Token(endpoint, token, tenant_id=project_id)
|
||||
catalog_key = 'serviceCatalog'
|
||||
access_key = 'access'
|
||||
else:
|
||||
raise exceptions.Error(_("Unknown Keystone version"))
|
||||
|
||||
auth_ref = token_obj.get_auth_ref(self._keystone_session)
|
||||
|
||||
if catalog_key in auth_ref:
|
||||
access_info = self.context.auth_token_info[access_key]
|
||||
access_info[catalog_key] = auth_ref[catalog_key]
|
||||
token_obj = generic.Token(endpoint, token)
|
||||
auth_ref = token_obj.get_access(self._keystone_session)
|
||||
if auth_ref.has_service_catalog():
|
||||
self.context.reload_auth_plugin()
|
||||
url = get_endpoint()
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ from glanceclient import exc as glance_exc
|
|||
from glanceclient.openstack.common.apiclient import exceptions as g_a_exc
|
||||
from heatclient import client as heatclient
|
||||
from heatclient import exc as heat_exc
|
||||
from keystoneauth1.identity import v3
|
||||
from keystoneauth1.identity import generic
|
||||
from keystoneclient import exceptions as keystone_exc
|
||||
from manilaclient import exceptions as manila_exc
|
||||
import mock
|
||||
|
@ -295,7 +295,7 @@ class ClientPluginTest(common.HeatTestCase):
|
|||
plugin.url_for(service_type='foo'))
|
||||
self.assertTrue(con.auth_plugin.get_endpoint.called)
|
||||
|
||||
@mock.patch.object(v3, "Token", name="v3_token")
|
||||
@mock.patch.object(generic, "Token", name="v3_token")
|
||||
def test_get_missing_service_catalog(self, mock_v3):
|
||||
class FakeKeystone(fakes.FakeKeystoneClient):
|
||||
def __init__(self):
|
||||
|
@ -323,7 +323,7 @@ class ClientPluginTest(common.HeatTestCase):
|
|||
self.assertEqual('http://192.0.2.1/bar',
|
||||
plugin.url_for(service_type='bar'))
|
||||
|
||||
@mock.patch.object(v3, "Token", name="v3_token")
|
||||
@mock.patch.object(generic, "Token", name="v3_token")
|
||||
def test_endpoint_not_found(self, mock_v3):
|
||||
class FakeKeystone(fakes.FakeKeystoneClient):
|
||||
def __init__(self):
|
||||
|
@ -343,8 +343,11 @@ class ClientPluginTest(common.HeatTestCase):
|
|||
|
||||
mock_token_obj = mock.Mock()
|
||||
mock_v3.return_value = mock_token_obj
|
||||
mock_token_obj.get_auth_ref.return_value = {'no_catalog': 'without'}
|
||||
|
||||
mock_access = mock.Mock()
|
||||
self.patchobject(mock_token_obj, 'get_access',
|
||||
return_value=mock_access)
|
||||
self.patchobject(mock_access, 'has_service_catalog',
|
||||
return_value=False)
|
||||
plugin = FooClientsPlugin(con)
|
||||
|
||||
self.assertRaises(keystone_exc.EndpointNotFound,
|
||||
|
|
Loading…
Reference in New Issue