Further fix to OpenStackAPIRelationAdapters

The existing method of using a property to lazily load the cluster
relation adapter permanently changes the class to include that as
a cluster property.  This means that a future (in the same hook
execution) instantiation of the class would include that property,
which means that 'real' cluster adapter could not be used. Sadly,
this was happening with the manila charm, and possibly others.

This patch changes it from a lazily loaded property, to a simple
attribute.

Change-Id: I704f362e0dd845ff00d0f0470b0235a4dead5f9f
Closes-Bug: #1981736
This commit is contained in:
Alex Kavanagh 2022-08-04 11:57:02 +01:00
parent c924762a9c
commit 581300632b
1 changed files with 2 additions and 11 deletions

View File

@ -1359,20 +1359,11 @@ 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.
# add a property for the cluster to resolve it
# automatically.
self._relations.add('cluster')
setattr(self.__class__, 'cluster',
property(lambda x: x._cluster()))
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
setattr(self, 'cluster', self._resolve_cluster())
def _resolve_cluster(self):
""" Resolve what the cluster adapter is.