Skip to content

Commit

Permalink
Merge pull request #56 from kytos-ng/fix/graph_updates_2022.3.1
Browse files Browse the repository at this point in the history
[release 2022.3.1] fix:  replaced `kytos/topology.links.metadata.(added|removed)` with `kytos/topology.updated`
  • Loading branch information
viniarck committed Jul 11, 2023
2 parents 8d27957 + 1b1ea28 commit 767d0ef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 79 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ All notable changes to the pathfinder NApp will be documented in this file.
[UNRELEASED] - Under development
********************************

[2022.3.1] - 2022-07-06
***********************

Removed
=======
- Removed ``on_links_metadata_changed`` and topology reconciliation

Changed
=======

- link metadata changes will be updated via ``kytos/topology.updated``

[2022.3.0] - 2022-12-15
***********************

Expand Down
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Subscribed

- ``kytos/topology.topology_loaded``
- ``kytos/topology.updated``
- ``kytos/topology.links.metadata.(added|removed)``

.. TAGs
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": "pathfinder",
"description": "Keeps track of topology changes, and calculates the best path between two points.",
"version": "2022.3.0",
"version": "2022.3.1",
"napp_dependencies": ["kytos/topology"],
"license": "MIT",
"tags": ["pathfinder", "rest", "work-in-progress"],
Expand Down
29 changes: 1 addition & 28 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Generator

from flask import jsonify, request
from kytos.core import KytosEvent, KytosNApp, log, rest
from kytos.core import KytosNApp, log, rest
from kytos.core.helpers import listen_to
from napps.kytos.pathfinder.graph import KytosGraph
# pylint: disable=import-error
Expand Down Expand Up @@ -225,7 +225,6 @@ def shortest_path(self):

@listen_to(
"kytos.topology.updated",
"kytos/topology.current",
"kytos/topology.topology_loaded",
)
def on_topology_updated(self, event):
Expand All @@ -249,29 +248,3 @@ def update_topology(self, event):
switches = list(topology.switches.keys())
links = list(topology.links.keys())
log.debug(f"Topology graph updated with switches: {switches}, links: {links}.")

def update_links_metadata_changed(self, event) -> None:
"""Update the graph when links' metadata are added or removed."""
link = event.content["link"]
try:
with self._lock:
if (
link.id in self._links_updated_at
and self._links_updated_at[link.id] > event.timestamp
):
return
self.graph.update_link_metadata(link)
self._links_updated_at[link.id] = event.timestamp
metadata = event.content["metadata"]
log.debug(f"Topology graph updated link id: {link.id} metadata: {metadata}")
except KeyError as exc:
log.warning(
f"Unexpected KeyError {str(exc)} on event {event}."
" pathfinder will reconciliate the topology"
)
self.controller.buffers.app.put(KytosEvent(name="kytos/topology.get"))

@listen_to("kytos/topology.links.metadata.(added|removed)")
def on_links_metadata_changed(self, event):
"""Update the graph when links' metadata are added or removed."""
self.update_links_metadata_changed(event)
49 changes: 0 additions & 49 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,55 +282,6 @@ def setting_path(self):
)
self.napp.update_topology(event)

def test_update_links_changed(self):
"""Test update_links_metadata_changed."""
self.napp.graph.update_link_metadata = MagicMock()
self.napp.controller.buffers.app.put = MagicMock()
event = KytosEvent(
name="kytos.topology.links.metadata.added",
content={"link": MagicMock(), "metadata": {}}
)
self.napp.update_links_metadata_changed(event)
assert self.napp.graph.update_link_metadata.call_count == 1
assert self.napp.controller.buffers.app.put.call_count == 0

def test_update_links_changed_out_of_order(self):
"""Test update_links_metadata_changed out of order."""
self.napp.graph.update_link_metadata = MagicMock()
self.napp.controller.buffers.app.put = MagicMock()
link = MagicMock(id="1")
assert link.id not in self.napp._links_updated_at
event = KytosEvent(
name="kytos.topology.links.metadata.added",
content={"link": link, "metadata": {}}
)
self.napp.update_links_metadata_changed(event)
assert self.napp.graph.update_link_metadata.call_count == 1
assert self.napp.controller.buffers.app.put.call_count == 0
assert self.napp._links_updated_at[link.id] == event.timestamp

second_event = KytosEvent(
name="kytos.topology.links.metadata.added",
content={"link": link, "metadata": {}}
)
second_event.timestamp = event.timestamp - timedelta(seconds=10)
self.napp.update_links_metadata_changed(second_event)
assert self.napp.graph.update_link_metadata.call_count == 1
assert self.napp.controller.buffers.app.put.call_count == 0
assert self.napp._links_updated_at[link.id] == event.timestamp

def test_update_links_changed_key_error(self):
"""Test update_links_metadata_changed key_error."""
self.napp.graph.update_link_metadata = MagicMock()
self.napp.controller.buffers.app.put = MagicMock()
event = KytosEvent(
name="kytos.topology.links.metadata.added",
content={"link": MagicMock()}
)
self.napp.update_links_metadata_changed(event)
assert self.napp.graph.update_link_metadata.call_count == 1
assert self.napp.controller.buffers.app.put.call_count == 1

def test_shortest_path(self):
"""Test shortest path."""
self.setting_path()
Expand Down

0 comments on commit 767d0ef

Please sign in to comment.