Skip to content

Commit

Permalink
Merge pull request #77 from atlanticwave-sdx/fix/setup_load
Browse files Browse the repository at this point in the history
fix: topology request during setup is blocking the MainThread, hanging until timeout
  • Loading branch information
italovalcy authored Nov 13, 2024
2 parents 0470d17 + 6627a47 commit c5d5cd2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Changed

Fixed
=====
-
- Avoid blocking setup() when loading topology
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def load_sdx_topology(self):
"version": 1,
"timestamp": get_timestamp(),
}

def load_kytos_topology(self):
"""Load topology from Kytos-ng."""
with self._topo_lock:
self._topo_dict = self.get_kytos_topology()
self._converted_topo = self.convert_topology_v2()
Expand All @@ -111,10 +114,16 @@ def get_kytos_topology():
)
return topology

@listen_to(
"kytos/topology.updated",
"kytos/topology.topology_loaded",
)
@listen_to("kytos/topology.topology_loaded")
def on_topology_loaded(self, _event: KytosEvent):
"""Handler for on topology_loaded."""
self.handler_on_topology_loaded()

def handler_on_topology_loaded(self):
"""Handler on_topology_loaded."""
self.load_kytos_topology()

@listen_to("kytos/topology.updated")
def on_topology_updated_event(self, event: KytosEvent):
"""Handler for topology updated events."""
self.handler_on_topology_updated_event(event)
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ async def test_create_l2vpn(self, requests_mock):
assert response.status_code == 201
assert response.json() == {"service_id": "a123"}

def test_handler_on_topology_loaded(self):
"""Test handler_on_topology_loaded."""
self.napp.get_kytos_topology = MagicMock()
some_topo = {"switches": {"dpid1": {}}, "links": {"link1": {}}}
self.napp.get_kytos_topology.return_value = some_topo
self.napp.convert_topology_v2 = MagicMock()
self.napp.handler_on_topology_loaded()
assert self.napp._topo_dict == some_topo

@patch("requests.post")
@patch("requests.patch")
async def test_update_l2vpn(self, req_patch_mock, req_post_mock):
Expand Down

0 comments on commit c5d5cd2

Please sign in to comment.