Browse Source

Fix traceback when a database hook value is null in a configuration file (#355).

master
Dan Helfman 2 weeks ago
parent
commit
0e978299cf
4 changed files with 16 additions and 3 deletions
  1. +1
    -0
      NEWS
  2. +3
    -1
      borgmatic/commands/borgmatic.py
  3. +1
    -1
      borgmatic/hooks/dispatch.py
  4. +11
    -1
      tests/unit/hooks/test_dispatch.py

+ 1
- 0
NEWS View File

@@ -1,6 +1,7 @@
1.5.11.dev0
* #341: Add "temporary_directory" option for changing Borg's temporary directory.
* #352: Lock down systemd security settings in sample systemd service file.
* #355: Fix traceback when a database hook value is null in a configuration file.

1.5.10
* #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract".


+ 3
- 1
borgmatic/commands/borgmatic.py View File

@@ -658,7 +658,9 @@ def collect_configuration_run_summary_logs(configs, arguments):

if not configs:
yield from make_error_log_records(
'{}: No configuration files found'.format(' '.join(arguments['global'].config_paths))
'{}: No valid configuration files found'.format(
' '.join(arguments['global'].config_paths)
)
)
return



+ 1
- 1
borgmatic/hooks/dispatch.py View File

@@ -58,5 +58,5 @@ def call_hooks(function_name, hooks, log_prefix, hook_names, *args, **kwargs):
return {
hook_name: call_hook(function_name, hooks, log_prefix, hook_name, *args, **kwargs)
for hook_name in hook_names
if hook_name in hooks
if hooks.get(hook_name)
}

+ 11
- 1
tests/unit/hooks/test_dispatch.py View File

@@ -58,7 +58,7 @@ def test_call_hooks_calls_each_hook_and_collects_return_values():
assert return_values == expected_return_values


def test_call_hooks_calls_skips_return_values_for_unconfigured_hooks():
def test_call_hooks_calls_skips_return_values_for_missing_hooks():
hooks = {'super_hook': flexmock()}
expected_return_values = {'super_hook': flexmock()}
flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook'])
@@ -66,3 +66,13 @@ def test_call_hooks_calls_skips_return_values_for_unconfigured_hooks():
return_values = module.call_hooks('do_stuff', hooks, 'prefix', ('super_hook', 'other_hook'), 55)

assert return_values == expected_return_values


def test_call_hooks_calls_skips_return_values_for_null_hooks():
hooks = {'super_hook': flexmock(), 'other_hook': None}
expected_return_values = {'super_hook': flexmock()}
flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook'])

return_values = module.call_hooks('do_stuff', hooks, 'prefix', ('super_hook', 'other_hook'), 55)

assert return_values == expected_return_values

Loading…
Cancel
Save