fix: never park the last present family as absent
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uc9V1v7iXruubpoLiSE24M
This commit is contained in:
@@ -92,3 +92,29 @@ def test_presence_survives_pickle_and_old_pickles_get_default():
|
||||
del h2.__dict__["presence"] # simulate a pre-feature pickle
|
||||
h2.fixup()
|
||||
assert h2.presence == {}
|
||||
|
||||
|
||||
def _all_absent(name, s4, s6=None):
|
||||
h = _host(name)
|
||||
_conn(h, "IPv4", s4)
|
||||
h.set_presence("IPv4", False, time.time())
|
||||
if s6 is not None:
|
||||
_conn(h, "IPv6", s6)
|
||||
h.set_presence("IPv6", False, time.time())
|
||||
return h
|
||||
|
||||
|
||||
def test_all_absent_single_family_overdue_is_overdue():
|
||||
assert _all_absent("abs-single", C.OVERDUE).status() == "overdue"
|
||||
|
||||
|
||||
def test_all_absent_dual_stack_one_absent_one_overdue_is_overdue():
|
||||
assert _all_absent("abs-dual-od", C.ABSENT, C.OVERDUE).status() == "overdue"
|
||||
|
||||
|
||||
def test_all_absent_dual_stack_v6_up_is_up():
|
||||
assert _all_absent("abs-dual-up", C.ABSENT, C.UP).status() == "up"
|
||||
|
||||
|
||||
def test_all_absent_all_unknown_is_unknown():
|
||||
assert _all_absent("abs-unknown", C.UNKNOWN, C.UNKNOWN).status() == "unknown"
|
||||
|
||||
@@ -217,3 +217,34 @@ def test_v4_only_host_overdue_is_single_critical(monkeypatch):
|
||||
assert "connectivity.IPv4" in h.alert_states
|
||||
asyncio.run(on_overdue(h.connections["IPv4"]))
|
||||
assert len([e for e in events if e[0] == "CRITICAL"]) == 1
|
||||
|
||||
|
||||
def test_all_families_absent_v4_only_host_still_alerts_when_it_dies(monkeypatch):
|
||||
events = _events(monkeypatch)
|
||||
ctx = _ctx()
|
||||
_fresh("pres-allabsent")
|
||||
_send("pres-allabsent", "127.0.0.1", ctx, p4=0)
|
||||
h = hbdclass.Host.hosts["pres-allabsent"]
|
||||
on_overdue, _ = udp._make_timer_callbacks("pres-allabsent", h, ctx)
|
||||
asyncio.run(on_overdue(h.connections["IPv4"]))
|
||||
assert [e for e in events if e[0] == "CRITICAL"] == [("CRITICAL", "IPv4 overdue")]
|
||||
assert h.connections["IPv4"].state == C.OVERDUE
|
||||
assert h.status() == "overdue"
|
||||
assert "connectivity.IPv4" in h.alert_states
|
||||
|
||||
|
||||
def test_last_present_family_is_not_parked_when_other_is_absent(monkeypatch):
|
||||
events = _events(monkeypatch)
|
||||
ctx = _ctx()
|
||||
h = _dual_stack("pres-lastfam", ctx)
|
||||
_send("pres-lastfam", "127.0.0.1", ctx, p4=0, p6=0)
|
||||
events.clear()
|
||||
on_overdue, _ = udp._make_timer_callbacks("pres-lastfam", h, ctx)
|
||||
asyncio.run(on_overdue(h.connections["IPv4"]))
|
||||
assert h.connections["IPv4"].state == C.ABSENT
|
||||
assert not any(level == "CRITICAL" for level, _ in events)
|
||||
assert h.status() == "up"
|
||||
asyncio.run(on_overdue(h.connections["IPv6"]))
|
||||
assert [e for e in events if e[0] == "CRITICAL"] == [("CRITICAL", "IPv6 overdue")]
|
||||
assert h.connections["IPv6"].state == C.OVERDUE
|
||||
assert h.status() == "overdue"
|
||||
|
||||
Reference in New Issue
Block a user