Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-4860][DPE-4982]
get_relation(PeerRelationName)
returns None
…
…if `remove-application` has been requested (#361) The main issue here is the `storage-detaching` after remove-application. That gets more complex if we consider the last unit going away. In this scenario, we cannot consider that relations will be available anymore, such as peer relation databag. For example, the `get_host_ip` uses the `charm.model.get_binding(peer_relation_name)`, which returns a valid object even if we have a single unit. The `unit_ip` is also called outside of the `helper_networking.py`, on `opensearch_distro`. However, all these methods have previous checks, i.e. we never call `unit_ip` for another unit that its own outside of `unit_ips`. Also, we skip acquiring the lock in this case, as the application is going away. ## The `get_relation` behavior ### Before `remove-application` with single unit Even if we have a single unit, we still have the peer relation databag available. The databag will be used by that single unit across the unit's lifecycle. We can see it with: ``` root@juju-941823-0:/var/lib/juju/agents/unit-opensearch-0/charm# nano src/charm.py root@juju-941823-0:/var/lib/juju/agents/unit-opensearch-0/charm# nano lib/charms/opensearch/v0/opensearch_base_charm.py root@juju-941823-0:/var/lib/juju/agents/unit-opensearch-0/charm# ./dispatch 2024-07-26 14:27:56,864 DEBUG ops 2.14.1 up and running. --Return-- > /var/lib/juju/agents/unit-opensearch-0/charm/lib/charms/opensearch/v0/opensearch_base_charm.py(250)__init__()->None -> import pdb; pdb.set_trace() (Pdb) p self.model.get_relation(PeerRelationName) <ops.model.Relation opensearch-peers:0> ``` ### After `remove-application` After remove-application has been received, we can see that relation object will not be retrieved anymore: ``` root@juju-6884bf-2:/var/lib/juju/agents/unit-opensearch-1/charm# ./dispatch 2024-08-05 18:38:42,246 DEBUG ops 2.15.0 up and running. --Return-- > /var/lib/juju/agents/unit-opensearch-1/charm/lib/charms/opensearch/v0/opensearch_base_charm.py(250)__init_ _()->None -> import pdb; pdb.set_trace() (Pdb) p self.model.get_relation(PeerRelationName) None (Pdb) ``` Closes #360 Closes #378 Closes #379 --------- Co-authored-by: Mehdi Bendriss <[email protected]>
- Loading branch information