diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 477473f..9250755 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ======== diff --git a/db/models/__init__.py b/db/models/__init__.py index b424160..575c90f 100644 --- a/db/models/__init__.py +++ b/db/models/__init__.py @@ -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 diff --git a/kytos.json b/kytos.json index ea3ea46..0340a02 100644 --- a/kytos.json +++ b/kytos.json @@ -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"], diff --git a/main.py b/main.py index 1aaa3ca..a0e1c9b 100644 --- a/main.py +++ b/main.py @@ -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): diff --git a/tests/unit/test_db_models.py b/tests/unit/test_db_models.py index 22a80b3..caf3a01 100644 --- a/tests/unit/test_db_models.py +++ b/tests/unit/test_db_models.py @@ -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" diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 985be39..289e83b 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -1184,8 +1184,9 @@ 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) @@ -1193,9 +1194,12 @@ def test_handle_interface_created(self, mock_link_up): 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) @@ -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."""