f-78: e2e: watchdog_quiet réussit sans alerte quand aucune exclusion n'est donnée #78

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-19 23:46:13 +02:00
commit a47af03eef
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 12 additions and 1 deletions

View file

@ -81,7 +81,8 @@ watchdog_alerts () {
watchdog_quiet () {
local out
out=$(watchdog_alerts "${1:-300}" | { if [ -n "${2:-}" ]; then grep -vF -- "${2}"; else cat; fi; }) || return 0
out=$(watchdog_alerts "${1:-300}" | { if [ -n "${2:-}" ]; then grep -vF -- "${2}"; else cat; fi; })
[ -z "${out}" ] && return 0
printf '%s\n' "${out}"
return 1
}

View file

@ -232,6 +232,16 @@ test_api_code_returns_the_http_status () {
teardown
}
test_watchdog_quiet_passes_without_alert_and_fails_on_one () {
setup "watchdog_quiet : réussit sans alerte, avec ou sans exclusion ; échoue sur une alerte non exclue"
local alert='{"level":"ERROR","msg":"watchdog: inconsistency detected","problem":"stale dhcp reservation on the server"}'
[[ $(node "journalctl () { :; }; watchdog_quiet 300 && echo OUI") == OUI ]] || fail "journal vide, sans exclusion : échec"
[[ $(node "journalctl () { :; }; watchdog_quiet 300 'stale dhcp' && echo OUI") == OUI ]] || fail "journal vide, avec exclusion : échec"
[[ $(node "journalctl () { echo '${alert}'; }; watchdog_quiet 300 >/dev/null || echo NON") == NON ]] || fail "alerte acceptée sans exclusion"
[[ $(node "journalctl () { echo '${alert}'; }; watchdog_quiet 300 'stale dhcp' && echo OUI") == OUI ]] || fail "alerte exclue refusée"
teardown
}
test_watchdog_reported_matches_only_watchdog_alerts () {
setup "watchdog_reported : alerte du watchdog contenant le texte, rien d'autre"
local alert='{"level":"ERROR","msg":"watchdog: inconsistency detected","kind":"vpc","name":"vp-s8","problem":"route 10.242.1.99/32 exported in vrf-s8 without a running owner: its traffic is black-holed"}'