Skip to content

Commit e92b56a

Browse files
authored
Handle missing stanza output (#866)
1 parent cada525 commit e92b56a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/backups.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ def can_use_s3_repository(self) -> tuple[bool, str | None]:
187187
for line in system_identifier_from_instance.splitlines()
188188
if "Database system identifier" in line
189189
).split(" ")[-1]
190-
system_identifier_from_stanza = str(stanza.get("db")[0]["system-id"])
190+
stanza_dbs = stanza.get("db")
191+
system_identifier_from_stanza = (
192+
str(stanza_dbs[0]["system-id"]) if len(stanza_dbs) else None
193+
)
191194
if system_identifier_from_instance != system_identifier_from_stanza:
192195
logger.debug(
193196
f"can_use_s3_repository: incompatible system identifier s3={system_identifier_from_stanza}, local={system_identifier_from_instance}"

tests/unit/test_backups.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ def test_can_use_s3_repository(harness):
288288
]
289289
assert harness.charm.backup.can_use_s3_repository() == (True, None)
290290

291+
# Empty db
292+
_execute_command.side_effect = [
293+
(
294+
f'[{{"db": [], "name": "another-model.{harness.charm.cluster_name}"}}]',
295+
None,
296+
)
297+
]
298+
assert harness.charm.backup.can_use_s3_repository() == (
299+
False,
300+
ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE,
301+
)
302+
291303

292304
def test_construct_endpoint(harness):
293305
# Test with an AWS endpoint without region.

0 commit comments

Comments
 (0)