mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
backups: Rename repo_path to borg_path for clarity
borg_path clearly signifies that it is to be used by borg and consumers of the class will not be confused by it. Also rename some repo_path variables in test cases. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
5865fbea26
commit
d05bbab751
@ -126,7 +126,7 @@ class BaseBorgRepository(abc.ABC):
|
||||
return True
|
||||
|
||||
@property
|
||||
def repo_path(self):
|
||||
def borg_path(self):
|
||||
"""Return the repository that the backups action script should use."""
|
||||
return self._path
|
||||
|
||||
@ -149,7 +149,7 @@ class BaseBorgRepository(abc.ABC):
|
||||
|
||||
def get_info(self):
|
||||
"""Return Borg information about a repository."""
|
||||
output = self.run(['info', '--path', self.repo_path])
|
||||
output = self.run(['info', '--path', self.borg_path])
|
||||
return json.loads(output)
|
||||
|
||||
def get_view_content(self):
|
||||
@ -174,7 +174,7 @@ class BaseBorgRepository(abc.ABC):
|
||||
"""Remove a borg repository"""
|
||||
|
||||
def list_archives(self):
|
||||
output = self.run(['list-repo', '--path', self.repo_path])
|
||||
output = self.run(['list-repo', '--path', self.borg_path])
|
||||
archives = json.loads(output)['archives']
|
||||
return sorted(archives, key=lambda archive: archive['start'],
|
||||
reverse=True)
|
||||
@ -194,7 +194,7 @@ class BaseBorgRepository(abc.ABC):
|
||||
if encryption not in SUPPORTED_BORG_ENCRYPTION:
|
||||
raise ValueError('Unsupported encryption: %s' % encryption)
|
||||
self.run(
|
||||
['init', '--path', self.repo_path, '--encryption', encryption])
|
||||
['init', '--path', self.borg_path, '--encryption', encryption])
|
||||
|
||||
def _run(self, cmd, arguments, superuser=True, **kwargs):
|
||||
"""Run a backups or sshfs action script command."""
|
||||
@ -250,7 +250,7 @@ class BaseBorgRepository(abc.ABC):
|
||||
|
||||
def _get_archive_path(self, archive_name):
|
||||
"""Return full borg path for an archive."""
|
||||
return '::'.join([self.repo_path, archive_name])
|
||||
return '::'.join([self.borg_path, archive_name])
|
||||
|
||||
@staticmethod
|
||||
def reraise_known_error(err):
|
||||
@ -311,7 +311,7 @@ class RootBorgRepository(BaseBorgRepository):
|
||||
"""Borg repository on the root filesystem."""
|
||||
storage_type = 'root'
|
||||
name = ROOT_REPOSITORY_NAME
|
||||
repo_path = ROOT_REPOSITORY
|
||||
borg_path = ROOT_REPOSITORY
|
||||
sort_order = 10
|
||||
is_mounted = True
|
||||
|
||||
@ -361,14 +361,13 @@ class SshBorgRepository(BaseBorgRepository):
|
||||
return self.kwargs.get('verified')
|
||||
|
||||
@property
|
||||
def repo_path(self):
|
||||
"""
|
||||
Return the path to use for backups actions.
|
||||
def borg_path(self):
|
||||
"""Return the path to use for backups actions.
|
||||
|
||||
This is the mount point for the remote SSH repositories.
|
||||
|
||||
This could either be the mountpoint or the remote ssh path,
|
||||
depending on whether borg is running on the remote server.
|
||||
"""
|
||||
return self.mountpoint
|
||||
return self._mountpoint
|
||||
|
||||
@property
|
||||
def mountpoint(self):
|
||||
|
||||
@ -87,8 +87,8 @@ def test_empty_dir(backup_directory):
|
||||
|
||||
def test_create_unencrypted_repository(backup_directory):
|
||||
"""Test creating an unencrypted repository."""
|
||||
repo_path = backup_directory / 'borgbackup'
|
||||
repository = BorgRepository(str(repo_path))
|
||||
path = backup_directory / 'borgbackup'
|
||||
repository = BorgRepository(str(path))
|
||||
repository.create_repository()
|
||||
info = repository.get_info()
|
||||
assert 'encryption' in info
|
||||
@ -103,11 +103,11 @@ def test_create_export_delete_archive(data_directory, backup_directory):
|
||||
"""
|
||||
repo_name = 'test_create_and_delete'
|
||||
archive_name = 'first_archive'
|
||||
repo_path = backup_directory / repo_name
|
||||
path = backup_directory / repo_name
|
||||
|
||||
repository = BorgRepository(str(repo_path))
|
||||
repository = BorgRepository(str(path))
|
||||
repository.create_repository()
|
||||
archive_path = "::".join([str(repo_path), archive_name])
|
||||
archive_path = "::".join([str(path), archive_name])
|
||||
actions.superuser_run('backups', [
|
||||
'create-archive', '--path', archive_path, '--paths',
|
||||
str(data_directory)
|
||||
@ -129,12 +129,12 @@ def test_remote_backup_actions():
|
||||
This relies on borgbackups being installed on the remote machine.
|
||||
"""
|
||||
credentials = _get_credentials(add_encryption_passphrase=True)
|
||||
repo_path = os.path.join(test_config.backups_ssh_path, str(uuid.uuid1()))
|
||||
arguments = ['init', '--path', repo_path, '--encryption', 'repokey']
|
||||
path = os.path.join(test_config.backups_ssh_path, str(uuid.uuid1()))
|
||||
arguments = ['init', '--path', path, '--encryption', 'repokey']
|
||||
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
||||
actions.superuser_run('backups', arguments, **kwargs)
|
||||
|
||||
arguments = ['info', '--path', repo_path]
|
||||
arguments = ['info', '--path', path]
|
||||
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
||||
info = actions.superuser_run('backups', arguments, **kwargs)
|
||||
info = json.loads(info)
|
||||
|
||||
@ -92,25 +92,25 @@ def test_user_setup(temp_home, temp_user):
|
||||
@pytest.mark.skip
|
||||
def test_add_repository_when_directory_is_missing(temp_user, temp_home,
|
||||
password):
|
||||
repo_path = os.path.join(temp_home, 'non_existent_dir')
|
||||
remote_path = os.path.join(temp_home, 'non_existent_dir')
|
||||
data = {
|
||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
||||
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||
'ssh_password': password,
|
||||
'encryption': 'none'
|
||||
}
|
||||
# TODO test the view instead of the form
|
||||
form = forms.AddRemoteRepositoryForm(data=data)
|
||||
form.is_valid()
|
||||
assert os.path.isdir(repo_path) # Directory gets created
|
||||
assert os.path.isdir(remote_path) # Directory gets created
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_add_repository_when_directory_exists_and_empty(
|
||||
temp_user, temp_home, password):
|
||||
repo_path = os.path.join(temp_home, 'empty_dir')
|
||||
os.makedirs(repo_path)
|
||||
remote_path = os.path.join(temp_home, 'empty_dir')
|
||||
os.makedirs(remote_path)
|
||||
data = {
|
||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
||||
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||
'ssh_password': password,
|
||||
'encryption': 'none'
|
||||
}
|
||||
@ -123,11 +123,11 @@ def test_add_repository_when_directory_exists_and_empty(
|
||||
@pytest.mark.skip
|
||||
def test_add_repository_when_directory_exists_and_not_empty(
|
||||
temp_user, temp_home, password):
|
||||
repo_path = os.path.join(temp_home, 'non_empty_dir')
|
||||
os.makedirs(repo_path)
|
||||
open(os.path.join(repo_path, 'somefile.txt'), 'w').close()
|
||||
remote_path = os.path.join(temp_home, 'non_empty_dir')
|
||||
os.makedirs(remote_path)
|
||||
open(os.path.join(remote_path, 'somefile.txt'), 'w').close()
|
||||
data = {
|
||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
||||
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||
'ssh_password': password,
|
||||
'encryption': 'none'
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user