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
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def insert_execute_command_mock(command):
|
2020-05-15 07:38:38 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(command).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 01:52:27 +02:00
|
|
|
def test_parse_checks_with_data_check_also_injects_archives():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': [{'name': 'data'}]})
|
2019-09-19 01:52:27 +02:00
|
|
|
|
|
|
|
assert checks == ('data', 'archives')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_checks_with_data_check_passes_through_archives():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': [{'name': 'data'}, {'name': 'archives'}]})
|
2019-09-19 01:52:27 +02:00
|
|
|
|
|
|
|
assert checks == ('data', 'archives')
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_checks_with_override_data_check_also_injects_archives():
|
2022-05-28 23:42:19 +02:00
|
|
|
checks = module.parse_checks({'checks': [{'name': 'extract'}]}, only_checks=['data'])
|
2019-09-19 20:43:53 +02:00
|
|
|
|
|
|
|
assert checks == ('data', 'archives')
|
|
|
|
|
|
|
|
|
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)),
|
|
|
|
('1 month', module.datetime.timedelta(weeks=4)),
|
|
|
|
('2 months', module.datetime.timedelta(weeks=8)),
|
|
|
|
('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(
|
|
|
|
'frequency', ('sometime', 'x days', '3 decades',),
|
|
|
|
)
|
|
|
|
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(
|
|
|
|
module.datetime.timedelta(weeks=2)
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_time_path')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(None)
|
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
|
|
|
location_config={},
|
|
|
|
consistency_config={},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('repository', 'archives'),
|
|
|
|
) == ('repository', 'archives')
|
|
|
|
|
|
|
|
|
|
|
|
def test_filter_checks_on_frequency_retains_unconfigured_check():
|
|
|
|
assert module.filter_checks_on_frequency(
|
|
|
|
location_config={}, consistency_config={}, borg_repository_id='repo', checks=('data',),
|
|
|
|
) == ('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(
|
|
|
|
location_config={},
|
|
|
|
consistency_config={'checks': [{'name': 'archives'}]},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
|
|
|
) == ('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')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(
|
|
|
|
module.datetime.datetime(year=module.datetime.MINYEAR, month=1, day=1)
|
|
|
|
)
|
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
|
|
|
location_config={},
|
|
|
|
consistency_config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
|
|
|
) == ('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')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(None)
|
|
|
|
|
|
|
|
assert module.filter_checks_on_frequency(
|
|
|
|
location_config={},
|
|
|
|
consistency_config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
|
|
|
) == ('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')
|
|
|
|
flexmock(module).should_receive('read_check_time').and_return(module.datetime.datetime.now())
|
|
|
|
|
|
|
|
assert (
|
|
|
|
module.filter_checks_on_frequency(
|
|
|
|
location_config={},
|
|
|
|
consistency_config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
|
|
|
borg_repository_id='repo',
|
|
|
|
checks=('archives',),
|
|
|
|
)
|
|
|
|
== ()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
def test_make_check_flags_with_repository_check_returns_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository',))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
2019-09-19 01:52:27 +02:00
|
|
|
def test_make_check_flags_with_archives_check_returns_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('archives',))
|
2019-09-19 01:52:27 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_data_check_returns_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('data',))
|
2019-09-19 01:52:27 +02:00
|
|
|
|
|
|
|
assert flags == ('--verify-data',)
|
|
|
|
|
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
def test_make_check_flags_with_extract_omits_extract_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('extract',))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
assert flags == ()
|
|
|
|
|
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
def test_make_check_flags_with_default_checks_and_default_prefix_returns_default_flags():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository', 'archives'), prefix=module.DEFAULT_PREFIX)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
assert flags == ('--prefix', module.DEFAULT_PREFIX)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
def test_make_check_flags_with_all_checks_and_default_prefix_returns_default_flags():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(
|
|
|
|
('repository', 'archives', 'extract'), prefix=module.DEFAULT_PREFIX
|
2019-07-27 23:08:47 +02:00
|
|
|
)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
assert flags == ('--prefix', module.DEFAULT_PREFIX)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_archives_check_and_last_includes_last_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('archives',), check_last=3)
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
assert flags == ('--archives-only', '--last', '3')
|
2018-01-14 23:09:20 +01:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
def test_make_check_flags_with_repository_check_and_last_omits_last_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository',), check_last=3)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
assert flags == ('--repository-only',)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
def test_make_check_flags_with_default_checks_and_last_includes_last_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository', 'archives'), 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
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_archives_check_and_prefix_includes_prefix_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('archives',), prefix='foo-')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only', '--prefix', 'foo-')
|
|
|
|
|
|
|
|
|
2019-07-27 23:04:13 +02:00
|
|
|
def test_make_check_flags_with_archives_check_and_empty_prefix_omits_prefix_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('archives',), prefix='')
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_archives_check_and_none_prefix_omits_prefix_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('archives',), prefix=None)
|
2019-07-27 23:04:13 +02:00
|
|
|
|
|
|
|
assert flags == ('--archives-only',)
|
|
|
|
|
|
|
|
|
2018-05-21 07:11:40 +02:00
|
|
|
def test_make_check_flags_with_repository_check_and_prefix_omits_prefix_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository',), prefix='foo-')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
assert flags == ('--repository-only',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_check_flags_with_default_checks_and_prefix_includes_prefix_flag():
|
2022-05-28 23:42:19 +02:00
|
|
|
flags = module.make_check_flags(('repository', 'archives'), prefix='foo-')
|
2018-05-21 07:11:40 +02:00
|
|
|
|
|
|
|
assert flags == ('--prefix', 'foo-')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2020-01-24 20:27:16 +01:00
|
|
|
def test_check_archives_with_progress_calls_borg_with_progress_parameter():
|
|
|
|
checks = ('repository',)
|
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2020-01-24 20:27:16 +01:00
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2020-05-15 07:38:38 +02:00
|
|
|
('borg', 'check', '--progress', 'repo'), output_file=module.DO_NOT_CAPTURE
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
progress=True,
|
2020-01-24 20:27:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-12-05 01:07:00 +01:00
|
|
|
def test_check_archives_with_repair_calls_borg_with_repair_parameter():
|
|
|
|
checks = ('repository',)
|
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
2019-12-05 01:07:00 +01:00
|
|
|
flexmock(module).should_receive('execute_command').never()
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2020-05-15 07:38:38 +02:00
|
|
|
('borg', 'check', '--repair', 'repo'), output_file=module.DO_NOT_CAPTURE
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
repair=True,
|
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()
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': check_last}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(
|
2019-07-27 23:04:13 +02:00
|
|
|
checks, check_last, module.DEFAULT_PREFIX
|
2018-09-30 07:45:00 +02:00
|
|
|
).and_return(())
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_json_error_raises():
|
|
|
|
checks = ('archives',)
|
|
|
|
check_last = flexmock()
|
|
|
|
consistency_config = {'check_last': check_last}
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"unexpected": {"id": "repo"}}'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2022-05-28 23:42:19 +02:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_missing_json_keys_raises():
|
|
|
|
checks = ('archives',)
|
|
|
|
check_last = flexmock()
|
|
|
|
consistency_config = {'check_last': check_last}
|
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return('{invalid JSON')
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_archives(
|
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
)
|
|
|
|
|
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()
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': check_last}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').never()
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
def test_check_archives_with_log_info_calls_borg_with_info_parameter():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-08 22:53:37 +02:00
|
|
|
def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-01-15 01:35:24 +01:00
|
|
|
def test_check_archives_without_any_checks_bails():
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(())
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_never()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.check_archives(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
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()
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': check_last}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(
|
2019-07-27 23:04:13 +02:00
|
|
|
checks, check_last, module.DEFAULT_PREFIX
|
2018-09-30 07:45:00 +02:00
|
|
|
).and_return(())
|
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(
|
|
|
|
repository='repo',
|
2022-05-28 23:42:19 +02:00
|
|
|
location_config={},
|
2018-02-20 00:51:04 +01:00
|
|
|
storage_config={},
|
2018-01-15 01:35:24 +01:00
|
|
|
consistency_config=consistency_config,
|
|
|
|
local_path='borg1',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
2017-08-06 01:21:39 +02:00
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': check_last}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(
|
2019-07-27 23:04:13 +02:00
|
|
|
checks, check_last, module.DEFAULT_PREFIX
|
2018-09-30 07:45:00 +02:00
|
|
|
).and_return(())
|
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(
|
|
|
|
repository='repo',
|
2022-05-28 23:42:19 +02:00
|
|
|
location_config={},
|
2018-02-20 00:51:04 +01:00
|
|
|
storage_config={},
|
2017-08-06 01:21:39 +02:00
|
|
|
consistency_config=consistency_config,
|
|
|
|
remote_path='borg1',
|
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|
|
|
checks = ('repository',)
|
|
|
|
check_last = flexmock()
|
2018-03-04 07:17:39 +01:00
|
|
|
consistency_config = {'check_last': check_last}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(
|
2019-07-27 23:04:13 +02:00
|
|
|
checks, check_last, module.DEFAULT_PREFIX
|
2018-09-30 07:45:00 +02:00
|
|
|
).and_return(())
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={'lock_wait': 5},
|
|
|
|
consistency_config=consistency_config,
|
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-'
|
|
|
|
consistency_config = {'check_last': check_last, 'prefix': prefix}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').with_args(
|
2018-09-30 07:45:00 +02:00
|
|
|
checks, check_last, prefix
|
|
|
|
).and_return(())
|
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(
|
2022-05-28 23:42:19 +02:00
|
|
|
repository='repo',
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
|
|
|
consistency_config=consistency_config,
|
2018-03-04 07:17:39 +01:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|
|
|
checks = ('repository',)
|
|
|
|
consistency_config = {'check_last': None}
|
2022-05-28 23:42:19 +02:00
|
|
|
flexmock(module).should_receive('parse_checks')
|
|
|
|
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
|
|
|
flexmock(module.info).should_receive('display_archives_info').and_return(
|
|
|
|
'{"repository": {"id": "repo"}}'
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('make_check_flags').and_return(())
|
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(
|
|
|
|
repository='repo',
|
2022-05-28 23:42:19 +02:00
|
|
|
location_config={},
|
2019-12-05 00:48:10 +01:00
|
|
|
storage_config={'extra_borg_options': {'check': '--extra --options'}},
|
|
|
|
consistency_config=consistency_config,
|
|
|
|
)
|