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

View file

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

View file

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

View file

@ -44,7 +44,7 @@ def raw_dummy_service(tmpdir, backups):
with open(testfile_path, "w") as file:
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):
pass
@ -143,7 +143,7 @@ def test_one_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()
name = dummy_service.get_id()
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):
service_folder = dummy_service.get_drive()
service_folder = dummy_service.get_folders()
file_to_nuke = listdir(service_folder)[0]
assert file_to_nuke is not None
path_to_nuke = path.join(service_folder, file_to_nuke)