diff --git a/lib/charms/opensearch/v0/opensearch_relation_provider.py b/lib/charms/opensearch/v0/opensearch_relation_provider.py index e59992436..b899cd53d 100644 --- a/lib/charms/opensearch/v0/opensearch_relation_provider.py +++ b/lib/charms/opensearch/v0/opensearch_relation_provider.py @@ -59,7 +59,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 2 +LIBPATCH = 3 logger = logging.getLogger(__name__) @@ -418,7 +418,7 @@ def update_endpoints(self, relation: Relation, omit_endpoints: Optional[Set[str] ips = set() port = self.opensearch.port - endpoints = ",".join([f"{ip}:{port}" for ip in ips - omit_endpoints]) + endpoints = ",".join(sorted([f"{ip}:{port}" for ip in ips - omit_endpoints])) databag_endpoints = relation.data[relation.app].get("endpoints") if endpoints != databag_endpoints: diff --git a/tests/unit/lib/test_opensearch_relation_provider.py b/tests/unit/lib/test_opensearch_relation_provider.py index 49692ba5d..c8c808968 100644 --- a/tests/unit/lib/test_opensearch_relation_provider.py +++ b/tests/unit/lib/test_opensearch_relation_provider.py @@ -252,14 +252,16 @@ def test_on_relation_broken(self, _, __, _is_node_up, _remove_users, _unit_depar @patch("charm.OpenSearchOperatorCharm._purge_users") def test_update_endpoints(self, _, __, _nodes, _is_node_up, _set_endpoints): self.harness.set_leader(True) - node = MagicMock() - node.ip = "4.4.4.4" - _nodes.return_value = [node] + node1 = MagicMock() + node1.ip = "4.4.4.4" + node2 = MagicMock() + node2.ip = "5.5.5.5" + _nodes.return_value = [node2, node1] # out of order relation = MagicMock() relation.id = 1 endpoints = [f"{node.ip}:{self.charm.opensearch.port}" for node in _nodes.return_value] self.opensearch_provider.update_endpoints(relation) - _set_endpoints.assert_called_with(relation.id, ",".join(endpoints)) + _set_endpoints.assert_called_with(relation.id, ",".join(sorted(endpoints))) def add_dashboard_relation(self): opensearch_relation = self.harness.add_relation(