Add additional command-line flags to rcreate action (#557).
This commit is contained in:
parent
00255a2437
commit
43d711463c
5 changed files with 63 additions and 18 deletions
|
@ -16,9 +16,11 @@ def create_repository(
|
||||||
storage_config,
|
storage_config,
|
||||||
local_borg_version,
|
local_borg_version,
|
||||||
encryption_mode,
|
encryption_mode,
|
||||||
other_repo=None,
|
key_repository=None,
|
||||||
|
copy_crypt_key=False,
|
||||||
append_only=None,
|
append_only=None,
|
||||||
storage_quota=None,
|
storage_quota=None,
|
||||||
|
make_parent_dirs=False,
|
||||||
local_path='borg',
|
local_path='borg',
|
||||||
remote_path=None,
|
remote_path=None,
|
||||||
):
|
):
|
||||||
|
@ -53,9 +55,11 @@ def create_repository(
|
||||||
else ('init',)
|
else ('init',)
|
||||||
)
|
)
|
||||||
+ (('--encryption', encryption_mode) if encryption_mode else ())
|
+ (('--encryption', encryption_mode) if encryption_mode else ())
|
||||||
+ (('--other-repo', other_repo) if other_repo else ())
|
+ (('--other-repo', key_repository) if key_repository else ())
|
||||||
|
+ (('--copy-crypt-key',) if copy_crypt_key else ())
|
||||||
+ (('--append-only',) if append_only else ())
|
+ (('--append-only',) if append_only else ())
|
||||||
+ (('--storage-quota', storage_quota) if storage_quota else ())
|
+ (('--storage-quota', storage_quota) if storage_quota else ())
|
||||||
|
+ (('--make-parent-dirs',) if make_parent_dirs else ())
|
||||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||||
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
|
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
|
||||||
+ (('--remote-path', remote_path) if remote_path else ())
|
+ (('--remote-path', remote_path) if remote_path else ())
|
||||||
|
|
|
@ -18,6 +18,7 @@ SUBPARSER_ALIASES = {
|
||||||
'list': ['--list', '-l'],
|
'list': ['--list', '-l'],
|
||||||
'rinfo': [],
|
'rinfo': [],
|
||||||
'info': ['--info', '-i'],
|
'info': ['--info', '-i'],
|
||||||
|
'transfer': [],
|
||||||
'borg': [],
|
'borg': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,20 +241,26 @@ def make_parsers():
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
rcreate_group.add_argument(
|
rcreate_group.add_argument(
|
||||||
|
'--key-repository',
|
||||||
'--other-repo',
|
'--other-repo',
|
||||||
metavar='SOURCE_REPOSITORY',
|
metavar='SOURCE_REPOSITORY',
|
||||||
help='Path to an existing Borg repository whose key material should be reused (Borg 2.x+ only)',
|
help='Path to an existing Borg repository whose key material should be reused (Borg 2.x+ only)',
|
||||||
)
|
)
|
||||||
rcreate_group.add_argument(
|
rcreate_group.add_argument(
|
||||||
'--append-only',
|
'--copy-crypt-key',
|
||||||
dest='append_only',
|
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Create an append-only repository',
|
help='Copy the crypt key used for authenticated encryption from the key repository, defaults to a new random key (Borg 2.x+ only)',
|
||||||
)
|
)
|
||||||
rcreate_group.add_argument(
|
rcreate_group.add_argument(
|
||||||
'--storage-quota',
|
'--append-only', action='store_true', help='Create an append-only repository',
|
||||||
dest='storage_quota',
|
)
|
||||||
help='Create a repository with a fixed storage quota',
|
rcreate_group.add_argument(
|
||||||
|
'--storage-quota', help='Create a repository with a fixed storage quota',
|
||||||
|
)
|
||||||
|
rcreate_group.add_argument(
|
||||||
|
'--make-parent-dirs',
|
||||||
|
action='store_true',
|
||||||
|
help='Create any missing parent directories of the repository directory',
|
||||||
)
|
)
|
||||||
rcreate_group.add_argument(
|
rcreate_group.add_argument(
|
||||||
'-h', '--help', action='help', help='Show this help message and exit'
|
'-h', '--help', action='help', help='Show this help message and exit'
|
||||||
|
|
|
@ -258,9 +258,11 @@ def run_actions(
|
||||||
storage,
|
storage,
|
||||||
local_borg_version,
|
local_borg_version,
|
||||||
arguments['rcreate'].encryption_mode,
|
arguments['rcreate'].encryption_mode,
|
||||||
arguments['rcreate'].other_repo,
|
arguments['rcreate'].key_repository,
|
||||||
|
arguments['rcreate'].copy_crypt_key,
|
||||||
arguments['rcreate'].append_only,
|
arguments['rcreate'].append_only,
|
||||||
arguments['rcreate'].storage_quota,
|
arguments['rcreate'].storage_quota,
|
||||||
|
arguments['rcreate'].make_parent_dirs,
|
||||||
local_path=local_path,
|
local_path=local_path,
|
||||||
remote_path=remote_path,
|
remote_path=remote_path,
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,7 +32,7 @@ def insert_rcreate_command_mock(rcreate_command, **kwargs):
|
||||||
).once()
|
).once()
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_calls_borg_with_parameters():
|
def test_create_repository_calls_borg_with_flags():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--repo', 'repo'))
|
||||||
flexmock(module.feature).should_receive('available').and_return(True)
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
@ -85,7 +85,7 @@ def test_create_repository_raises_for_unknown_rinfo_command_error():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_append_only_calls_borg_with_other_repo_parameter():
|
def test_create_repository_with_key_repository_calls_borg_with_other_repo_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--other-repo', 'other.borg', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--other-repo', 'other.borg', '--repo', 'repo'))
|
||||||
flexmock(module.feature).should_receive('available').and_return(True)
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
@ -96,11 +96,26 @@ def test_create_repository_with_append_only_calls_borg_with_other_repo_parameter
|
||||||
storage_config={},
|
storage_config={},
|
||||||
local_borg_version='2.3.4',
|
local_borg_version='2.3.4',
|
||||||
encryption_mode='repokey',
|
encryption_mode='repokey',
|
||||||
other_repo='other.borg',
|
key_repository='other.borg',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_append_only_calls_borg_with_append_only_parameter():
|
def test_create_repository_with_copy_crypt_key_calls_borg_with_copy_crypt_key_flag():
|
||||||
|
insert_rinfo_command_not_found_mock()
|
||||||
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--copy-crypt-key', '--repo', 'repo'))
|
||||||
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||||
|
|
||||||
|
module.create_repository(
|
||||||
|
repository='repo',
|
||||||
|
storage_config={},
|
||||||
|
local_borg_version='2.3.4',
|
||||||
|
encryption_mode='repokey',
|
||||||
|
copy_crypt_key=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_repository_with_append_only_calls_borg_with_append_only_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
|
||||||
flexmock(module.feature).should_receive('available').and_return(True)
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
@ -115,7 +130,7 @@ def test_create_repository_with_append_only_calls_borg_with_append_only_paramete
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_parameter():
|
def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--storage-quota', '5G', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--storage-quota', '5G', '--repo', 'repo'))
|
||||||
flexmock(module.feature).should_receive('available').and_return(True)
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
@ -130,7 +145,22 @@ def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_para
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_log_info_calls_borg_with_info_parameter():
|
def test_create_repository_with_make_parent_dirs_calls_borg_with_make_parent_dirs_flag():
|
||||||
|
insert_rinfo_command_not_found_mock()
|
||||||
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--make-parent-dirs', '--repo', 'repo'))
|
||||||
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||||
|
|
||||||
|
module.create_repository(
|
||||||
|
repository='repo',
|
||||||
|
storage_config={},
|
||||||
|
local_borg_version='2.3.4',
|
||||||
|
encryption_mode='repokey',
|
||||||
|
make_parent_dirs=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_repository_with_log_info_calls_borg_with_info_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--info', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--info', '--repo', 'repo'))
|
||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
|
@ -142,7 +172,7 @@ def test_create_repository_with_log_info_calls_borg_with_info_parameter():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_log_debug_calls_borg_with_debug_parameter():
|
def test_create_repository_with_log_debug_calls_borg_with_debug_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--debug', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--debug', '--repo', 'repo'))
|
||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
@ -169,7 +199,7 @@ def test_create_repository_with_local_path_calls_borg_via_local_path():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_repository_with_remote_path_calls_borg_with_remote_path_parameter():
|
def test_create_repository_with_remote_path_calls_borg_with_remote_path_flag():
|
||||||
insert_rinfo_command_not_found_mock()
|
insert_rinfo_command_not_found_mock()
|
||||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--remote-path', 'borg1', '--repo', 'repo'))
|
insert_rcreate_command_mock(RCREATE_COMMAND + ('--remote-path', 'borg1', '--repo', 'repo'))
|
||||||
flexmock(module.feature).should_receive('available').and_return(True)
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
|
|
@ -346,9 +346,11 @@ def test_run_actions_does_not_raise_for_rcreate_action():
|
||||||
'global': flexmock(monitoring_verbosity=1, dry_run=False),
|
'global': flexmock(monitoring_verbosity=1, dry_run=False),
|
||||||
'rcreate': flexmock(
|
'rcreate': flexmock(
|
||||||
encryption_mode=flexmock(),
|
encryption_mode=flexmock(),
|
||||||
other_repo=flexmock(),
|
key_repository=flexmock(),
|
||||||
|
copy_crypt_key=flexmock(),
|
||||||
append_only=flexmock(),
|
append_only=flexmock(),
|
||||||
storage_quota=flexmock(),
|
storage_quota=flexmock(),
|
||||||
|
make_parent_dirs=flexmock(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue