Skip to content

Commit

Permalink
Merge pull request #112 from kytos-ng/feature/event_current_topology
Browse files Browse the repository at this point in the history
[Feature] Added event to publish the current topology when requested
  • Loading branch information
viniarck committed Nov 4, 2022
2 parents 95e5791 + 6e0dacd commit 7054ad7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ All notable changes to the ``topology`` project will be documented in this file.

[UNRELEASED] - Under development
********************************

Added
=====
- Publish event ``kytos/topology.current`` for topology reconciliation
- Subscribed to event ``kytos/topology.get`` to publish the current topology

Changed
=======
Expand Down
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Subscribed
- ``kytos/maintenance.end_switch``
- ``kytos/.*.liveness.(up|down)``
- ``kytos/.*.liveness.disabled``
- ``kytos/topology.get``


Published
Expand Down Expand Up @@ -91,6 +92,20 @@ topology.

Content:

.. code-block:: python3
{
'topology': <Topology object>
}
kytos/topology.current
~~~~~~~~~~~~~~~~~~~~~~

Event reporting the current topology, this is meant as a broadcast response when
a subscriber needs it for reconciliation.

Content:

.. code-block:: python3
{
Expand Down
12 changes: 12 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,18 @@ def delete_link_metadata(self, link_id, key):
self.notify_metadata_changes(link, 'removed')
return jsonify("Operation successful"), 200

def notify_current_topology(self) -> None:
"""Notify current topology."""
name = "kytos/topology.current"
event = KytosEvent(name=name, content={"topology":
self._get_topology()})
self.controller.buffers.app.put(event)

@listen_to("kytos/topology.get")
def on_get_topology(self, _event) -> None:
"""Handle kytos/topology.get."""
self.notify_current_topology()

@listen_to("kytos/.*.liveness.(up|down)")
def on_link_liveness_status(self, event) -> None:
"""Handle link liveness up|down status event."""
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_get_event_listeners(self):
'kytos/.*.link_available_tags',
'kytos/.*.liveness.(up|down)',
'kytos/.*.liveness.disabled',
'kytos/topology.get',
'.*.topo_controller.upsert_switch',
'.*.of_lldp.network_status.updated',
'.*.interface.is.nni',
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_get_event_listeners(self):
'.*.switch.(new|reconnected)',
'kytos/.*.liveness.(up|down)',
'kytos/.*.liveness.disabled',
'kytos/topology.get',
'.*.switch.port.created']
actual_events = self.napp.listeners()
self.assertCountEqual(expected_events, actual_events)
Expand Down Expand Up @@ -1373,6 +1374,16 @@ def test_notify_topology_update(self, *args):
mock_event.assert_called()
mock_buffers_put.assert_called()

@patch('kytos.core.buffers.KytosEventBuffer.put')
def test_notify_current_topology(self, mock_buffers_put):
"""Test notify_current_topology."""
self.napp.notify_current_topology()
mock_buffers_put.assert_called()
args = mock_buffers_put.call_args
expected_event = args[0][0]
assert expected_event.name == "kytos/topology.current"
assert "topology" in expected_event.content

@patch('napps.kytos.topology.main.KytosEvent')
@patch('kytos.core.buffers.KytosEventBuffer.put')
def test_notify_link_status_change(self, *args):
Expand Down

0 comments on commit 7054ad7

Please sign in to comment.