Fix missing service_catalog parameter in Client object
Return None if service_catalog parameter does not exist. service_catalog is the property and it is not initialized on object creation. service_catalog tries to get value from auth_ref and raises AttributeError exception if auth_ref is not initialized. It worked before we introduced sessions, because authentication happened on client instantiation. Now, when sessions are used, auth_ref is not initialized until the first request. This change adds try-catch block in service_catalog property to catch this error. Change-Id: I58eb888f0989241f9e5626564bd48d901b324d36 Closes-Bug: #1508374
This commit is contained in:
parent
5a7f800e27
commit
b405d71a5f
|
@ -442,7 +442,10 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
|||
@property
|
||||
def service_catalog(self):
|
||||
"""Return this client's service catalog."""
|
||||
return self.auth_ref.service_catalog
|
||||
try:
|
||||
return self.auth_ref.service_catalog
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
def has_service_catalog(self):
|
||||
"""Return True if this client provides a service catalog."""
|
||||
|
|
|
@ -15,6 +15,7 @@ import uuid
|
|||
|
||||
import six
|
||||
|
||||
from keystoneauth1 import session as auth_session
|
||||
from keystoneclient.auth import token_endpoint
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient import fixture
|
||||
|
@ -211,3 +212,10 @@ class KeystoneClientTest(utils.TestCase):
|
|||
|
||||
self.assertEqual('identity', cl._adapter.service_type)
|
||||
self.assertEqual((2, 0), cl._adapter.version)
|
||||
|
||||
def test_empty_service_catalog_param(self):
|
||||
# Client().service_catalog should return None if the client is not
|
||||
# authenticated
|
||||
sess = auth_session.Session()
|
||||
cl = client.Client(session=sess)
|
||||
self.assertEqual(None, cl.service_catalog)
|
||||
|
|
|
@ -16,6 +16,7 @@ import uuid
|
|||
|
||||
import six
|
||||
|
||||
from keystoneauth1 import session as auth_session
|
||||
from keystoneclient.auth import token_endpoint
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient import session
|
||||
|
@ -261,3 +262,10 @@ class KeystoneClientTest(utils.TestCase):
|
|||
|
||||
self.assertEqual('identity', cl._adapter.service_type)
|
||||
self.assertEqual((3, 0), cl._adapter.version)
|
||||
|
||||
def test_empty_service_catalog_param(self):
|
||||
# Client().service_catalog should return None if the client is not
|
||||
# authenticated
|
||||
sess = auth_session.Session()
|
||||
cl = client.Client(session=sess)
|
||||
self.assertEqual(None, cl.service_catalog)
|
||||
|
|
Loading…
Reference in New Issue