mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +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
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repo_path(self):
|
def borg_path(self):
|
||||||
"""Return the repository that the backups action script should use."""
|
"""Return the repository that the backups action script should use."""
|
||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class BaseBorgRepository(abc.ABC):
|
|||||||
|
|
||||||
def get_info(self):
|
def get_info(self):
|
||||||
"""Return Borg information about a repository."""
|
"""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)
|
return json.loads(output)
|
||||||
|
|
||||||
def get_view_content(self):
|
def get_view_content(self):
|
||||||
@ -174,7 +174,7 @@ class BaseBorgRepository(abc.ABC):
|
|||||||
"""Remove a borg repository"""
|
"""Remove a borg repository"""
|
||||||
|
|
||||||
def list_archives(self):
|
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']
|
archives = json.loads(output)['archives']
|
||||||
return sorted(archives, key=lambda archive: archive['start'],
|
return sorted(archives, key=lambda archive: archive['start'],
|
||||||
reverse=True)
|
reverse=True)
|
||||||
@ -194,7 +194,7 @@ class BaseBorgRepository(abc.ABC):
|
|||||||
if encryption not in SUPPORTED_BORG_ENCRYPTION:
|
if encryption not in SUPPORTED_BORG_ENCRYPTION:
|
||||||
raise ValueError('Unsupported encryption: %s' % encryption)
|
raise ValueError('Unsupported encryption: %s' % encryption)
|
||||||
self.run(
|
self.run(
|
||||||
['init', '--path', self.repo_path, '--encryption', encryption])
|
['init', '--path', self.borg_path, '--encryption', encryption])
|
||||||
|
|
||||||
def _run(self, cmd, arguments, superuser=True, **kwargs):
|
def _run(self, cmd, arguments, superuser=True, **kwargs):
|
||||||
"""Run a backups or sshfs action script command."""
|
"""Run a backups or sshfs action script command."""
|
||||||
@ -250,7 +250,7 @@ class BaseBorgRepository(abc.ABC):
|
|||||||
|
|
||||||
def _get_archive_path(self, archive_name):
|
def _get_archive_path(self, archive_name):
|
||||||
"""Return full borg path for an archive."""
|
"""Return full borg path for an archive."""
|
||||||
return '::'.join([self.repo_path, archive_name])
|
return '::'.join([self.borg_path, archive_name])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reraise_known_error(err):
|
def reraise_known_error(err):
|
||||||
@ -311,7 +311,7 @@ class RootBorgRepository(BaseBorgRepository):
|
|||||||
"""Borg repository on the root filesystem."""
|
"""Borg repository on the root filesystem."""
|
||||||
storage_type = 'root'
|
storage_type = 'root'
|
||||||
name = ROOT_REPOSITORY_NAME
|
name = ROOT_REPOSITORY_NAME
|
||||||
repo_path = ROOT_REPOSITORY
|
borg_path = ROOT_REPOSITORY
|
||||||
sort_order = 10
|
sort_order = 10
|
||||||
is_mounted = True
|
is_mounted = True
|
||||||
|
|
||||||
@ -361,14 +361,13 @@ class SshBorgRepository(BaseBorgRepository):
|
|||||||
return self.kwargs.get('verified')
|
return self.kwargs.get('verified')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repo_path(self):
|
def borg_path(self):
|
||||||
"""
|
"""Return the path to use for backups actions.
|
||||||
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
|
@property
|
||||||
def mountpoint(self):
|
def mountpoint(self):
|
||||||
|
|||||||
@ -87,8 +87,8 @@ def test_empty_dir(backup_directory):
|
|||||||
|
|
||||||
def test_create_unencrypted_repository(backup_directory):
|
def test_create_unencrypted_repository(backup_directory):
|
||||||
"""Test creating an unencrypted repository."""
|
"""Test creating an unencrypted repository."""
|
||||||
repo_path = backup_directory / 'borgbackup'
|
path = backup_directory / 'borgbackup'
|
||||||
repository = BorgRepository(str(repo_path))
|
repository = BorgRepository(str(path))
|
||||||
repository.create_repository()
|
repository.create_repository()
|
||||||
info = repository.get_info()
|
info = repository.get_info()
|
||||||
assert 'encryption' in 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'
|
repo_name = 'test_create_and_delete'
|
||||||
archive_name = 'first_archive'
|
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()
|
repository.create_repository()
|
||||||
archive_path = "::".join([str(repo_path), archive_name])
|
archive_path = "::".join([str(path), archive_name])
|
||||||
actions.superuser_run('backups', [
|
actions.superuser_run('backups', [
|
||||||
'create-archive', '--path', archive_path, '--paths',
|
'create-archive', '--path', archive_path, '--paths',
|
||||||
str(data_directory)
|
str(data_directory)
|
||||||
@ -129,12 +129,12 @@ def test_remote_backup_actions():
|
|||||||
This relies on borgbackups being installed on the remote machine.
|
This relies on borgbackups being installed on the remote machine.
|
||||||
"""
|
"""
|
||||||
credentials = _get_credentials(add_encryption_passphrase=True)
|
credentials = _get_credentials(add_encryption_passphrase=True)
|
||||||
repo_path = os.path.join(test_config.backups_ssh_path, str(uuid.uuid1()))
|
path = os.path.join(test_config.backups_ssh_path, str(uuid.uuid1()))
|
||||||
arguments = ['init', '--path', repo_path, '--encryption', 'repokey']
|
arguments = ['init', '--path', path, '--encryption', 'repokey']
|
||||||
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
||||||
actions.superuser_run('backups', arguments, **kwargs)
|
actions.superuser_run('backups', arguments, **kwargs)
|
||||||
|
|
||||||
arguments = ['info', '--path', repo_path]
|
arguments = ['info', '--path', path]
|
||||||
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
arguments, kwargs = _append_borg_arguments(arguments, credentials)
|
||||||
info = actions.superuser_run('backups', arguments, **kwargs)
|
info = actions.superuser_run('backups', arguments, **kwargs)
|
||||||
info = json.loads(info)
|
info = json.loads(info)
|
||||||
|
|||||||
@ -92,25 +92,25 @@ def test_user_setup(temp_home, temp_user):
|
|||||||
@pytest.mark.skip
|
@pytest.mark.skip
|
||||||
def test_add_repository_when_directory_is_missing(temp_user, temp_home,
|
def test_add_repository_when_directory_is_missing(temp_user, temp_home,
|
||||||
password):
|
password):
|
||||||
repo_path = os.path.join(temp_home, 'non_existent_dir')
|
remote_path = os.path.join(temp_home, 'non_existent_dir')
|
||||||
data = {
|
data = {
|
||||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||||
'ssh_password': password,
|
'ssh_password': password,
|
||||||
'encryption': 'none'
|
'encryption': 'none'
|
||||||
}
|
}
|
||||||
# TODO test the view instead of the form
|
# TODO test the view instead of the form
|
||||||
form = forms.AddRemoteRepositoryForm(data=data)
|
form = forms.AddRemoteRepositoryForm(data=data)
|
||||||
form.is_valid()
|
form.is_valid()
|
||||||
assert os.path.isdir(repo_path) # Directory gets created
|
assert os.path.isdir(remote_path) # Directory gets created
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip
|
@pytest.mark.skip
|
||||||
def test_add_repository_when_directory_exists_and_empty(
|
def test_add_repository_when_directory_exists_and_empty(
|
||||||
temp_user, temp_home, password):
|
temp_user, temp_home, password):
|
||||||
repo_path = os.path.join(temp_home, 'empty_dir')
|
remote_path = os.path.join(temp_home, 'empty_dir')
|
||||||
os.makedirs(repo_path)
|
os.makedirs(remote_path)
|
||||||
data = {
|
data = {
|
||||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||||
'ssh_password': password,
|
'ssh_password': password,
|
||||||
'encryption': 'none'
|
'encryption': 'none'
|
||||||
}
|
}
|
||||||
@ -123,11 +123,11 @@ def test_add_repository_when_directory_exists_and_empty(
|
|||||||
@pytest.mark.skip
|
@pytest.mark.skip
|
||||||
def test_add_repository_when_directory_exists_and_not_empty(
|
def test_add_repository_when_directory_exists_and_not_empty(
|
||||||
temp_user, temp_home, password):
|
temp_user, temp_home, password):
|
||||||
repo_path = os.path.join(temp_home, 'non_empty_dir')
|
remote_path = os.path.join(temp_home, 'non_empty_dir')
|
||||||
os.makedirs(repo_path)
|
os.makedirs(remote_path)
|
||||||
open(os.path.join(repo_path, 'somefile.txt'), 'w').close()
|
open(os.path.join(remote_path, 'somefile.txt'), 'w').close()
|
||||||
data = {
|
data = {
|
||||||
'repository': f'{temp_user}@localhost:{repo_path}',
|
'repository': f'{temp_user}@localhost:{remote_path}',
|
||||||
'ssh_password': password,
|
'ssh_password': password,
|
||||||
'encryption': 'none'
|
'encryption': 'none'
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user