Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: registered status_reason hook for link liveness #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Added
=====
- ``LIVENESS_MIN_HELLOS_UP = 2`` is now supported on settings to configure the number of minimum liveness hellos expected before considering ``up``. This is to contribute to stability before considering it ``up``. If ``LIVENESS_MIN_HELLOS_UP = 1`` then it means the old behavior where a single hello received on both ends would transition to ``up``.

Fixed
=====
- Registered ``status_reason`` hook for link liveness

[2024.1.0] - 2024-07-23
***********************

Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def setup(self):
self.liveness_manager = LivenessManager(self.controller)
Link.register_status_func(f"{self.napp_id}_liveness",
LivenessManager.link_status_hook_liveness)
status_reason_func = LivenessManager.link_status_reason_hook_liveness
Link.register_status_reason_func(f"{self.napp_id}_liveness",
status_reason_func)
self.table_group = {"base": 0}

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions managers/liveness.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def link_status_hook_liveness(cls, link) -> Optional[EntityStatus]:
return EntityStatus.DOWN
return None

@classmethod
def link_status_reason_hook_liveness(cls, link) -> frozenset[str]:
"""Link status reason hook liveness."""
if cls.link_status_hook_liveness(link) == EntityStatus.DOWN:
return frozenset({"liveness"})
return frozenset()

def is_enabled(self, *interfaces) -> bool:
"""Check if liveness is enabled on an interface."""
for interface in interfaces:
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_liveness_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ def test_link_status_hook_liveness(self, liveness_manager) -> None:
status = liveness_manager.link_status_hook_liveness(mock_link)
assert status is None

def test_link_status_reason_hook_liveness(self, liveness_manager) -> None:
"""Test link_status_reason_hook_liveness."""
mock_link = MagicMock()
mock_link.is_active.return_value = True
mock_link.is_enabled.return_value = True
mock_link.metadata = {"liveness_status": "down"}
status = liveness_manager.link_status_reason_hook_liveness(mock_link)
assert status == frozenset({"liveness"})

mock_link.metadata = {"liveness_status": "up"}
status = liveness_manager.link_status_reason_hook_liveness(mock_link)
assert status == frozenset()

def test_try_to_publish_lsm_event(
self, liveness_manager, intf_one, intf_two
) -> None:
Expand Down