mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 04:01:27 +00:00
fix(backup): early abort and better error reporting for restore_all
This commit is contained in:
parent
2ad518499e
commit
5850c05bd1
|
@ -220,6 +220,7 @@ def do_full_restore(job: Job) -> None:
|
||||||
Backups.restore_snapshot(snap)
|
Backups.restore_snapshot(snap)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
report_job_error(error, job)
|
report_job_error(error, job)
|
||||||
|
return
|
||||||
progress = progress + progress_per_service
|
progress = progress + progress_per_service
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job,
|
job,
|
||||||
|
|
|
@ -186,11 +186,11 @@ def get_testfile_bodies(service: DummyService):
|
||||||
return bodies
|
return bodies
|
||||||
|
|
||||||
|
|
||||||
def is_original_files(service: DummyService):
|
def assert_original_files(service: DummyService):
|
||||||
# For use in restoration tests mostly
|
# For use in restoration tests mostly
|
||||||
|
|
||||||
paths = testfile_paths(service.get_folders())
|
paths = testfile_paths(service.get_folders())
|
||||||
return get_testfile_bodies(service) == {
|
assert get_testfile_bodies(service) == {
|
||||||
paths[0]: TESTFILE_BODY,
|
paths[0]: TESTFILE_BODY,
|
||||||
paths[1]: TESTFILE2_BODY,
|
paths[1]: TESTFILE2_BODY,
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ def raw_dummy_service(tmpdir) -> DummyService:
|
||||||
service = TestDummyService()
|
service = TestDummyService()
|
||||||
write_testfile_bodies(service, bodies)
|
write_testfile_bodies(service, bodies)
|
||||||
|
|
||||||
assert is_original_files(service)
|
assert_original_files(service)
|
||||||
|
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ def catch_nixos_rebuild_calls(fp):
|
||||||
return fp
|
return fp
|
||||||
|
|
||||||
|
|
||||||
def assert_rebuild_was_made(fp, unit_name):
|
def assert_rebuild_was_made(fp):
|
||||||
# You call it after you have done the operation that
|
# You call it after you have done the operation that
|
||||||
# calls a rebuild
|
# calls a rebuild
|
||||||
assert_rebuild_or_upgrade_was_made(fp, API_REBUILD_SYSTEM_UNIT)
|
assert_rebuild_or_upgrade_was_made(fp, API_REBUILD_SYSTEM_UNIT)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path as path
|
import os.path as path
|
||||||
from os import remove
|
from os import remove
|
||||||
|
@ -11,7 +13,6 @@ import tempfile
|
||||||
|
|
||||||
from selfprivacy_api.utils.huey import huey
|
from selfprivacy_api.utils.huey import huey
|
||||||
|
|
||||||
|
|
||||||
from selfprivacy_api.services.service import ServiceStatus
|
from selfprivacy_api.services.service import ServiceStatus
|
||||||
from selfprivacy_api.services import ServiceManager
|
from selfprivacy_api.services import ServiceManager
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ from selfprivacy_api.backup.tasks import (
|
||||||
reload_snapshot_cache,
|
reload_snapshot_cache,
|
||||||
total_backup,
|
total_backup,
|
||||||
do_full_restore,
|
do_full_restore,
|
||||||
|
which_snapshots_to_full_restore,
|
||||||
)
|
)
|
||||||
from selfprivacy_api.backup.storage import Storage
|
from selfprivacy_api.backup.storage import Storage
|
||||||
from selfprivacy_api.backup.local_secret import LocalBackupSecret
|
from selfprivacy_api.backup.local_secret import LocalBackupSecret
|
||||||
|
@ -50,6 +52,12 @@ from selfprivacy_api.backup.jobs import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import assert_job_errored
|
from tests.common import assert_job_errored
|
||||||
|
from tests.conftest import (
|
||||||
|
write_testfile_bodies,
|
||||||
|
get_testfile_bodies,
|
||||||
|
assert_original_files,
|
||||||
|
assert_rebuild_was_made,
|
||||||
|
)
|
||||||
from tests.test_dkim import dkim_file
|
from tests.test_dkim import dkim_file
|
||||||
|
|
||||||
from tests.test_graphql.test_services import (
|
from tests.test_graphql.test_services import (
|
||||||
|
@ -119,6 +127,18 @@ def file_backup(tmpdir) -> AbstractBackupProvider:
|
||||||
return provider
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
def ids(snapshots: List[Snapshot]) -> List[str]:
|
||||||
|
return [snapshot.id for snapshot in snapshots]
|
||||||
|
|
||||||
|
|
||||||
|
def assert_job_ok(job: Job):
|
||||||
|
try:
|
||||||
|
assert job.status == JobStatus.FINISHED
|
||||||
|
# For easier debug
|
||||||
|
except AssertionError:
|
||||||
|
raise ValueError("Job errored out when it was not supposed to:", job.error)
|
||||||
|
|
||||||
|
|
||||||
def test_reset_sets_to_none1():
|
def test_reset_sets_to_none1():
|
||||||
Backups.reset()
|
Backups.reset()
|
||||||
provider = Backups.provider()
|
provider = Backups.provider()
|
||||||
|
@ -842,15 +862,27 @@ def test_backup_all_restore_all(
|
||||||
fp = catch_nixos_rebuild_calls
|
fp = catch_nixos_rebuild_calls
|
||||||
fp.pass_command(["restic", fp.any()])
|
fp.pass_command(["restic", fp.any()])
|
||||||
fp.keep_last_process(True)
|
fp.keep_last_process(True)
|
||||||
|
fp.pass_command(["rclone", fp.any()])
|
||||||
|
fp.keep_last_process(True)
|
||||||
|
fp.pass_command(["lsblk", fp.any()])
|
||||||
|
fp.keep_last_process(True)
|
||||||
|
|
||||||
|
assert len(Backups.get_all_snapshots()) == 0
|
||||||
|
|
||||||
backup_job = add_total_backup_job()
|
backup_job = add_total_backup_job()
|
||||||
total_backup(backup_job)
|
total_backup(backup_job)
|
||||||
assert len(Backups.get_all_snapshots()) == 2
|
assert len(Backups.get_all_snapshots()) == 2
|
||||||
|
|
||||||
|
assert set(ids(which_snapshots_to_full_restore())) == set(
|
||||||
|
ids(Backups.get_all_snapshots())
|
||||||
|
)
|
||||||
|
|
||||||
|
write_testfile_bodies(dummy_service, ["bogus", "bleeegh corruption ><"])
|
||||||
|
|
||||||
restore_job = add_total_restore_job()
|
restore_job = add_total_restore_job()
|
||||||
|
|
||||||
do_full_restore(restore_job)
|
do_full_restore(restore_job)
|
||||||
|
assert_job_ok(restore_job)
|
||||||
|
|
||||||
# TODO: maybe test integrity.
|
assert_rebuild_was_made(fp)
|
||||||
# since it is standard restore operations they would have failed if something went wrong
|
assert_original_files(dummy_service)
|
||||||
# however, one still needs to check that all of the required restores have even started
|
|
||||||
|
|
Loading…
Reference in a new issue