diff --git a/src/backups.py b/src/backups.py index c798e930be..2bdc776374 100644 --- a/src/backups.py +++ b/src/backups.py @@ -187,7 +187,10 @@ def can_use_s3_repository(self) -> tuple[bool, str | None]: for line in system_identifier_from_instance.splitlines() if "Database system identifier" in line ).split(" ")[-1] - system_identifier_from_stanza = str(stanza.get("db")[0]["system-id"]) + stanza_dbs = stanza.get("db") + system_identifier_from_stanza = ( + str(stanza_dbs[0]["system-id"]) if len(stanza_dbs) else None + ) if system_identifier_from_instance != system_identifier_from_stanza: logger.debug( f"can_use_s3_repository: incompatible system identifier s3={system_identifier_from_stanza}, local={system_identifier_from_instance}" diff --git a/tests/unit/test_backups.py b/tests/unit/test_backups.py index 33c4bb81be..f2fd77dfb4 100644 --- a/tests/unit/test_backups.py +++ b/tests/unit/test_backups.py @@ -288,6 +288,18 @@ def test_can_use_s3_repository(harness): ] assert harness.charm.backup.can_use_s3_repository() == (True, None) + # Empty db + _execute_command.side_effect = [ + ( + f'[{{"db": [], "name": "another-model.{harness.charm.cluster_name}"}}]', + None, + ) + ] + assert harness.charm.backup.can_use_s3_repository() == ( + False, + ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE, + ) + def test_construct_endpoint(harness): # Test with an AWS endpoint without region.