From 581300632b426e985bf3daaed426daf3c89f825a Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Thu, 4 Aug 2022 11:57:02 +0100 Subject: [PATCH] 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 --- charms_openstack/adapters.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/charms_openstack/adapters.py b/charms_openstack/adapters.py index 5d1d90c..e5d42ec 100644 --- a/charms_openstack/adapters.py +++ b/charms_openstack/adapters.py @@ -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.