Skip to content

Commit

Permalink
Report WaitingStatus for relations that have not requested user & d…
Browse files Browse the repository at this point in the history
…atabase (#48)

Previously, `WaitingStatus` was only reported if no other
database_provides relations were active. However, if a relation is
established but we're waiting for data, it makes more sense to set
`WaitingStatus` instead of `ActiveStatus`, even though the charm is
active on one relation
  • Loading branch information
carlcsaposs-canonical committed Jun 30, 2023
1 parent af2bd8d commit 849b00b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/relations/database_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ def delete_all_databags(self) -> None:
def get_status(self, event) -> typing.Optional[ops.StatusBase]:
"""Report non-active status."""
requested_users = []
exception_reporting_priority = (
_UnsupportedExtraUserRole,
remote_databag.IncompleteDatabag,
)
# TODO python3.10 min version: Use `list` instead of `typing.List`
exceptions: typing.List[status_exception.StatusException] = []
for relation in self._interface.relations:
Expand All @@ -247,16 +251,11 @@ def get_status(self, event) -> typing.Optional[ops.StatusBase]:
)
except _RelationBreaking:
pass
except (remote_databag.IncompleteDatabag, _UnsupportedExtraUserRole) as exception:
except exception_reporting_priority as exception:
exceptions.append(exception)
# Always report unsupported extra user role
for exception in exceptions:
if isinstance(exception, _UnsupportedExtraUserRole):
return exception.status
if requested_users:
# At least one relation is active—do not report about inactive relations
return
for exception in exceptions:
if isinstance(exception, remote_databag.IncompleteDatabag):
return exception.status
return ops.BlockedStatus(f"Missing relation: {self._NAME}")
for exception_type in exception_reporting_priority:
for exception in exceptions:
if isinstance(exception, exception_type):
return exception.status
if not requested_users:
return ops.BlockedStatus(f"Missing relation: {self._NAME}")

0 comments on commit 849b00b

Please sign in to comment.