|
|
|
@ -112,7 +112,7 @@ def test_run_configuration_logs_actions_error():
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module.dispatch).should_receive('call_hooks')
|
|
|
|
|
expected_results = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError)
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False)}
|
|
|
|
@ -127,7 +127,7 @@ def test_run_configuration_logs_pre_hook_error():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_raise(OSError).and_return(None)
|
|
|
|
|
expected_results = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('run_actions').never()
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
@ -142,7 +142,7 @@ def test_run_configuration_bails_for_pre_hook_soft_failure():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_raise(error).and_return(None)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').never()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').never()
|
|
|
|
|
flexmock(module).should_receive('run_actions').never()
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
@ -160,7 +160,7 @@ def test_run_configuration_logs_post_hook_error():
|
|
|
|
|
).and_return(None)
|
|
|
|
|
flexmock(module.dispatch).should_receive('call_hooks')
|
|
|
|
|
expected_results = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_return([])
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
@ -178,7 +178,7 @@ def test_run_configuration_bails_for_post_hook_soft_failure():
|
|
|
|
|
error
|
|
|
|
|
).and_return(None)
|
|
|
|
|
flexmock(module.dispatch).should_receive('call_hooks')
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').never()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').never()
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_return([])
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
@ -193,7 +193,7 @@ def test_run_configuration_logs_on_error_hook_error():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_raise(OSError)
|
|
|
|
|
expected_results = [flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(
|
|
|
|
|
expected_results[:1]
|
|
|
|
|
).and_return(expected_results[1:])
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError)
|
|
|
|
@ -211,7 +211,7 @@ def test_run_configuration_bails_for_on_error_hook_soft_failure():
|
|
|
|
|
error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_return(None).and_raise(error)
|
|
|
|
|
expected_results = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_results)
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError)
|
|
|
|
|
config = {'location': {'repositories': ['foo']}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
@ -227,12 +227,11 @@ def test_run_configuration_retries_soft_error():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).and_return([])
|
|
|
|
|
expected_results = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_results).once()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return([flexmock()]).once()
|
|
|
|
|
config = {'location': {'repositories': ['foo']}, 'storage': {'retries': 1}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_configuration_retries_hard_error():
|
|
|
|
@ -241,18 +240,20 @@ def test_run_configuration_retries_hard_error():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).times(2)
|
|
|
|
|
expected_results = [flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[:1]).with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(
|
|
|
|
|
expected_results[1:]
|
|
|
|
|
).twice()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()])
|
|
|
|
|
error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError,
|
|
|
|
|
).and_return(error_logs)
|
|
|
|
|
config = {'location': {'repositories': ['foo']}, 'storage': {'retries': 1}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == error_logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_repos_ordered():
|
|
|
|
@ -261,10 +262,10 @@ def test_run_repos_ordered():
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).times(2)
|
|
|
|
|
expected_results = [flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[:1]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[1:]).ordered()
|
|
|
|
|
config = {'location': {'repositories': ['foo', 'bar']}}
|
|
|
|
@ -278,23 +279,30 @@ def test_run_configuration_retries_round_robbin():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).times(4)
|
|
|
|
|
expected_results = [flexmock(), flexmock(), flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
foo_error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[0:1]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
).and_return(foo_error_logs).ordered()
|
|
|
|
|
bar_error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[1:2]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[2:3]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[3:4]).ordered()
|
|
|
|
|
).and_return(bar_error_logs).ordered()
|
|
|
|
|
config = {'location': {'repositories': ['foo', 'bar']}, 'storage': {'retries': 1}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == foo_error_logs + bar_error_logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_configuration_retries_one_passes():
|
|
|
|
@ -304,20 +312,26 @@ def test_run_configuration_retries_one_passes():
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return(
|
|
|
|
|
[]
|
|
|
|
|
).and_raise(OSError).times(4)
|
|
|
|
|
expected_results = [flexmock(), flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[0:1]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[1:2]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return(flexmock()).ordered()
|
|
|
|
|
error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[2:3]).ordered()
|
|
|
|
|
).and_return(error_logs).ordered()
|
|
|
|
|
config = {'location': {'repositories': ['foo', 'bar']}, 'storage': {'retries': 1}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == error_logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_configuration_retry_wait():
|
|
|
|
@ -325,29 +339,38 @@ def test_run_configuration_retry_wait():
|
|
|
|
|
flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook')
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).times(4)
|
|
|
|
|
expected_results = [flexmock(), flexmock(), flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[0:1]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
|
|
|
|
|
flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[1:2]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
|
|
|
|
|
flexmock(time).should_receive('sleep').with_args(20).and_return().ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[2:3]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
|
|
|
|
|
flexmock(time).should_receive('sleep').with_args(30).and_return().ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[3:4]).ordered()
|
|
|
|
|
).and_return(error_logs).ordered()
|
|
|
|
|
config = {'location': {'repositories': ['foo']}, 'storage': {'retries': 3, 'retry_wait': 10}}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == error_logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_configuration_retries_timeout_multiple_repos():
|
|
|
|
@ -357,29 +380,35 @@ def test_run_configuration_retries_timeout_multiple_repos():
|
|
|
|
|
flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return(
|
|
|
|
|
[]
|
|
|
|
|
).and_raise(OSError).times(4)
|
|
|
|
|
expected_results = [flexmock(), flexmock(), flexmock()]
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[0:1]).ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[1:2]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'foo: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository',
|
|
|
|
|
OSError,
|
|
|
|
|
levelno=logging.WARNING,
|
|
|
|
|
log_command_error_output=True,
|
|
|
|
|
).and_return([flexmock()]).ordered()
|
|
|
|
|
|
|
|
|
|
# Sleep before retrying foo (and passing)
|
|
|
|
|
flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
|
|
|
|
|
|
# Sleep before retrying bar (and failing)
|
|
|
|
|
flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').with_args(
|
|
|
|
|
error_logs = [flexmock()]
|
|
|
|
|
flexmock(module).should_receive('log_error_records').with_args(
|
|
|
|
|
'bar: Error running actions for repository', OSError
|
|
|
|
|
).and_return(expected_results[2:3]).ordered()
|
|
|
|
|
).and_return(error_logs).ordered()
|
|
|
|
|
config = {
|
|
|
|
|
'location': {'repositories': ['foo', 'bar']},
|
|
|
|
|
'storage': {'retries': 1, 'retry_wait': 10},
|
|
|
|
|
}
|
|
|
|
|
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
|
assert results == expected_results
|
|
|
|
|
assert results == error_logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_load_configurations_collects_parsed_configurations():
|
|
|
|
@ -421,48 +450,46 @@ def test_log_record_with_suppress_does_not_raise():
|
|
|
|
|
module.log_record(levelno=1, foo='bar', baz='quux', suppress_log=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_error_log_records_generates_output_logs_for_message_only():
|
|
|
|
|
def test_log_error_records_generates_output_logs_for_message_only():
|
|
|
|
|
flexmock(module).should_receive('log_record').replace_with(dict)
|
|
|
|
|
|
|
|
|
|
logs = tuple(module.make_error_log_records('Error'))
|
|
|
|
|
logs = tuple(module.log_error_records('Error'))
|
|
|
|
|
|
|
|
|
|
assert {log['levelno'] for log in logs} == {logging.CRITICAL}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_error_log_records_generates_output_logs_for_called_process_error():
|
|
|
|
|
def test_log_error_records_generates_output_logs_for_called_process_error():
|
|
|
|
|
flexmock(module).should_receive('log_record').replace_with(dict)
|
|
|
|
|
flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
|
module.make_error_log_records(
|
|
|
|
|
'Error', subprocess.CalledProcessError(1, 'ls', 'error output')
|
|
|
|
|
)
|
|
|
|
|
module.log_error_records('Error', subprocess.CalledProcessError(1, 'ls', 'error output'))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert {log['levelno'] for log in logs} == {logging.CRITICAL}
|
|
|
|
|
assert any(log for log in logs if 'error output' in str(log))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_error_log_records_generates_logs_for_value_error():
|
|
|
|
|
def test_log_error_records_generates_logs_for_value_error():
|
|
|
|
|
flexmock(module).should_receive('log_record').replace_with(dict)
|
|
|
|
|
|
|
|
|
|
logs = tuple(module.make_error_log_records('Error', ValueError()))
|
|
|
|
|
logs = tuple(module.log_error_records('Error', ValueError()))
|
|
|
|
|
|
|
|
|
|
assert {log['levelno'] for log in logs} == {logging.CRITICAL}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_error_log_records_generates_logs_for_os_error():
|
|
|
|
|
def test_log_error_records_generates_logs_for_os_error():
|
|
|
|
|
flexmock(module).should_receive('log_record').replace_with(dict)
|
|
|
|
|
|
|
|
|
|
logs = tuple(module.make_error_log_records('Error', OSError()))
|
|
|
|
|
logs = tuple(module.log_error_records('Error', OSError()))
|
|
|
|
|
|
|
|
|
|
assert {log['levelno'] for log in logs} == {logging.CRITICAL}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_error_log_records_generates_nothing_for_other_error():
|
|
|
|
|
def test_log_error_records_generates_nothing_for_other_error():
|
|
|
|
|
flexmock(module).should_receive('log_record').replace_with(dict)
|
|
|
|
|
|
|
|
|
|
logs = tuple(module.make_error_log_records('Error', KeyError()))
|
|
|
|
|
logs = tuple(module.log_error_records('Error', KeyError()))
|
|
|
|
|
|
|
|
|
|
assert logs == ()
|
|
|
|
|
|
|
|
|
@ -519,7 +546,7 @@ def test_collect_configuration_run_summary_logs_extract_with_repository_error():
|
|
|
|
|
ValueError
|
|
|
|
|
)
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
arguments = {'extract': flexmock(repository='repo')}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -546,7 +573,7 @@ def test_collect_configuration_run_summary_logs_mount_with_repository_error():
|
|
|
|
|
ValueError
|
|
|
|
|
)
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
arguments = {'mount': flexmock(repository='repo')}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -559,7 +586,7 @@ def test_collect_configuration_run_summary_logs_mount_with_repository_error():
|
|
|
|
|
def test_collect_configuration_run_summary_logs_missing_configs_error():
|
|
|
|
|
arguments = {'global': flexmock(config_paths=[])}
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
|
|
|
|
|
logs = tuple(module.collect_configuration_run_summary_logs({}, arguments=arguments))
|
|
|
|
|
|
|
|
|
@ -569,7 +596,7 @@ def test_collect_configuration_run_summary_logs_missing_configs_error():
|
|
|
|
|
def test_collect_configuration_run_summary_logs_pre_hook_error():
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_raise(ValueError)
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -583,7 +610,7 @@ def test_collect_configuration_run_summary_logs_post_hook_error():
|
|
|
|
|
flexmock(module.command).should_receive('execute_hook').and_return(None).and_raise(ValueError)
|
|
|
|
|
flexmock(module).should_receive('run_configuration').and_return([])
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -598,7 +625,7 @@ def test_collect_configuration_run_summary_logs_for_list_with_archive_and_reposi
|
|
|
|
|
ValueError
|
|
|
|
|
)
|
|
|
|
|
expected_logs = (flexmock(),)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(expected_logs)
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(expected_logs)
|
|
|
|
|
arguments = {'list': flexmock(repository='repo', archive='test')}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -624,7 +651,7 @@ def test_collect_configuration_run_summary_logs_run_configuration_error():
|
|
|
|
|
flexmock(module).should_receive('run_configuration').and_return(
|
|
|
|
|
[logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
|
|
|
|
|
)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return([])
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return([])
|
|
|
|
|
arguments = {}
|
|
|
|
|
|
|
|
|
|
logs = tuple(
|
|
|
|
@ -638,7 +665,7 @@ def test_collect_configuration_run_summary_logs_run_umount_error():
|
|
|
|
|
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
|
|
|
|
|
flexmock(module).should_receive('run_configuration').and_return([])
|
|
|
|
|
flexmock(module.borg_umount).should_receive('unmount_archive').and_raise(OSError)
|
|
|
|
|
flexmock(module).should_receive('make_error_log_records').and_return(
|
|
|
|
|
flexmock(module).should_receive('log_error_records').and_return(
|
|
|
|
|
[logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
|
|
|
|
|
)
|
|
|
|
|
arguments = {'umount': flexmock(mount_point='/mnt')}
|
|
|
|
|