Browse Source

Add get_keystone_token and get_keystone_endpoint functions

Change-Id: If82e2e9626908cefbe5466527a01d90b79337d92
changes/26/761726/6
Federico Ressi 10 months ago
parent
commit
c8f3f2b301
  1. 2
      tobiko/openstack/keystone/__init__.py
  2. 16
      tobiko/openstack/keystone/_session.py
  3. 9
      tobiko/tests/functional/openstack/test_keystone.py

2
tobiko/openstack/keystone/__init__.py

@ -55,4 +55,6 @@ keystone_session = _session.keystone_session
KeystoneSessionType = _session.KeystoneSessionType
KeystoneSessionFixture = _session.KeystoneSessionFixture
KeystoneSessionManager = _session.KeystoneSessionManager
get_keystone_endpoint = _session.get_keystone_endpoint
get_keystone_session = _session.get_keystone_session
get_keystone_token = _session.get_keystone_token

16
tobiko/openstack/keystone/_session.py

@ -17,6 +17,7 @@ import typing
from keystoneauth1 import loading
from keystoneauth1 import session as _session
from keystoneauth1 import plugin as _plugin
from oslo_log import log
import tobiko
@ -165,3 +166,18 @@ def get_keystone_session(
init_session=init_session)
tobiko.check_valid_type(session, KeystoneSessionFixture)
return tobiko.setup_fixture(session).session
def get_keystone_endpoint(
session: KeystoneSessionType = None,
auth: typing.Optional[_plugin.BaseAuthPlugin] = None,
**kwargs) -> \
typing.Optional[str]:
return keystone_session(session).get_endpoint(auth=auth, **kwargs)
def get_keystone_token(
session: KeystoneSessionType = None,
auth: typing.Optional[_plugin.BaseAuthPlugin] = None) -> \
typing.Optional[str]:
return keystone_session(session).get_token(auth=auth)

9
tobiko/tests/functional/openstack/test_keystone.py

@ -172,3 +172,12 @@ class KeystoneClientAPITest(testtools.TestCase):
self.assertEqual(service.id, endpoint.service_id)
self.assertEqual('public', endpoint.interface)
self.assertTrue(endpoint.enabled)
def test_get_session_endpoint(self):
endpoint = keystone.get_keystone_endpoint(
service_type='identity')
self.assertIsInstance(endpoint, str)
def test_get_session_token(self):
token = keystone.get_keystone_token()
self.assertIsInstance(token, str)
Loading…
Cancel
Save