refactor(backups): make a dedicated get_folders() function

This commit is contained in:
Houkime 2023-04-14 10:32:14 +00:00 committed by Inex Code
parent 170cf1923e
commit 69f63f04eb
4 changed files with 16 additions and 6 deletions

View file

@ -194,7 +194,7 @@ class Backups:
@staticmethod @staticmethod
def back_up(service: Service): def back_up(service: Service):
"""The top-level function to back up a service""" """The top-level function to back up a service"""
folder = service.get_drive() folder = service.get_folders()
repo_name = service.get_id() repo_name = service.get_id()
service.pre_backup() service.pre_backup()
@ -238,7 +238,7 @@ class Backups:
@staticmethod @staticmethod
def restore_service_from_snapshot(service: Service, snapshot_id: str): def restore_service_from_snapshot(service: Service, snapshot_id: str):
repo_name = service.get_id() repo_name = service.get_id()
folder = service.get_drive() folder = service.get_folders()
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder) Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder)

View file

@ -135,6 +135,11 @@ class Service(ABC):
def get_drive() -> str: def get_drive() -> str:
pass pass
# @staticmethod
# @abstractmethod
# def get_folders() -> str:
# pass
@abstractmethod @abstractmethod
def move_to_volume(self, volume: BlockDevice) -> Job: def move_to_volume(self, volume: BlockDevice) -> Job:
pass pass

View file

@ -106,8 +106,13 @@ class DummyService(Service):
storage_usage = 0 storage_usage = 0
return storage_usage return storage_usage
@classmethod @staticmethod
def get_drive(cls) -> str: def get_drive(cls) -> str:
return "sda1"
@classmethod
def get_folders(cls) -> str:
# for now only a single folder
return cls.location return cls.location
@staticmethod @staticmethod

View file

@ -44,7 +44,7 @@ def raw_dummy_service(tmpdir, backups):
with open(testfile_path, "w") as file: with open(testfile_path, "w") as file:
file.write(TESTFILE_BODY) file.write(TESTFILE_BODY)
# we need this to not change get_drive() much # we need this to not change get_folders() much
class TestDummyService(DummyService, location=service_dir): class TestDummyService(DummyService, location=service_dir):
pass pass
@ -143,7 +143,7 @@ def test_one_snapshot(backups, dummy_service):
def test_backup_returns_snapshot(backups, dummy_service): def test_backup_returns_snapshot(backups, dummy_service):
service_folder = dummy_service.get_drive() service_folder = dummy_service.get_folders()
provider = Backups.provider() provider = Backups.provider()
name = dummy_service.get_id() name = dummy_service.get_id()
snapshot = provider.backuper.start_backup(service_folder, name) snapshot = provider.backuper.start_backup(service_folder, name)
@ -154,7 +154,7 @@ def test_backup_returns_snapshot(backups, dummy_service):
def test_restore(backups, dummy_service): def test_restore(backups, dummy_service):
service_folder = dummy_service.get_drive() service_folder = dummy_service.get_folders()
file_to_nuke = listdir(service_folder)[0] file_to_nuke = listdir(service_folder)[0]
assert file_to_nuke is not None assert file_to_nuke is not None
path_to_nuke = path.join(service_folder, file_to_nuke) path_to_nuke = path.join(service_folder, file_to_nuke)