[tempest-k8s] Fix error on remove-application
Previously on application remove, tempest-k8s charm would error at the relation-broken hook, causing the removal to fail: ``` tempest/0* error idle 10.1.169.40 hook failed: "identity-ops-relation-broken" ``` with traceback: ``` File "/var/lib/juju/agents/unit-tempest-0/charm/src/handlers.py", line 609, in _on_provider_goneaway self.charm.set_tempest_ready(False) File "/var/lib/juju/agents/unit-tempest-0/charm/./src/charm.py", line 283, in set_tempest_ready self.peers.set_unit_data({TEMPEST_READY_KEY: "true" if ready else ""}) File "/var/lib/juju/agents/unit-tempest-0/charm/lib/ops_sunbeam/relation_handlers.py", line 625, in set_unit_data self.interface.set_unit_data(settings) File "/var/lib/juju/agents/unit-tempest-0/charm/lib/ops_sunbeam/interfaces.py", line 150, in set_unit_data self.peers_rel.data[self.model.unit][k] = v AttributeError: 'NoneType' object has no attribute 'data' ``` This fixes the issue for tempest (and potentially if similar issues are present on other sunbeam charms), by checking if peels_rel exists because trying to interact with it. Change-Id: I5e01c1dba719a63160f0452282d57b9eae14b41b
This commit is contained in:
@@ -84,7 +84,7 @@ class OperatorPeers(Object):
|
||||
)
|
||||
|
||||
@property
|
||||
def peers_rel(self) -> ops.model.Relation:
|
||||
def peers_rel(self) -> ops.model.Relation | None:
|
||||
"""Peer relation."""
|
||||
return self.framework.model.get_relation(self.relation_name)
|
||||
|
||||
@@ -146,11 +146,15 @@ class OperatorPeers(Object):
|
||||
|
||||
def set_unit_data(self, settings: Dict[str, str]) -> None:
|
||||
"""Publish settings on the peer unit data bag."""
|
||||
if not self.peers_rel:
|
||||
return
|
||||
for k, v in settings.items():
|
||||
self.peers_rel.data[self.model.unit][k] = v
|
||||
|
||||
def all_joined_units(self) -> List[ops.model.Unit]:
|
||||
"""All remote units joined to the peer relation."""
|
||||
if not self.peers_rel:
|
||||
return []
|
||||
return set(self.peers_rel.units)
|
||||
|
||||
def expected_peer_units(self) -> int:
|
||||
@@ -158,4 +162,6 @@ class OperatorPeers(Object):
|
||||
|
||||
NOTE: This count includes this unit
|
||||
"""
|
||||
if not self.peers_rel:
|
||||
return 0
|
||||
return self.peers_rel.app.planned_units()
|
||||
|
Reference in New Issue
Block a user