Fix the "spot" check to have a nicer error when there are no source paths to compare.

This commit is contained in:
Dan Helfman
2025-01-15 19:48:08 -08:00
parent 44efca2be9
commit 3bda843139
3 changed files with 39 additions and 1 deletions
+1
View File
@@ -12,6 +12,7 @@
* #965: Fix a borgmatic runtime directory error when running the "spot" check with a database hook
enabled.
* Fix the "spot" check to no longer consider pipe files within an archive for file comparisons.
* Fix the "spot" check to have a nicer error when there are no source paths to compare.
* Fix auto-excluding of special files (when databases are configured) to support relative source
directory paths.
* Drop support for Python 3.8, which has been end-of-lifed.
+8
View File
@@ -629,6 +629,14 @@ def spot_check(
)
logger.debug(f'{log_prefix}: {len(archive_paths)} total archive paths for spot check')
if len(source_paths) == 0:
logger.debug(
f'{log_prefix}: Paths in latest archive but not source paths: {", ".join(set(archive_paths)) or "none"}'
)
raise ValueError(
f'Spot check failed: There are no source paths to compare against the archive'
)
# Calculate the percentage delta between the source paths count and the archive paths count, and
# compare that delta to the configured count tolerance percentage.
count_delta_percentage = abs(len(source_paths) - len(archive_paths)) / len(source_paths) * 100
+30 -1
View File
@@ -1251,7 +1251,7 @@ def test_spot_check_without_any_configuration_errors():
)
def test_spot_check_data_tolerance_percenatge_greater_than_data_sample_percentage_errors():
def test_spot_check_data_tolerance_percentage_greater_than_data_sample_percentage_errors():
with pytest.raises(ValueError):
module.spot_check(
repository={'path': 'repo'},
@@ -1369,6 +1369,35 @@ def test_spot_check_with_high_enough_tolerances_does_not_raise():
)
def test_spot_check_without_any_source_paths_errors():
flexmock(module).should_receive('collect_spot_check_source_paths').and_return(())
flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return(
'archive'
)
flexmock(module).should_receive('collect_spot_check_archive_paths').and_return(('/foo', '/bar'))
flexmock(module).should_receive('compare_spot_check_hashes').never()
with pytest.raises(ValueError):
module.spot_check(
repository={'path': 'repo'},
config={
'checks': [
{
'name': 'spot',
'count_tolerance_percentage': 10,
'data_tolerance_percentage': 40,
'data_sample_percentage': 50,
},
]
},
local_borg_version=flexmock(),
global_arguments=flexmock(),
local_path=flexmock(),
remote_path=flexmock(),
borgmatic_runtime_directory='/run/borgmatic',
)
def test_run_check_checks_archives_for_configured_repository():
flexmock(module.logger).answer = lambda message: None
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()