Skip to content

Commit

Permalink
move peer app databag to property
Browse files Browse the repository at this point in the history
peer relation not available in install event
  • Loading branch information
carlcsaposs-canonical committed Jun 29, 2023
1 parent 74e24f6 commit 6a8e044
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/relations/deprecated_shared_db_database_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ def __init__(self, charm_: "abstract_charm.MySQLRouterCharm") -> None:
logger.warning(
"'mysql-shared' relation interface is DEPRECATED and will be removed in a future release. Use 'mysql_client' interface instead."
)
self._unit = charm_.unit
self._peer_app_databag = charm_.model.get_relation(
self._CREDENTIALS_PEER_RELATION_ENDPOINT_NAME
).data[charm_.app]
charm_.framework.observe(
charm_.on[self._NAME].relation_changed,
charm_.reconcile_database_relations,
Expand All @@ -178,6 +174,13 @@ def __init__(self, charm_: "abstract_charm.MySQLRouterCharm") -> None:
charm_.on[self._CREDENTIALS_PEER_RELATION_ENDPOINT_NAME].relation_changed,
self._update_unit_databag,
)
self._charm = charm_

@property
def _peer_app_databag(self) -> ops.RelationDataContent:
return self._charm.model.get_relation(self._CREDENTIALS_PEER_RELATION_ENDPOINT_NAME).data[
self._charm.app
]

def _update_unit_databag(self, event: ops.RelationChangedEvent) -> None:
"""Synchronize shared-db unit databag with peer app databag.
Expand All @@ -196,7 +199,7 @@ def _update_unit_databag(self, event: ops.RelationChangedEvent) -> None:
requested_users.append(
_RelationThatRequestedUser(
relation=relation,
unit=self._unit,
unit=self._charm.unit,
peer_relation_app_databag=self._peer_app_databag,
event=event,
)
Expand All @@ -221,7 +224,7 @@ def _created_users(self) -> typing.List[_RelationWithCreatedUser]:
created_users.append(
_RelationWithCreatedUser(
relation=relation,
unit=self._unit,
unit=self._charm.unit,
peer_relation_app_databag=self._peer_app_databag,
)
)
Expand All @@ -248,7 +251,7 @@ def reconcile_users(
requested_users.append(
_RelationThatRequestedUser(
relation=relation,
unit=self._unit,
unit=self._charm.unit,
peer_relation_app_databag=self._peer_app_databag,
event=event,
)
Expand Down Expand Up @@ -294,7 +297,7 @@ def get_status(self, event) -> typing.Optional[ops.StatusBase]:
requested_users.append(
_RelationThatRequestedUser(
relation=relation,
unit=self._unit,
unit=self._charm.unit,
peer_relation_app_databag=self._peer_app_databag,
event=event,
)
Expand Down

0 comments on commit 6a8e044

Please sign in to comment.