Skip to content

Commit

Permalink
Merge branch 'upgrade/python' of https://github.com/kytos-ng/topology
Browse files Browse the repository at this point in the history
…into upgrade/python
  • Loading branch information
Alopalao committed Mar 28, 2024
2 parents 856a26b + e50d3b4 commit e5e2ea2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Removed
Fixed
=====
- An interface cannot be enabled if its switch is disabled.
- Handled deactivated interfaces when an interface gets created.
- Allowed interface speed to be null on ``switches`` collection

Security
========
Expand Down
2 changes: 1 addition & 1 deletion db/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InterfaceSubDoc(BaseModel):
id: str
enabled: bool
mac: str
speed: float
speed: Optional[float]
port_number: int
name: str
nni: bool = False
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": "2023.1.0",
"version": "2023.2.0",
"napp_dependencies": ["kytos/of_core", "kytos/of_lldp"],
"license": "MIT",
"tags": ["topology", "rest"],
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,9 @@ def handle_interface_created(self, event):
"""
interface = event.content['interface']
if not interface.is_active():
return
self.handle_interface_link_up(interface, event)
self.handle_interface_link_down(interface, event)
else:
self.handle_interface_link_up(interface, event)

@listen_to('.*.topology.switch.interface.created')
def on_interface_created(self, event):
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ def test_switch_doc_preset_interfaces() -> None:
assert interface_id == model.interfaces[0].id


def test_switch_doc_preset_interfaces_speed_none() -> None:
"""test_switch_doc_preset_interfaces speed none."""
dpid = "00:00:00:00:00:00:00:01"
interface_id = f"{dpid}:1"
interfaces = {
interface_id: {
"id": interface_id,
"port_number": 1,
"lldp": True,
"enabled": True,
"active": True,
"mac": "some_mac",
"speed": None,
"name": "some_name",
"switch": dpid,
}
}
payload = {
"_id": dpid,
"enabled": True,
"active": True,
"interfaces": interfaces,
}
model = SwitchDoc(**payload)
assert model
assert interface_id == model.interfaces[0].id
assert model.interfaces[0].speed is None


def test_switch_doc_no_preset_interfaces() -> None:
"""test_switch_doc_no_preset_interfaces."""
dpid = "00:00:00:00:00:00:00:01"
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,18 +1184,22 @@ def test_handle_connection_lost(self, mock_notify_topology_update):
self.napp.handle_connection_lost(mock_event)
mock_notify_topology_update.assert_called()

@patch('napps.kytos.topology.main.Main.handle_interface_link_down')
@patch('napps.kytos.topology.main.Main.handle_interface_link_up')
def test_handle_interface_created(self, mock_link_up):
def test_handle_interface_created(self, mock_link_up, mock_link_down):
"""Test handle_interface_created."""
mock_event = MagicMock()
mock_interface = create_autospec(Interface)
mock_interface.id = "1"
mock_event.content = {'interface': mock_interface}
self.napp.handle_interface_created(mock_event)
mock_link_up.assert_called()
mock_link_down.assert_not_called()

@patch('napps.kytos.topology.main.Main.handle_interface_link_down')
@patch('napps.kytos.topology.main.Main.handle_interface_link_up')
def test_handle_interface_created_inactive(self, mock_link_up):
def test_handle_interface_created_inactive(self, mock_link_up,
mock_link_down):
"""Test handle_interface_created inactive."""
mock_event = MagicMock()
mock_interface = create_autospec(Interface)
Expand All @@ -1204,6 +1208,7 @@ def test_handle_interface_created_inactive(self, mock_link_up):
mock_interface.is_active.return_value = False
self.napp.handle_interface_created(mock_event)
mock_link_up.assert_not_called()
mock_link_down.assert_called()

def test_handle_interfaces_created(self):
"""Test handle_interfaces_created."""
Expand Down

0 comments on commit e5e2ea2

Please sign in to comment.