Skip to content

Commit a723606

Browse files
[DPE-10625] select valid backup entry in restore integration test (#1840)
test_restore_on_new_cluster selected a backup ID from the list-backups output by positional index (backups.split("\n")[-3]), assuming the last two entries are always restore/timeline records. When the output contains a different number of such entries, the selected line is itself a timeline entry, which fails with "Cannot restore to the timeline without restore-to-time parameter". Parse the pipe-delimited output instead and select only lines whose action column contains "backup" (full/differential/incremental), and include action.results in the restore assertion message. Backport of canonical/postgresql-k8s-operator#1552. Assisted-by: Claude:claude-5-fable
1 parent 9b17fd3 commit a723606

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tests/integration/test_backups_gcp.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,28 @@ async def test_restore_on_new_cluster(
131131
):
132132
with attempt:
133133
logger.info("restoring the backup")
134-
# Last two entries are 'action: restore', that cannot be used without restore-to-time parameter
135-
most_recent_real_backup = backups.split("\n")[-3]
136-
backup_id = most_recent_real_backup.split()[0]
134+
# The list-backups output contains real backup entries (action = "full backup",
135+
# "differential backup", "incremental backup") as well as restore/timeline entries
136+
# (action = "restore") that cannot be used without the restore-to-time parameter.
137+
# Select only lines where the action column contains "backup" to avoid picking
138+
# a timeline entry that would cause: "Cannot restore to the timeline without
139+
# restore-to-time parameter".
140+
real_backup_lines = [
141+
line
142+
for line in backups.splitlines()
143+
for parts in [line.split("|")]
144+
if len(parts) > 1 and "backup" in parts[1].lower()
145+
]
146+
assert real_backup_lines, (
147+
f"No valid backup entry found in list-backups output:\n{backups}"
148+
)
149+
backup_id = real_backup_lines[-1].split()[0]
137150
action = await ops_test.model.units.get(unit_name).run_action(
138151
"restore", **{"backup-id": backup_id}
139152
)
140153
await action.wait()
141154
restore_status = action.results.get("restore-status")
142-
assert restore_status, "restore hasn't succeeded"
155+
assert restore_status, f"restore hasn't succeeded: {action.results}"
143156

144157
# Wait for the restore to complete.
145158
async with ops_test.fast_forward():

0 commit comments

Comments
 (0)