From aabc9deb900e13a75677285d888397194e0dadb2 Mon Sep 17 00:00:00 2001 From: Pedro Guimaraes Date: Fri, 3 May 2024 11:14:55 +0200 Subject: [PATCH] Add sort_keys=True --- .../v0/opensearch_relation_peer_cluster.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py b/lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py index 9b70192d3..6672d3ea1 100644 --- a/lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py +++ b/lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py @@ -187,7 +187,8 @@ def _on_peer_cluster_relation_changed(self, event: RelationChangedEvent): ) orchestrators.failover_app = candidate_failover_app self.put_in_rel( - data={"orchestrators": json.dumps(orchestrators.to_dict())}, rel_id=rel_id + data={"orchestrators": json.dumps(orchestrators.to_dict(), sort_keys=True)}, + rel_id=rel_id, ) def _on_peer_cluster_relation_departed(self, event: RelationDepartedEvent) -> None: @@ -249,7 +250,9 @@ def refresh_relation_data(self, event: EventBase) -> None: f"{cluster_type}_rel_id": rel_id, } ) - self.put_in_rel(data={"orchestrators": json.dumps(orchestrators)}, rel_id=rel_id) + self.put_in_rel( + data={"orchestrators": json.dumps(orchestrators, sort_keys=True)}, rel_id=rel_id + ) # there is no error to broadcast - we clear any previously broadcasted error if isinstance(rel_data, PeerClusterRelData): @@ -257,7 +260,8 @@ def refresh_relation_data(self, event: EventBase) -> None: # are we potentially overriding stuff here? self.put_in_rel( - data={peer_rel_data_key: json.dumps(rel_data.to_dict())}, rel_id=rel_id + data={peer_rel_data_key: json.dumps(rel_data.to_dict(), sort_keys=True)}, + rel_id=rel_id, ) if should_defer: @@ -276,7 +280,9 @@ def _notify_if_wrong_integration( return False for rel_id in target_relation_ids: - self.put_in_rel(data={"error_data": json.dumps(rel_data.to_dict())}, rel_id=rel_id) + self.put_in_rel( + data={"error_data": json.dumps(rel_data.to_dict(), sort_keys=True)}, rel_id=rel_id + ) return True @@ -292,7 +298,11 @@ def _put_planned_units(self, app: str, count: int, target_relation_ids: List[int for rel_id in target_relation_ids: self.put_in_rel( - data={"cluster_fleet_planned_units": json.dumps(cluster_fleet_planned_units)}, + data={ + "cluster_fleet_planned_units": json.dumps( + cluster_fleet_planned_units, sort_keys=True + ) + }, rel_id=rel_id, ) @@ -519,7 +529,7 @@ def _put_planned_units(self, event: RelationEvent): """Report self planned units and store the fleet's on the peer data bag.""" # register the number of planned units in the current app, to notify the orchestrators self.put_in_rel( - data={"planned_units": json.dumps(self.charm.app.planned_units())}, + data={"planned_units": json.dumps(self.charm.app.planned_units(), sort_keys=True)}, rel_id=event.relation.id, ) @@ -606,7 +616,8 @@ def _on_peer_cluster_relation_departed(self, event: RelationDepartedEvent): rel_orchestrators.promote_failover() self.put_in_rel( - data={"orchestrators": json.dumps(rel_orchestrators.to_dict())}, rel_id=rel_id + data={"orchestrators": json.dumps(rel_orchestrators.to_dict(), sort_keys=True)}, + rel_id=rel_id, ) def _promote_failover(self, orchestrators: PeerClusterOrchestrators, cms: List[Node]) -> None: