Skip to content

Commit

Permalink
Ensure unflap doesn't crash on unknown interface
Browse files Browse the repository at this point in the history
The submitted interface argument may not have any flap stats, but
there is no need for the implementation to crash if it doesn't.  It's
safe to quietly ignore it, as this means the interface is already
"unflapped".
  • Loading branch information
lunkwill42 committed Jul 3, 2024
1 parent ab5eee4 commit a7ff2da
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/zino/flaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def first_flap(self, interface: PortIndex) -> FlappingState:
self.interfaces[interface] = flap
return flap

def unflap(self, interface: PortIndex) -> FlappingState:
"""Removes all flapping stats tracking for a port"""
return self.interfaces.pop(interface)
def unflap(self, interface: PortIndex) -> Optional[FlappingState]:
"""Removes all flapping stats tracking for a port, if they exist"""
return self.interfaces.pop(interface, None)

def is_flapping(self, interface: PortIndex) -> bool:
"""Returns True if the current stats indicate that the interface has crossed the flapping threshold.
Expand Down

0 comments on commit a7ff2da

Please sign in to comment.