Merge "Break reference cycle in KeystoneClient plugins"

This commit is contained in:
Jenkins 2016-05-16 05:44:38 +00:00 committed by Gerrit Code Review
commit bf18856442
2 changed files with 17 additions and 2 deletions

View File

@ -13,6 +13,8 @@
"""Client Library for Keystone Resources.""" """Client Library for Keystone Resources."""
import weakref
from keystoneclient.v2_0 import client as kc from keystoneclient.v2_0 import client as kc
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -48,7 +50,7 @@ class KeystoneClientV2(object):
# get a new trust-token even if context.auth_token is set. # get a new trust-token even if context.auth_token is set.
# #
# - context.auth_url is expected to contain the v2.0 keystone endpoint # - context.auth_url is expected to contain the v2.0 keystone endpoint
self.context = context self._context = weakref.ref(context)
self._client = None self._client = None
if self.context.trust_id: if self.context.trust_id:
@ -56,6 +58,12 @@ class KeystoneClientV2(object):
# populates self.context.auth_token with a trust-scoped token # populates self.context.auth_token with a trust-scoped token
self._client = self._v2_client_init() self._client = self._v2_client_init()
@property
def context(self):
ctxt = self._context()
assert ctxt is not None, "Need a reference to the context"
return ctxt
@property @property
def client(self): def client(self):
if not self._client: if not self._client:

View File

@ -15,6 +15,7 @@
import collections import collections
import uuid import uuid
import weakref
from keystoneclient.auth.identity import v3 as kc_auth_v3 from keystoneclient.auth.identity import v3 as kc_auth_v3
import keystoneclient.exceptions as kc_exception import keystoneclient.exceptions as kc_exception
@ -69,7 +70,7 @@ class KeystoneClientV3(object):
# #
# - context.auth_url is expected to contain a versioned keystone # - context.auth_url is expected to contain a versioned keystone
# path, we will work with either a v2.0 or v3 path # path, we will work with either a v2.0 or v3 path
self.context = context self._context = weakref.ref(context)
self._client = None self._client = None
self._admin_auth = None self._admin_auth = None
self._domain_admin_auth = None self._domain_admin_auth = None
@ -96,6 +97,12 @@ class KeystoneClientV3(object):
LOG.debug('Using stack domain %s' % self.stack_domain) LOG.debug('Using stack domain %s' % self.stack_domain)
@property
def context(self):
ctxt = self._context()
assert ctxt is not None, "Need a reference to the context"
return ctxt
@property @property
def stack_domain(self): def stack_domain(self):
"""Domain scope data. """Domain scope data.