2018-09-08 22:53:37 +02:00
|
|
|
import logging
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import prune as module
|
2019-05-13 23:39:10 +02:00
|
|
|
|
2018-09-30 22:57:20 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def insert_execute_command_mock(prune_command, output_log_level, borg_exit_codes=None):
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-09-23 22:07:51 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-06-30 22:42:17 +02:00
|
|
|
prune_command,
|
|
|
|
output_log_level=output_log_level,
|
|
|
|
borg_local_path=prune_command[0],
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=borg_exit_codes,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-09-23 22:07:51 +02:00
|
|
|
).once()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
BASE_PRUNE_FLAGS = ('--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
def test_make_prune_flags_returns_flags_from_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {
|
|
|
|
'keep_daily': 1,
|
|
|
|
'keep_weekly': 2,
|
|
|
|
'keep_monthly': 3,
|
|
|
|
}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-07-09 08:14:30 +02:00
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert result == BASE_PRUNE_FLAGS
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2017-09-03 20:13:14 +02:00
|
|
|
def test_make_prune_flags_accepts_prefix_with_placeholders():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {
|
|
|
|
'keep_daily': 1,
|
|
|
|
'prefix': 'Documents_{hostname}-{now}', # noqa: FS003
|
|
|
|
}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2017-09-03 20:13:14 +02:00
|
|
|
|
2023-07-09 08:14:30 +02:00
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-03-24 07:11:14 +01:00
|
|
|
expected = (
|
2023-04-01 00:21:08 +02:00
|
|
|
'--keep-daily',
|
|
|
|
'1',
|
|
|
|
'--match-archives',
|
|
|
|
'sh:Documents_{hostname}-{now}*', # noqa: FS003
|
2023-03-24 07:11:14 +01:00
|
|
|
)
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert result == expected
|
2022-10-04 07:50:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {
|
|
|
|
'keep_daily': 1,
|
|
|
|
'prefix': 'Documents_{hostname}-{now}', # noqa: FS003
|
|
|
|
}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-07-09 08:14:30 +02:00
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
2017-09-03 20:13:14 +02:00
|
|
|
|
2023-03-24 07:11:14 +01:00
|
|
|
expected = (
|
2023-04-01 00:21:08 +02:00
|
|
|
'--keep-daily',
|
|
|
|
'1',
|
|
|
|
'--glob-archives',
|
|
|
|
'Documents_{hostname}-{now}*', # noqa: FS003
|
2023-03-24 07:11:14 +01:00
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert result == expected
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-04-05 23:58:05 +02:00
|
|
|
def test_make_prune_flags_prefers_prefix_to_archive_name_format():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {
|
|
|
|
'archive_name_format': 'bar-{now}', # noqa: FS003
|
|
|
|
'keep_daily': 1,
|
|
|
|
'prefix': 'bar-',
|
|
|
|
}
|
2023-04-05 23:58:05 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').never()
|
|
|
|
|
2023-07-09 08:14:30 +02:00
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
2023-04-05 23:58:05 +02:00
|
|
|
|
|
|
|
expected = (
|
|
|
|
'--keep-daily',
|
|
|
|
'1',
|
|
|
|
'--match-archives',
|
|
|
|
'sh:bar-*', # noqa: FS003
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {
|
|
|
|
'archive_name_format': 'bar-{now}', # noqa: FS003
|
|
|
|
'keep_daily': 1,
|
|
|
|
'prefix': None,
|
|
|
|
}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2023-04-01 00:21:08 +02:00
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
2023-04-02 08:57:55 +02:00
|
|
|
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
2023-04-01 00:21:08 +02:00
|
|
|
).and_return(('--match-archives', 'sh:bar-*'))
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-07-09 08:14:30 +02:00
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
expected = (
|
|
|
|
'--keep-daily',
|
|
|
|
'1',
|
|
|
|
'--match-archives',
|
|
|
|
'sh:bar-*', # noqa: FS003
|
|
|
|
)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert result == expected
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-07-22 19:26:52 +02:00
|
|
|
def test_make_prune_flags_ignores_keep_exclude_tags_in_config():
|
|
|
|
config = {
|
|
|
|
'keep_daily': 1,
|
|
|
|
'keep_exclude_tags': True,
|
|
|
|
}
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
|
|
|
result = module.make_prune_flags(config, local_borg_version='1.2.3')
|
|
|
|
|
|
|
|
assert result == ('--keep-daily', '1')
|
|
|
|
|
|
|
|
|
2019-09-13 00:27:04 +02:00
|
|
|
PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_calls_borg_with_flags():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2017-08-06 01:21:39 +02:00
|
|
|
module.prune_archives(
|
2022-08-14 02:26:51 +02:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2022-08-14 02:26:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_log_info_calls_borg_with_info_flag():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2020-01-11 16:38:07 +01:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2017-08-06 01:21:39 +02:00
|
|
|
module.prune_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
dry_run=False,
|
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_log_debug_calls_borg_with_debug_flag():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2020-01-23 00:23:49 +01:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2017-08-06 01:21:39 +02:00
|
|
|
module.prune_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
dry_run=False,
|
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2018-01-16 05:55:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
|
2018-01-16 05:55:27 +01:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2018-01-16 05:55:27 +01:00
|
|
|
module.prune_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
dry_run=True,
|
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2017-09-03 20:13:14 +02:00
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
|
2018-01-15 01:35:24 +01:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2018-01-15 01:35:24 +01:00
|
|
|
module.prune_archives(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2018-01-15 01:35:24 +01:00
|
|
|
local_path='borg1',
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2018-01-15 01:35:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def test_prune_archives_with_exit_codes_calls_borg_using_them():
|
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
borg_exit_codes = flexmock()
|
|
|
|
insert_execute_command_mock(
|
|
|
|
('borg',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO, borg_exit_codes
|
|
|
|
)
|
|
|
|
|
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={'borg_exit_codes': borg_exit_codes},
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
prune_arguments=prune_arguments,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2017-08-06 01:21:39 +02:00
|
|
|
module.prune_archives(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
remote_path='borg1',
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_stats_calls_borg_with_stats_flag_and_answer_output_log_level():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-12-02 21:12:10 +01:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER)
|
2019-09-23 22:07:51 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=True, list_archives=False)
|
2019-09-23 22:07:51 +02:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2019-09-23 22:07:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_files_calls_borg_with_list_flag_and_answer_output_log_level():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-12-02 21:12:10 +01:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER)
|
2020-01-22 22:28:24 +01:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=True)
|
2020-01-22 22:28:24 +01:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_umask_calls_borg_with_umask_flags():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'umask': '077'}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
|
2018-06-18 00:12:43 +02:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2018-06-18 00:12:43 +02:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2018-06-18 00:12:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-09 08:00:49 +02:00
|
|
|
def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
|
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
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 + ('--log-json', 'repo'), logging.INFO)
|
|
|
|
|
2023-05-20 15:23:09 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2023-05-09 08:00:49 +02:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2023-05-09 08:00:49 +02:00
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=True),
|
2023-05-20 15:23:09 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2023-05-09 08:00:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'lock_wait': 5}
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-23 22:07:51 +02:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2018-02-20 00:51:04 +01:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2018-02-20 00:51:04 +01:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-04 07:50:37 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-12-05 00:48:10 +01:00
|
|
|
insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
|
|
|
|
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments = flexmock(stats=False, list_archives=False)
|
2019-12-05 00:48:10 +01:00
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'extra_borg_options': {'prune': '--extra --options'}},
|
2022-08-14 02:26:51 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 16:54:41 +02:00
|
|
|
prune_arguments=prune_arguments,
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|
2023-04-24 17:13:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flags():
|
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2023-05-20 15:23:09 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
2023-04-24 17:13:34 +02:00
|
|
|
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
2023-05-20 15:23:09 +02:00
|
|
|
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
|
|
|
(
|
|
|
|
'--newer',
|
|
|
|
'1d',
|
|
|
|
'--newest',
|
|
|
|
'1y',
|
|
|
|
'--older',
|
|
|
|
'1m',
|
|
|
|
'--oldest',
|
|
|
|
'1w',
|
|
|
|
'--match-archives',
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
(
|
|
|
|
'borg',
|
|
|
|
'prune',
|
|
|
|
'--keep-daily',
|
|
|
|
'1',
|
|
|
|
'--keep-weekly',
|
|
|
|
'2',
|
|
|
|
'--keep-monthly',
|
|
|
|
'3',
|
|
|
|
'--newer',
|
|
|
|
'1d',
|
|
|
|
'--newest',
|
|
|
|
'1y',
|
|
|
|
'--older',
|
|
|
|
'1m',
|
|
|
|
'--oldest',
|
|
|
|
'1w',
|
|
|
|
'--match-archives',
|
|
|
|
None,
|
|
|
|
'--repo',
|
|
|
|
'repo',
|
|
|
|
),
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2023-05-20 15:23:09 +02:00
|
|
|
extra_environment=None,
|
2023-04-24 17:13:34 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
prune_arguments = flexmock(
|
|
|
|
stats=False, list_archives=False, newer='1d', newest='1y', older='1m', oldest='1w'
|
|
|
|
)
|
|
|
|
module.prune_archives(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2023-04-24 17:13:34 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-05-20 15:23:09 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2023-04-24 17:13:34 +02:00
|
|
|
prune_arguments=prune_arguments,
|
|
|
|
)
|