Skip to content

Commit

Permalink
[DPE-4230] - fix: sort endpoints so not constantly updating (#270)
Browse files Browse the repository at this point in the history
Fixes #269, I
think
  • Loading branch information
marcoppenheimer authored Apr 29, 2024
1 parent a682863 commit 704e521
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/charms/opensearch/v0/opensearch_relation_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/lib/test_opensearch_relation_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 704e521

Please sign in to comment.