Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zvirovyi committed Jun 18, 2024
1 parent 3601f82 commit 4663afc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
33 changes: 15 additions & 18 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,24 +798,23 @@ def _on_restore_action(self, event):
f" has been requested on the unit"
)

if backup_id:
# Validate the provided backup id.
logger.info("Validating provided backup-id")
try:
backups = self._list_backups(show_failed=False)
if backup_id not in backups.keys():
error_message = f"Invalid backup-id: {backup_id}"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return
except ListBackupsError as e:
logger.exception(e)
error_message = "Failed to retrieve backup id"
# Validate the provided backup id and restore to time.
logger.info("Validating provided backup-id and restore-to-time")
try:
backups = self._list_backups(show_failed=False)
if backup_id and backup_id not in backups.keys():
error_message = f"Invalid backup-id: {backup_id}"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return
elif not self._list_backups(show_failed=False):
error_message = "Cannot restore PITR without any backups created"
if not backup_id and restore_to_time and not backups:
error_message = "Cannot restore PITR without any backups created"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return
except ListBackupsError as e:
logger.exception(e)
error_message = "Failed to retrieve backups list"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return
Expand Down Expand Up @@ -863,9 +862,7 @@ def _on_restore_action(self, event):
# Mark the cluster as in a restoring backup state and update the Patroni configuration.
logger.info("Configuring Patroni to restore the backup")
self.charm.app_peer_data.update({
"restoring-backup": self._fetch_backup_from_id(backup_id)
if backup_id
else "",
"restoring-backup": self._fetch_backup_from_id(backup_id) if backup_id else "",
"restore-stanza": backups[backup_id]
if backup_id
else self.charm.app_peer_data.get("stanza", self.stanza_name),
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ async def test_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict], charm
# Wait for the restore to complete.
async with ops_test.fast_forward():
await ops_test.model.block_until(
lambda: remaining_unit.workload_status_message == MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET,
lambda: remaining_unit.workload_status_message
== MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET,
timeout=1000,
)

Expand Down

0 comments on commit 4663afc

Please sign in to comment.