Skip to content

Commit

Permalink
Add sort_keys=True
Browse files Browse the repository at this point in the history
  • Loading branch information
phvalguima committed May 3, 2024
1 parent bb6aa21 commit aabc9de
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/charms/opensearch/v0/opensearch_relation_peer_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -249,15 +250,18 @@ 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):
self.delete_from_rel("error_data", rel_id=rel_id)

# 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:
Expand All @@ -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

Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit aabc9de

Please sign in to comment.