Ensure that the _resolved_cluster member is set
In the OpenStackAPIRelationAdapters class, the _resolved_cluster member
is used to determine the cluster relation had been resolved. However,
it's possible that it is accessed prior to be used as it was originally
an dunderscored method (__method). This patch makes it more robust by
switching to a single-underscore (which is inherited and not class-
mangled) and that it is always set to None initially in the __init__
method.
Change-Id: I9b119ba6848923c27844a2f758ae9e3c34c7722d
Closes-Bug: #1981736
(cherry picked from commit c924762a9c
)
This commit is contained in:
parent
a2df79c76f
commit
40b616ef1c
|
@ -1333,22 +1333,22 @@ class OpenStackAPIRelationAdapters(OpenStackRelationAdapters):
|
|||
options=options,
|
||||
options_instance=options_instance,
|
||||
charm_instance=charm_instance)
|
||||
self._resolved_cluster = None
|
||||
if 'cluster' not in self._relations:
|
||||
# cluster has not been passed through already, so try to resolve it
|
||||
# automatically when it is accessed.
|
||||
self.__resolved_cluster = None
|
||||
# add a property for the cluster to resolve it
|
||||
self._relations.add('cluster')
|
||||
setattr(self.__class__, 'cluster',
|
||||
property(lambda x: x.__cluster()))
|
||||
property(lambda x: x._cluster()))
|
||||
|
||||
def __cluster(self):
|
||||
def _cluster(self):
|
||||
"""The cluster relations is auto added onto adapters instance"""
|
||||
if not self.__resolved_cluster:
|
||||
self.__resolved_cluster = self.__resolve_cluster()
|
||||
return self.__resolved_cluster
|
||||
if not self._resolved_cluster:
|
||||
self._resolved_cluster = self._resolve_cluster()
|
||||
return self._resolved_cluster
|
||||
|
||||
def __resolve_cluster(self):
|
||||
def _resolve_cluster(self):
|
||||
""" Resolve what the cluster adapter is.
|
||||
|
||||
LY: The cluster interface only gets initialised if there are more
|
||||
|
|
Loading…
Reference in New Issue