add test for healthchecks
Signed-off-by: Soumik Dutta <shalearkane@gmail.com>
This commit is contained in:
parent
1573d68fe2
commit
45256ae33f
5 changed files with 28 additions and 19 deletions
|
@ -153,16 +153,17 @@ def run_configuration(config_filename, config, arguments):
|
||||||
error_repository = repository_path
|
error_repository = repository_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# send logs irrespective of error
|
if using_primary_action:
|
||||||
dispatch.call_hooks(
|
# send logs irrespective of error
|
||||||
'ping_monitor',
|
dispatch.call_hooks(
|
||||||
hooks,
|
'ping_monitor',
|
||||||
config_filename,
|
hooks,
|
||||||
monitor.MONITOR_HOOK_NAMES,
|
config_filename,
|
||||||
monitor.State.LOG,
|
monitor.MONITOR_HOOK_NAMES,
|
||||||
monitoring_log_level,
|
monitor.State.LOG,
|
||||||
global_arguments.dry_run,
|
monitoring_log_level,
|
||||||
)
|
global_arguments.dry_run,
|
||||||
|
)
|
||||||
except (OSError, CalledProcessError) as error:
|
except (OSError, CalledProcessError) as error:
|
||||||
if command.considered_soft_failure(config_filename, error):
|
if command.considered_soft_failure(config_filename, error):
|
||||||
return
|
return
|
||||||
|
|
|
@ -10,7 +10,6 @@ MONITOR_STATE_TO_CRONHUB = {
|
||||||
monitor.State.START: 'start',
|
monitor.State.START: 'start',
|
||||||
monitor.State.FINISH: 'finish',
|
monitor.State.FINISH: 'finish',
|
||||||
monitor.State.FAIL: 'fail',
|
monitor.State.FAIL: 'fail',
|
||||||
monitor.State.LOG: 'log',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ MONITOR_STATE_TO_CRONITOR = {
|
||||||
monitor.State.START: 'run',
|
monitor.State.START: 'run',
|
||||||
monitor.State.FINISH: 'complete',
|
monitor.State.FINISH: 'complete',
|
||||||
monitor.State.FAIL: 'fail',
|
monitor.State.FAIL: 'fail',
|
||||||
monitor.State.LOG: 'ok',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,6 @@ from borgmatic.hooks import monitor
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
MONITOR_STATE_TO_NTFY = {
|
|
||||||
monitor.State.START: None,
|
|
||||||
monitor.State.FINISH: None,
|
|
||||||
monitor.State.FAIL: None,
|
|
||||||
monitor.State.LOG: None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def initialize_monitor(
|
def initialize_monitor(
|
||||||
ping_url, config_filename, monitoring_log_level, dry_run
|
ping_url, config_filename, monitoring_log_level, dry_run
|
||||||
|
|
|
@ -184,6 +184,23 @@ def test_ping_monitor_hits_ping_url_for_fail_state():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ping_monitor_hits_ping_url_for_log_state():
|
||||||
|
hook_config = {'ping_url': 'https://example.com'}
|
||||||
|
payload = 'data'
|
||||||
|
flexmock(module).should_receive('format_buffered_logs_for_payload').and_return(payload)
|
||||||
|
flexmock(module.requests).should_receive('post').with_args(
|
||||||
|
'https://example.com/log', data=payload.encode('utf'), verify=True
|
||||||
|
).and_return(flexmock(ok=True))
|
||||||
|
|
||||||
|
module.ping_monitor(
|
||||||
|
hook_config,
|
||||||
|
'config.yaml',
|
||||||
|
state=module.monitor.State.LOG,
|
||||||
|
monitoring_log_level=1,
|
||||||
|
dry_run=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_ping_monitor_with_ping_uuid_hits_corresponding_url():
|
def test_ping_monitor_with_ping_uuid_hits_corresponding_url():
|
||||||
hook_config = {'ping_url': 'abcd-efgh-ijkl-mnop'}
|
hook_config = {'ping_url': 'abcd-efgh-ijkl-mnop'}
|
||||||
payload = 'data'
|
payload = 'data'
|
||||||
|
|
Loading…
Reference in a new issue