Skip to content

Commit

Permalink
Merge pull request #212 from kytos-ng/refactor/dynamic_single_interru…
Browse files Browse the repository at this point in the history
…ptions

Changed interruptions to use dynamic_single for handling
  • Loading branch information
Ktmi authored Sep 13, 2024
2 parents 2e6031e + fa8e7f9 commit 10fad8f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ All notable changes to the ``topology`` project will be documented in this file.
[UNRELEASED] - Under development
********************************

[2024.1.3] - 2024-09-13
***********************

Changed
=======
- Combined ``interruption.start`` and ``interruption.end`` handlers to use a single event ``interruption.(start|end)`` handler. The new handler is also uses the ``dynamic_single`` pool when processing events to ensure in order processing.

[2024.1.2] - 2024-09-10
***********************

Expand Down
2 changes: 1 addition & 1 deletion kytos.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"username": "kytos",
"name": "topology",
"description": "Manage the network topology.",
"version": "2024.1.2",
"version": "2024.1.3",
"napp_dependencies": ["kytos/of_core", "kytos/of_lldp"],
"license": "MIT",
"tags": ["topology", "rest"],
Expand Down
21 changes: 11 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,11 +1402,18 @@ def load_interfaces_tags_values(switch: Switch,
interface_details['special_tags'],
)

@listen_to('topology.interruption.start')
def on_interruption_start(self, event: KytosEvent):
"""Deals with the start of service interruption."""
@listen_to(
'topology.interruption.(start|end)',
pool="dynamic_single"
)
def on_interruption(self, event: KytosEvent):
"""Deals with service interruptions."""
with self._links_lock:
self.handle_interruption_start(event)
_, _, interrupt_type = event.name.rpartition(".")
if interrupt_type == "start":
self.handle_interruption_start(event)
elif interrupt_type == "end":
self.handle_interruption_end(event)

def handle_interruption_start(self, event: KytosEvent):
"""Deals with the start of service interruption."""
Expand Down Expand Up @@ -1438,12 +1445,6 @@ def handle_interruption_start(self, event: KytosEvent):
self.notify_link_status_change(link, interrupt_type)
self.notify_topology_update()

@listen_to('topology.interruption.end')
def on_interruption_end(self, event: KytosEvent):
"""Deals with the end of service interruption."""
with self._links_lock:
self.handle_interruption_end(event)

def handle_interruption_end(self, event: KytosEvent):
"""Deals with the end of service interruption."""
interrupt_type = event.content['type']
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def test_get_event_listeners(self):
'.*.switch.(new|reconnected)',
'.*.switch.port.created',
'kytos/topology.notify_link_up_if_status',
'topology.interruption.start',
'topology.interruption.end',
'topology.interruption.(start|end)',
'kytos/core.interface_tags',
]
assert sorted(expected_events) == sorted(actual_events)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def test_get_event_listeners(self):
'kytos/.*.liveness.disabled',
'.*.switch.port.created',
'kytos/topology.notify_link_up_if_status',
'topology.interruption.start',
'topology.interruption.end',
'topology.interruption.(start|end)',
'kytos/core.interface_tags',
]
actual_events = self.napp.listeners()
Expand Down

0 comments on commit 10fad8f

Please sign in to comment.