Fix visibility of "borgmatic prune --stats" output (#219).

This commit is contained in:
Dan Helfman 2019-09-23 13:07:51 -07:00
parent cf4c6c274d
commit 07222cd984
5 changed files with 34 additions and 12 deletions

View file

@ -1 +1,2 @@
include borgmatic/config/schema.yaml include borgmatic/config/schema.yaml
graft sample/systemd

3
NEWS
View file

@ -1,3 +1,6 @@
1.3.19
* #219: Fix visibility of "borgmatic prune --stats" output.
1.3.18 1.3.18
* #220: Fix regression of argument parsing for default actions. * #220: Fix regression of argument parsing for default actions.

View file

@ -64,4 +64,4 @@ def prune_archives(
+ (repository,) + (repository,)
) )
execute_command(full_command) execute_command(full_command, output_log_level=logging.WARNING if stats else logging.INFO)

View file

@ -1,6 +1,6 @@
from setuptools import find_packages, setup from setuptools import find_packages, setup
VERSION = '1.3.18' VERSION = '1.3.19'
setup( setup(

View file

@ -8,8 +8,10 @@ from borgmatic.borg import prune as module
from ..test_verbosity import insert_logging_mock from ..test_verbosity import insert_logging_mock
def insert_execute_command_mock(prune_command, **kwargs): def insert_execute_command_mock(prune_command, output_log_level):
flexmock(module).should_receive('execute_command').with_args(prune_command).once() 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')) 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('repo',)) insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
module.prune_archives( module.prune_archives(
dry_run=False, repository='repo', storage_config={}, retention_config=retention_config 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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) insert_logging_mock(logging.INFO)
module.prune_archives( module.prune_archives(
@ -87,7 +89,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock( 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) 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
repository='repo', storage_config={}, dry_run=True, retention_config=retention_config 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
dry_run=False, 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
dry_run=False, 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(): def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
storage_config = {'umask': '077'} storage_config = {'umask': '077'}
retention_config = flexmock() retention_config = flexmock()
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
dry_run=False, 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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
dry_run=False, dry_run=False,