From 07222cd984a5af263300ef07cb638f9d88ed65a0 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 23 Sep 2019 13:07:51 -0700 Subject: [PATCH] Fix visibility of "borgmatic prune --stats" output (#219). --- MANIFEST.in | 1 + NEWS | 3 +++ borgmatic/borg/prune.py | 2 +- setup.py | 2 +- tests/unit/borg/test_prune.py | 38 ++++++++++++++++++++++++++--------- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 20ff231..fee8b6d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include borgmatic/config/schema.yaml +graft sample/systemd diff --git a/NEWS b/NEWS index 7192591..49a7e8b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.3.19 + * #219: Fix visibility of "borgmatic prune --stats" output. + 1.3.18 * #220: Fix regression of argument parsing for default actions. diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index 7b59c0a..ec5963f 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -64,4 +64,4 @@ def prune_archives( + (repository,) ) - execute_command(full_command) + execute_command(full_command, output_log_level=logging.WARNING if stats else logging.INFO) diff --git a/setup.py b/setup.py index 20a99c8..adf8953 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.18' +VERSION = '1.3.19' setup( diff --git a/tests/unit/borg/test_prune.py b/tests/unit/borg/test_prune.py index 638fb85..d05e8c0 100644 --- a/tests/unit/borg/test_prune.py +++ b/tests/unit/borg/test_prune.py @@ -8,8 +8,10 @@ from borgmatic.borg import prune as module from ..test_verbosity import insert_logging_mock -def insert_execute_command_mock(prune_command, **kwargs): - flexmock(module).should_receive('execute_command').with_args(prune_command).once() +def insert_execute_command_mock(prune_command, output_log_level): + flexmock(module).should_receive('execute_command').with_args( + prune_command, output_log_level=output_log_level + ).once() BASE_PRUNE_FLAGS = (('--keep-daily', '1'), ('--keep-weekly', '2'), ('--keep-monthly', '3')) @@ -61,7 +63,7 @@ def test_prune_archives_calls_borg_with_parameters(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('repo',)) + insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO) module.prune_archives( dry_run=False, repository='repo', storage_config={}, retention_config=retention_config @@ -73,7 +75,7 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo')) + insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo'), logging.INFO) insert_logging_mock(logging.INFO) module.prune_archives( @@ -87,7 +89,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter(): BASE_PRUNE_FLAGS ) insert_execute_command_mock( - PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc', 'repo') + PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc', 'repo'), logging.INFO ) insert_logging_mock(logging.DEBUG) @@ -101,7 +103,7 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo')) + insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO) module.prune_archives( repository='repo', storage_config={}, dry_run=True, retention_config=retention_config @@ -113,7 +115,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',)) + insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO) module.prune_archives( dry_run=False, @@ -129,7 +131,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo')) + insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO) module.prune_archives( dry_run=False, @@ -140,13 +142,29 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters( ) +def test_prune_archives_with_stats_calls_borg_with_stats_parameter(): + retention_config = flexmock() + flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( + BASE_PRUNE_FLAGS + ) + insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING) + + module.prune_archives( + dry_run=False, + repository='repo', + storage_config={}, + retention_config=retention_config, + stats=True, + ) + + def test_prune_archives_with_umask_calls_borg_with_umask_parameters(): storage_config = {'umask': '077'} retention_config = flexmock() flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo')) + insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO) module.prune_archives( dry_run=False, @@ -162,7 +180,7 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo')) + insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO) module.prune_archives( dry_run=False,