From 37f1712a687d15c29e78e3a90a10657b2e883707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Karpu=C5=A1ka?= Date: Tue, 17 Dec 2024 17:21:29 +0200 Subject: [PATCH] Fix FiveTuple printing to print actual contents of dataclass instead of class type --- .unreleased/fix-fivetuple-printing | 0 nat-lab/tests/utils/connection_tracker.py | 9 ++++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .unreleased/fix-fivetuple-printing diff --git a/.unreleased/fix-fivetuple-printing b/.unreleased/fix-fivetuple-printing new file mode 100644 index 000000000..e69de29bb diff --git a/nat-lab/tests/utils/connection_tracker.py b/nat-lab/tests/utils/connection_tracker.py index 265e8489d..9715b66f4 100644 --- a/nat-lab/tests/utils/connection_tracker.py +++ b/nat-lab/tests/utils/connection_tracker.py @@ -41,6 +41,9 @@ def __hash__(self): (self.protocol, self.src_ip, self.dst_ip, self.src_port, self.dst_port) ) + def __str__(self) -> str: + return f"{self.protocol} {self.src_ip}:{self.src_port} -> {self.dst_ip}:{self.dst_port}" + class EventType(Enum): """Event type reported by conntrack""" @@ -147,7 +150,7 @@ def __init__( ): if max_limit is not None and min_limit is not None and max_limit < min_limit: raise ValueError( - f"Max limit {max_limit} is smaller then min limit {min_limit}" + f"Max limit {max_limit} is smaller than min limit {min_limit}" ) self.key = key @@ -172,12 +175,12 @@ def find_conntracker_violations( if self.max_limit is not None and count > self.max_limit: return ConnTrackerViolation( recoverable=False, - reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is more then max limit of {self.max_limit}", + reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is more than max limit of {self.max_limit}", ) if self.min_limit is not None and count < self.min_limit: return ConnTrackerViolation( recoverable=True, - reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is less then min limit of {self.min_limit}", + reason=f"In {self.key} there has been {count} connections to {FiveTuple} which is less than min limit of {self.min_limit}", ) return None