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
This commit is contained in:
Alex Kavanagh 2022-08-01 19:05:23 +01:00
parent 11ba59ab4d
commit c924762a9c
1 changed files with 7 additions and 7 deletions

View File

@ -1359,22 +1359,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