|
|
|
@ -23,16 +23,29 @@ BASE_PRUNE_FLAGS = (('--keep-daily', '1'), ('--keep-weekly', '2'), ('--keep-mont
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_returns_flags_from_config_plus_default_prefix_glob():
|
|
|
|
|
retention_config = OrderedDict((('keep_daily', 1), ('keep_weekly', 2), ('keep_monthly', 3)))
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
|
|
result = module.make_prune_flags(retention_config)
|
|
|
|
|
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
|
|
assert tuple(result) == BASE_PRUNE_FLAGS + (('--glob-archives', '{hostname}-*'),)
|
|
|
|
|
assert tuple(result) == BASE_PRUNE_FLAGS + (('--match-archives', 'sh:{hostname}-*'),)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_accepts_prefix_with_placeholders():
|
|
|
|
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', 'Documents_{hostname}-{now}')))
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
|
|
result = module.make_prune_flags(retention_config)
|
|
|
|
|
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
|
|
expected = (('--keep-daily', '1'), ('--match-archives', 'sh:Documents_{hostname}-{now}*'))
|
|
|
|
|
|
|
|
|
|
assert tuple(result) == expected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives():
|
|
|
|
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', 'Documents_{hostname}-{now}')))
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
|
|
|
|
|
|
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
|
|
expected = (('--keep-daily', '1'), ('--glob-archives', 'Documents_{hostname}-{now}*'))
|
|
|
|
|
|
|
|
|
@ -41,8 +54,9 @@ def test_make_prune_flags_accepts_prefix_with_placeholders():
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_treats_empty_prefix_as_no_prefix():
|
|
|
|
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', '')))
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
|
|
result = module.make_prune_flags(retention_config)
|
|
|
|
|
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
|
|
expected = (('--keep-daily', '1'),)
|
|
|
|
|
|
|
|
|
@ -51,8 +65,9 @@ def test_make_prune_flags_treats_empty_prefix_as_no_prefix():
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_treats_none_prefix_as_no_prefix():
|
|
|
|
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', None)))
|
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
|
|
result = module.make_prune_flags(retention_config)
|
|
|
|
|
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
|
|
expected = (('--keep-daily', '1'),)
|
|
|
|
|
|
|
|
|
@ -63,10 +78,7 @@ PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_calls_borg_with_parameters():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -74,16 +86,13 @@ def test_prune_archives_calls_borg_with_parameters():
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
|
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
@ -92,16 +101,13 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
dry_run=False,
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
|
|
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
@ -110,16 +116,13 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
dry_run=False,
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -127,16 +130,13 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
dry_run=True,
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -144,17 +144,14 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
local_path='borg1',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -162,17 +159,14 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
remote_path='borg1',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_stats_calls_borg_with_stats_parameter_and_warning_output_log_level():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING)
|
|
|
|
|
|
|
|
|
@ -180,17 +174,14 @@ def test_prune_archives_with_stats_calls_borg_with_stats_parameter_and_warning_o
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
stats=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_stats_and_log_info_calls_borg_with_stats_parameter_and_info_output_log_level():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo'), logging.INFO)
|
|
|
|
@ -199,17 +190,14 @@ def test_prune_archives_with_stats_and_log_info_calls_borg_with_stats_parameter_
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
stats=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_files_calls_borg_with_list_parameter_and_warning_output_log_level():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), logging.WARNING)
|
|
|
|
|
|
|
|
|
@ -217,17 +205,14 @@ def test_prune_archives_with_files_calls_borg_with_list_parameter_and_warning_ou
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
list_archives=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_files_and_log_info_calls_borg_with_list_parameter_and_info_output_log_level():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--info', '--list', 'repo'), logging.INFO)
|
|
|
|
@ -236,7 +221,7 @@ def test_prune_archives_with_files_and_log_info_calls_borg_with_list_parameter_a
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
list_archives=True,
|
|
|
|
|
)
|
|
|
|
@ -244,10 +229,7 @@ def test_prune_archives_with_files_and_log_info_calls_borg_with_list_parameter_a
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
|
|
|
|
|
storage_config = {'umask': '077'}
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -255,17 +237,14 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config=storage_config,
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
|
|
storage_config = {'lock_wait': 5}
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -273,16 +252,13 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config=storage_config,
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
|
|
retention_config = flexmock()
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
|
|
|
BASE_PRUNE_FLAGS
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
|
|
|
|
|
|
|
|
|
@ -290,6 +266,6 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
|
|
dry_run=False,
|
|
|
|
|
repository='repo',
|
|
|
|
|
storage_config={'extra_borg_options': {'prune': '--extra --options'}},
|
|
|
|
|
retention_config=retention_config,
|
|
|
|
|
retention_config=flexmock(),
|
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
|
)
|
|
|
|
|