Skip to content

Commit

Permalink
Handle Secret permission error (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp authored Sep 4, 2024
1 parent 5001b09 commit ff5d1bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/relations/backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,16 @@ def ready(self) -> bool:
logger.debug("Backend not ready: no connection info")
return False

if (
not (auth_file := self.charm.get_secret(APP_SCOPE, AUTH_FILE_DATABAG_KEY))
or not self.auth_user
or self.auth_user not in auth_file
):
logger.debug("Backend not ready: no auth file secret set")
try:
if (
not (auth_file := self.charm.get_secret(APP_SCOPE, AUTH_FILE_DATABAG_KEY))
or not self.auth_user
or self.auth_user not in auth_file
):
logger.debug("Backend not ready: no auth file secret set")
return False
except ModelError:
logger.debug("Backend not ready: Unable to get secret")
return False

# Check we can actually connect to backend database by running a command.
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def test_pre_upgrade_check_not_ready(self, _check_pgb_running: Mock):
@patch("charm.BackendDatabaseRequires.ready", return_value=False, new_callable=PropertyMock)
@patch("charm.PgBouncerCharm.check_pgb_running", return_value=True)
def test_pre_upgrade_check_backend_not_ready(self, _check_pgb_running: Mock, _, __):
print(self.charm.backend.ready)
with pytest.raises(ClusterNotReadyError):
self.charm.upgrade.pre_upgrade_check()

Expand Down

0 comments on commit ff5d1bf

Please sign in to comment.