2018-09-30 08:15:18 +02:00
|
|
|
import logging
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
import pytest
|
2019-05-13 23:39:10 +02:00
|
|
|
from flexmock import flexmock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
from borgmatic.borg import check 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
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def insert_execute_command_mock(command, borg_exit_codes=None):
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-01-21 20:34:40 +01:00
|
|
|
command,
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path=command[0],
|
|
|
|
borg_exit_codes=borg_exit_codes,
|
2022-06-30 22:42:17 +02:00
|
|
|
).once()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def insert_execute_command_never():
|
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_checks_returns_them_as_tuple():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': [{'name': 'foo'}, {'name': 'bar'}]})
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
assert checks == ('foo', 'bar')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_checks_with_missing_value_returns_defaults():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({})
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
assert checks == ('repository', 'archives')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
def test_parse_checks_with_empty_list_returns_defaults():
|
|
|
|
checks = module.parse_checks({'checks': []})
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
assert checks == ('repository', 'archives')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-08-26 18:52:32 +02:00
|
|
|
def test_parse_checks_with_none_value_returns_defaults():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': None})
|
2019-08-26 18:52:32 +02:00
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
assert checks == ('repository', 'archives')
|
2019-08-26 18:52:32 +02:00
|
|
|
|
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
def test_parse_checks_with_disabled_returns_no_checks():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': [{'name': 'foo'}, {'name': 'disabled'}]})
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
assert checks == ()
|
|
|
|
|
|
|
|
|
2019-09-19 20:43:53 +02:00
|
|
|
def test_parse_checks_prefers_override_checks_to_configured_checks():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks(
|
|
|
|
{'checks': [{'name': 'archives'}]}, only_checks=['repository', 'extract']
|
|
|
|
)
|
2019-09-19 20:43:53 +02:00
|
|
|
|
|
|
|
assert checks == ('repository', 'extract')
|
|
|
|
|
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'frequency,expected_result',
|
|
|
|
(
|
|
|
|
(None, None),
|
|
|
|
('always', None),
|
|
|
|
('1 hour', module.datetime.timedelta(hours=1)),
|
|
|
|
('2 hours', module.datetime.timedelta(hours=2)),
|
|
|
|
('1 day', module.datetime.timedelta(days=1)),
|
|
|
|
('2 days', module.datetime.timedelta(days=2)),
|
|
|
|
('1 week', module.datetime.timedelta(weeks=1)),
|
|
|
|
('2 weeks', module.datetime.timedelta(weeks=2)),
|
2022-05-29 04:29:33 +02:00
|
|
|
('1 month', module.datetime.timedelta(days=30)),
|
|
|
|
('2 months', module.datetime.timedelta(days=60)),
|
2022-05-28 23:42:19 +02:00
|
|
|
('1 year', module.datetime.timedelta(days=365)),
|
|
|
|
('2 years', module.datetime.timedelta(days=365 * 2)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_parse_frequency_parses_into_timedeltas(frequency, expected_result):
|
|
|
|
assert module.parse_frequency(frequency) == expected_result
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-04-15 04:35:24 +02:00
|
|
|
'frequency',
|
|
|
|
(
|
|
|
|
'sometime',
|
|
|
|
'x days',
|
|
|
|
'3 decades',
|
|
|
|
),
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
def test_parse_frequency_raises_on_parse_error(frequency):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.parse_frequency(frequency)
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_without_config_uses_default_checks():
|
|
|
|
flexmock(module).should_receive('parse_frequency').and_return(
|
2022-05-29 00:49:50 +02:00
|
|
|
module.datetime.timedelta(weeks=4)
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('probe_for_check_time').and_return(None)
|
2022-05-28 23:42:19 +02:00
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-05-28 23:42:19 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('repository', 'archives'),
|
2022-05-29 04:29:33 +02:00
|
|
|
force=False,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-28 23:42:19 +02:00
|
|
|
) == ('repository', 'archives')
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_retains_unconfigured_check():
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={},
|
2022-05-29 04:29:33 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('data',),
|
|
|
|
force=False,
|
2022-05-28 23:42:19 +02:00
|
|
|
) == ('data',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_retains_check_without_frequency():
|
|
|
|
flexmock(module).should_receive('parse_frequency').and_return(None)
|
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'checks': [{'name': 'archives'}]},
|
2022-05-28 23:42:19 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
2022-05-29 04:29:33 +02:00
|
|
|
force=False,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-28 23:42:19 +02:00
|
|
|
) == ('archives',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_retains_check_with_elapsed_frequency():
|
|
|
|
flexmock(module).should_receive('parse_frequency').and_return(
|
|
|
|
module.datetime.timedelta(hours=1)
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('probe_for_check_time').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
module.datetime.datetime(year=module.datetime.MINYEAR, month=1, day=1)
|
|
|
|
)
|
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
2022-05-28 23:42:19 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
2022-05-29 04:29:33 +02:00
|
|
|
force=False,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-28 23:42:19 +02:00
|
|
|
) == ('archives',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_retains_check_with_missing_check_time_file():
|
|
|
|
flexmock(module).should_receive('parse_frequency').and_return(
|
|
|
|
module.datetime.timedelta(hours=1)
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('probe_for_check_time').and_return(None)
|
2022-05-28 23:42:19 +02:00
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
2022-05-28 23:42:19 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
2022-05-29 04:29:33 +02:00
|
|
|
force=False,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-28 23:42:19 +02:00
|
|
|
) == ('archives',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_skips_check_with_unelapsed_frequency():
|
|
|
|
flexmock(module).should_receive('parse_frequency').and_return(
|
|
|
|
module.datetime.timedelta(hours=1)
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('probe_for_check_time').and_return(
|
|
|
|
module.datetime.datetime.now()
|
|
|
|
)
|
2022-05-28 23:42:19 +02:00
|
|
|
|
|
|
|
assert (
|
|
|
|
module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
2022-05-28 23:42:19 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
2022-05-29 04:29:33 +02:00
|
|
|
force=False,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
== ()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-05-29 04:29:33 +02:00
|
|
|
def test_filter_checks_on_frequency_restains_check_with_unelapsed_frequency_and_force():
|
|
|
|
assert module.filter_checks_on_frequency(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
2022-05-29 04:29:33 +02:00
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
|
|
|
force=True,
|
2023-05-16 08:17:45 +02:00
|
|
|
archives_check_id='1234',
|
2022-05-29 04:29:33 +02:00
|
|
|
) == ('archives',)
|
|
|
|
|
|
|
|
|
2023-11-01 05:54:41 +01:00
|
|
|
def test_filter_checks_on_frequency_passes_through_empty_checks():
|
|
|
|
assert (
|
|
|
|
module.filter_checks_on_frequency(
|
|
|
|
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=(),
|
|
|
|
force=False,
|
|
|
|
archives_check_id='1234',
|
|
|
|
)
|
|
|
|
== ()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_prefix_returns_default_flags():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('repository', 'archives'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-04-15 04:35:24 +02:00
|
|
|
prefix='foo',
|
|
|
|
)
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo*')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_all_checks_and_prefix_returns_default_flags():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('repository', 'archives', 'extract'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-04-15 04:35:24 +02:00
|
|
|
prefix='foo',
|
2022-10-04 07:50:37 +02:00
|
|
|
)
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo*')
|
2022-10-04 07:50:37 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_all_checks_and_prefix_without_borg_features_returns_glob_archives_flags():
|
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-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-04-15 04:35:24 +02:00
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('repository', 'archives', 'extract'),
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(match_archives=None),
|
2023-04-15 04:35:24 +02:00
|
|
|
prefix='foo',
|
2019-07-27 23:08:47 +02:00
|
|
|
)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
assert flags == ('--glob-archives', 'foo*')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_last_includes_last_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('archives',), check_arguments=flexmock(match_archives=None), check_last=3
|
|
|
|
)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--last', '3')
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_data_check_and_last_includes_last_flag():
|
2022-11-17 19:19:48 +01: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(())
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('data',), check_arguments=flexmock(match_archives=None), check_last=3
|
|
|
|
)
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--last', '3')
|
2022-11-17 19:19:48 +01:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_repository_check_and_last_omits_last_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('repository',), check_arguments=flexmock(match_archives=None), check_last=3
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_last_includes_last_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('repository', 'archives'),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
|
|
|
check_last=3,
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
assert flags == ('--last', '3')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_prefix_includes_match_archives_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('archives',), check_arguments=flexmock(match_archives=None), prefix='foo-'
|
|
|
|
)
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_data_check_and_prefix_includes_match_archives_flag():
|
2022-11-17 19:19:48 +01: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(())
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('data',), check_arguments=flexmock(match_archives=None), prefix='foo-'
|
|
|
|
)
|
2022-11-17 19:19:48 +01:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2022-11-17 19:19:48 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_make_archive_filter_flags_prefers_check_arguments_match_archives_to_config_match_archives():
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
|
|
|
'baz-*', None, '1.2.3'
|
|
|
|
).and_return(('--match-archives', 'sh:baz-*'))
|
|
|
|
|
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
|
|
|
{'match_archives': 'bar-{now}'}, # noqa: FS003
|
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives='baz-*'),
|
|
|
|
prefix='',
|
|
|
|
)
|
|
|
|
|
|
|
|
assert flags == ('--match-archives', 'sh:baz-*')
|
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_empty_prefix_uses_archive_name_format_instead():
|
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-*'))
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_archive_filter_flags(
|
2023-10-30 00:22:39 +01:00
|
|
|
'1.2.3',
|
|
|
|
{'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
|
|
|
('archives',),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
|
|
|
prefix='',
|
2023-04-01 00:21:08 +02:00
|
|
|
)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:bar-*')
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_archives_check_and_none_prefix_omits_match_archives_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('archives',), check_arguments=flexmock(match_archives=None), prefix=None
|
|
|
|
)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_repository_check_and_prefix_omits_match_archives_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3', {}, ('repository',), check_arguments=flexmock(match_archives=None), prefix='foo-'
|
|
|
|
)
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
assert flags == ()
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archive_filter_flags_with_default_checks_and_prefix_includes_match_archives_flag():
|
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(())
|
2022-10-04 07:50:37 +02:00
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
flags = module.make_archive_filter_flags(
|
|
|
|
'1.2.3',
|
|
|
|
{},
|
|
|
|
('repository', 'archives'),
|
|
|
|
check_arguments=flexmock(match_archives=None),
|
|
|
|
prefix='foo-',
|
|
|
|
)
|
2018-05-21 07:11:40 +02:00
|
|
|
|
2022-10-04 07:50:37 +02:00
|
|
|
assert flags == ('--match-archives', 'sh:foo-*')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_archives_check_id_with_flags_returns_a_value_and_does_not_raise():
|
|
|
|
assert module.make_archives_check_id(('--match-archives', 'sh:foo-*'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_archives_check_id_with_empty_flags_returns_none():
|
|
|
|
assert module.make_archives_check_id(()) is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_repository_check_returns_flag():
|
|
|
|
flags = module.make_check_flags(('repository',), ())
|
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_archives_check_returns_flag():
|
|
|
|
flags = module.make_check_flags(('archives',), ())
|
|
|
|
|
|
|
|
assert flags == ('--archives-only',)
|
|
|
|
|
|
|
|
|
2023-05-31 08:19:33 +02:00
|
|
|
def test_make_check_flags_with_archives_check_and_archive_filter_flags_includes_those_flags():
|
2023-05-16 08:17:45 +02:00
|
|
|
flags = module.make_check_flags(('archives',), ('--match-archives', 'sh:foo-*'))
|
|
|
|
|
|
|
|
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
|
|
|
|
|
|
|
|
2023-05-31 08:19:33 +02:00
|
|
|
def test_make_check_flags_without_archives_check_and_with_archive_filter_flags_includes_those_flags():
|
|
|
|
flags = module.make_check_flags(('repository',), ('--match-archives', 'sh:foo-*'))
|
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_make_check_flags_with_data_check_returns_flag_and_implies_archives():
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
|
|
|
flags = module.make_check_flags(('data',), ())
|
|
|
|
|
|
|
|
assert flags == (
|
|
|
|
'--archives-only',
|
|
|
|
'--verify-data',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_extract_omits_extract_flag():
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
|
|
|
flags = module.make_check_flags(('extract',), ())
|
|
|
|
|
|
|
|
assert flags == ()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_repository_and_data_checks_does_not_return_repository_only():
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
|
|
|
|
|
|
|
flags = module.make_check_flags(
|
|
|
|
(
|
|
|
|
'repository',
|
|
|
|
'data',
|
|
|
|
),
|
|
|
|
(),
|
|
|
|
)
|
|
|
|
|
|
|
|
assert flags == ('--verify-data',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_time_path_with_borgmatic_source_directory_includes_it():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
|
|
|
'/home/user/.borgmatic'
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
module.make_check_time_path(
|
|
|
|
{'borgmatic_source_directory': '~/.borgmatic'}, '1234', 'archives', '5678'
|
|
|
|
)
|
|
|
|
== '/home/user/.borgmatic/checks/1234/archives/5678'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_time_path_without_borgmatic_source_directory_uses_default():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args(
|
|
|
|
module.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
|
|
|
|
).and_return('/home/user/.borgmatic')
|
|
|
|
|
|
|
|
assert (
|
|
|
|
module.make_check_time_path({}, '1234', 'archives', '5678')
|
|
|
|
== '/home/user/.borgmatic/checks/1234/archives/5678'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_time_path_with_archives_check_and_no_archives_check_id_defaults_to_all():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
|
|
|
'/home/user/.borgmatic'
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
module.make_check_time_path(
|
|
|
|
{'borgmatic_source_directory': '~/.borgmatic'},
|
|
|
|
'1234',
|
|
|
|
'archives',
|
|
|
|
)
|
|
|
|
== '/home/user/.borgmatic/checks/1234/archives/all'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_time_path_with_repositories_check_ignores_archives_check_id():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
|
|
|
'/home/user/.borgmatic'
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
module.make_check_time_path(
|
|
|
|
{'borgmatic_source_directory': '~/.borgmatic'}, '1234', 'repository', '5678'
|
|
|
|
)
|
|
|
|
== '/home/user/.borgmatic/checks/1234/repository'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
def test_read_check_time_does_not_raise():
|
|
|
|
flexmock(module.os).should_receive('stat').and_return(flexmock(st_mtime=123))
|
|
|
|
|
|
|
|
assert module.read_check_time('/path')
|
|
|
|
|
|
|
|
|
|
|
|
def test_read_check_time_on_missing_file_does_not_raise():
|
|
|
|
flexmock(module.os).should_receive('stat').and_raise(FileNotFoundError)
|
|
|
|
|
|
|
|
assert module.read_check_time('/path') is None
|
|
|
|
|
|
|
|
|
2023-05-16 19:20:52 +02:00
|
|
|
def test_probe_for_check_time_uses_maximum_of_multiple_check_times():
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/5678'
|
|
|
|
).and_return('~/.borgmatic/checks/1234/archives/all')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(1).and_return(2)
|
|
|
|
|
2023-05-16 19:20:52 +02:00
|
|
|
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 2
|
2023-05-16 08:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_probe_for_check_time_deduplicates_identical_check_time_paths():
|
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/5678'
|
|
|
|
).and_return('~/.borgmatic/checks/1234/archives/5678')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(1).once()
|
|
|
|
|
|
|
|
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_probe_for_check_time_skips_none_check_time():
|
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/5678'
|
|
|
|
).and_return('~/.borgmatic/checks/1234/archives/all')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(None).and_return(2)
|
|
|
|
|
|
|
|
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 2
|
|
|
|
|
|
|
|
|
|
|
|
def test_probe_for_check_time_uses_single_check_time():
|
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/5678'
|
|
|
|
).and_return('~/.borgmatic/checks/1234/archives/all')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(1).and_return(None)
|
|
|
|
|
|
|
|
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_probe_for_check_time_returns_none_when_no_check_time_found():
|
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/5678'
|
|
|
|
).and_return('~/.borgmatic/checks/1234/archives/all')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(None).and_return(None)
|
|
|
|
|
|
|
|
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_upgrade_check_times_renames_old_check_paths_to_all():
|
|
|
|
base_path = '~/.borgmatic/checks/1234'
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'archives', 'all'
|
|
|
|
).and_return(f'{base_path}/archives/all')
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'data', 'all'
|
|
|
|
).and_return(f'{base_path}/data/all')
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return(
|
|
|
|
True
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(
|
|
|
|
f'{base_path}/archives.temp'
|
|
|
|
).and_return(False)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return(
|
|
|
|
False
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(
|
|
|
|
f'{base_path}/data.temp'
|
|
|
|
).and_return(False)
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/archives', f'{base_path}/archives.temp'
|
|
|
|
).once()
|
|
|
|
flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/archives').once()
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/archives.temp', f'{base_path}/archives/all'
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.upgrade_check_times(flexmock(), flexmock())
|
|
|
|
|
|
|
|
|
2023-06-20 08:07:57 +02:00
|
|
|
def test_upgrade_check_times_renames_data_check_paths_when_archives_paths_are_already_upgraded():
|
|
|
|
base_path = '~/.borgmatic/checks/1234'
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'archives', 'all'
|
|
|
|
).and_return(f'{base_path}/archives/all')
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'data', 'all'
|
|
|
|
).and_return(f'{base_path}/data/all')
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return(
|
|
|
|
False
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(
|
|
|
|
f'{base_path}/archives.temp'
|
|
|
|
).and_return(False)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return(
|
|
|
|
True
|
|
|
|
)
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/data', f'{base_path}/data.temp'
|
|
|
|
).once()
|
|
|
|
flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/data').once()
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/data.temp', f'{base_path}/data/all'
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.upgrade_check_times(flexmock(), flexmock())
|
|
|
|
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
def test_upgrade_check_times_skips_missing_check_paths():
|
|
|
|
flexmock(module).should_receive('make_check_time_path').and_return(
|
|
|
|
'~/.borgmatic/checks/1234/archives/all'
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').and_return(False)
|
|
|
|
flexmock(module.os).should_receive('rename').never()
|
|
|
|
flexmock(module.os).should_receive('mkdir').never()
|
|
|
|
|
|
|
|
module.upgrade_check_times(flexmock(), flexmock())
|
|
|
|
|
|
|
|
|
|
|
|
def test_upgrade_check_times_renames_stale_temporary_check_path():
|
|
|
|
base_path = '~/.borgmatic/checks/1234'
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'archives', 'all'
|
|
|
|
).and_return(f'{base_path}/archives/all')
|
|
|
|
flexmock(module).should_receive('make_check_time_path').with_args(
|
|
|
|
object, object, 'data', 'all'
|
|
|
|
).and_return(f'{base_path}/data/all')
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return(
|
|
|
|
False
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(
|
|
|
|
f'{base_path}/archives.temp'
|
|
|
|
).and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return(
|
|
|
|
False
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('isfile').with_args(
|
|
|
|
f'{base_path}/data.temp'
|
|
|
|
).and_return(False)
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/archives', f'{base_path}/archives.temp'
|
|
|
|
).and_raise(FileNotFoundError)
|
|
|
|
flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/archives').once()
|
|
|
|
flexmock(module.os).should_receive('rename').with_args(
|
|
|
|
f'{base_path}/archives.temp', f'{base_path}/archives/all'
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.upgrade_check_times(flexmock(), flexmock())
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_progress_passes_through_to_borg():
|
2020-01-24 20:27:16 +01:00
|
|
|
checks = ('repository',)
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2020-01-24 20:27:16 +01:00
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-06-30 22:42:17 +02:00
|
|
|
('borg', 'check', '--progress', 'repo'),
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2020-01-24 20:27:16 +01:00
|
|
|
).once()
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2020-01-24 20:27:16 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=True, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2020-01-24 20:27:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_repair_passes_through_to_borg():
|
2019-12-05 01:07:00 +01:00
|
|
|
checks = ('repository',)
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2019-12-05 01:07:00 +01:00
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2022-06-30 22:42:17 +02:00
|
|
|
('borg', 'check', '--repair', 'repo'),
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2019-12-05 01:07:00 +01:00
|
|
|
).once()
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2019-12-05 01:07:00 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=True, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2019-12-05 01:07:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'checks',
|
|
|
|
(
|
|
|
|
('repository',),
|
|
|
|
('archives',),
|
|
|
|
('repository', 'archives'),
|
|
|
|
('repository', 'archives', 'other'),
|
|
|
|
),
|
|
|
|
)
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_calls_borg_with_parameters(checks):
|
2017-08-06 01:21:39 +02:00
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_json_error_raises():
|
|
|
|
checks = ('archives',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"unexpected": {"id": "repo"}}'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_missing_json_keys_raises():
|
|
|
|
checks = ('archives',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return('{invalid JSON')
|
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2022-05-28 23:42:19 +02:00
|
|
|
)
|
|
|
|
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_with_extract_check_calls_extract_only():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('extract',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').never()
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2017-08-06 01:21:39 +02:00
|
|
|
flexmock(module.extract).should_receive('extract_last_archive_dry_run').once()
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('write_check_time')
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_never()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_info_passes_through_to_borg():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_debug_passes_through_to_borg():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_without_any_checks_bails():
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(())
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_never()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_with_local_path_calls_borg_via_local_path():
|
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2018-01-15 01:35:24 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
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',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-21 20:34:40 +01:00
|
|
|
def test_check_archives_with_exit_codes_calls_borg_using_them():
|
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
|
|
|
borg_exit_codes = flexmock()
|
|
|
|
config = {'check_last': check_last, 'borg_exit_codes': borg_exit_codes}
|
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'), borg_exit_codes=borg_exit_codes)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_remote_path_passes_through_to_borg():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
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',
|
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_log_json_passes_through_to_borg():
|
2023-05-09 08:00:49 +02:00
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last}
|
2023-05-09 08:00:49 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2023-05-09 08:00:49 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2023-05-09 08:00:49 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=True),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_lock_wait_passes_through_to_borg():
|
2018-02-20 00:51:04 +01:00
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'lock_wait': 5, 'check_last': check_last}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-09-13 00:27:04 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2018-02-20 00:51:04 +01:00
|
|
|
)
|
2018-03-04 07:17:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_retention_prefix():
|
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2018-05-21 07:11:40 +02:00
|
|
|
prefix = 'foo-'
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': check_last, 'prefix': prefix}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
2022-08-14 07:07:15 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'check', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2018-03-04 07:17:39 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2018-03-04 07:17:39 +01:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
2023-10-30 00:22:39 +01:00
|
|
|
def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
2019-12-05 00:48:10 +01:00
|
|
|
checks = ('repository',)
|
2023-07-09 08:14:30 +02:00
|
|
|
config = {'check_last': None, 'extra_borg_options': {'check': '--extra --options'}}
|
2022-08-12 23:53:20 +02:00
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
2022-05-28 23:42:19 +02:00
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2023-05-16 08:17:45 +02:00
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
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(('borg', 'check', '--extra', '--options', 'repo'))
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
module.check_archives(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config=config,
|
2022-08-12 23:53:20 +02:00
|
|
|
local_borg_version='1.2.3',
|
2023-10-30 00:22:39 +01:00
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
|
|
|
),
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_match_archives_passes_through_to_borg():
|
|
|
|
checks = ('archives',)
|
|
|
|
config = {'check_last': None}
|
|
|
|
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('upgrade_check_times')
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('make_archive_filter_flags').and_return(
|
|
|
|
('--match-archives', 'foo-*')
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(('--match-archives', 'foo-*'))
|
|
|
|
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'check', '--match-archives', 'foo-*', 'repo'),
|
|
|
|
extra_environment=None,
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
2023-10-30 00:22:39 +01:00
|
|
|
).once()
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('write_check_time')
|
|
|
|
|
|
|
|
module.check_archives(
|
|
|
|
repository_path='repo',
|
|
|
|
config=config,
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
check_arguments=flexmock(
|
|
|
|
progress=None, repair=None, only_checks=None, force=None, match_archives='foo-*'
|
|
|
|
),
|
2023-05-09 08:00:49 +02:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|