From bfbfef8d441ad8432ffd2625ba6bf9fc7908b283 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Thu, 15 Feb 2024 17:48:49 -0300 Subject: [PATCH 1/6] release: bumped 2023.2.0 --- CHANGELOG.rst | 3 +++ kytos.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de01d9b..1bc2473 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,9 @@ All notable changes to the ``topology`` project will be documented in this file. [UNRELEASED] - Under development ******************************** +[2023.2.0] - 2024-02-16 +*********************** + Added ===== - Added endpoint ``POST v3/interfaces/{interface_id}/tag_ranges`` to set ``tag_ranges`` to interfaces. 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"], From 9de1c506ae9298b2e46470024eca45ca154cba74 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Fri, 1 Mar 2024 14:27:54 -0300 Subject: [PATCH 2/6] fix: also handled interface_link_down when an interface is created --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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): From 691bd3812ba597c95434fa372611a24e4619467e Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Fri, 1 Mar 2024 14:30:11 -0300 Subject: [PATCH 3/6] test: covered with unit test --- tests/unit/test_main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index fa87b77..c16612a 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.""" From 96a550a4b43828def821a83eeb1b8ef3c46c7c72 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Fri, 1 Mar 2024 14:31:34 -0300 Subject: [PATCH 4/6] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de01d9b..e8290cd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -33,6 +33,7 @@ Removed Fixed ===== - An interface cannot be enabled if its switch is disabled. +- Handled deactivated interfaces when an interface gets created. Security ======== From d1a3aea802e55c7b5ed9025f6c1a69aac3ef9516 Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Tue, 5 Mar 2024 13:16:41 -0300 Subject: [PATCH 5/6] fix:allowed interface speed to be null on switches collection --- db/models/__init__.py | 2 +- tests/unit/test_db_models.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/db/models/__init__.py b/db/models/__init__.py index 5684687..f127231 100644 --- a/db/models/__init__.py +++ b/db/models/__init__.py @@ -31,7 +31,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/tests/unit/test_db_models.py b/tests/unit/test_db_models.py index cf43c94..12a30e9 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" From 01ae7bcde1941a1d9245da8a5acbde6af99d2e9e Mon Sep 17 00:00:00 2001 From: Vinicius Arcanjo Date: Tue, 5 Mar 2024 13:16:49 -0300 Subject: [PATCH 6/6] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e8290cd..1b0cc96 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -34,6 +34,7 @@ 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 ========