From 1ac39684ccc86d193843db5cd76127f14497f79d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 14 Nov 2024 17:39:42 -0600 Subject: [PATCH 1/7] Add a test for issue #356 --- sdx_controller/test/__init__.py | 4 ++ sdx_controller/test/test_l2vpn_controller.py | 42 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/sdx_controller/test/__init__.py b/sdx_controller/test/__init__.py index c703327..90ecf8f 100644 --- a/sdx_controller/test/__init__.py +++ b/sdx_controller/test/__init__.py @@ -42,3 +42,7 @@ class TestData: CONNECTION_REQ_V2_AMLIGHT_ZAOXI = ( REQUESTS_DIR / "test_request-amlight_zaoxi-p2p-v2.json" ) + + TOPOLOGY_FILE_AMLIGHT_v2 = TOPOLOGY_DIR / "ampath_v2.json" + TOPOLOGY_FILE_SAX_v2 = TOPOLOGY_DIR / "sax_v2.json" + TOPOLOGY_FILE_ZAOXI_v2 = TOPOLOGY_DIR / "zaoxi_v2.json" diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 590483d..23d3760 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -48,6 +48,21 @@ def __add_the_three_topologies(self): print(f"Adding topology: {topology.get('id')}") self.te_manager.add_topology(topology) + def __add_the_three_v2_topologies(self): + """ + A helper to add the three known topologies. + """ + for idx, topology_file in enumerate( + [ + TestData.TOPOLOGY_FILE_AMLIGHT_v2, + TestData.TOPOLOGY_FILE_SAX_v2, + TestData.TOPOLOGY_FILE_ZAOXI_v2, + ] + ): + topology = json.loads(topology_file.read_text()) + print(f"Adding topology: {topology.get('id')}") + self.te_manager.add_topology(topology) + def test_delete_connection_with_setup(self): """ Test case for delete_connection() @@ -569,6 +584,33 @@ def test_z105_getconnections_success(self): assert len(response.get_json()) != 0 + def test_issue_356(self): + """ + See https://github.com/atlanticwave-sdx/sdx-controller/issues/356 + """ + + self.__add_the_three_v2_topologies() + + connection_request = { + "name": "VLAN between AMPATH/300 and TENET/300", + "endpoints": [ + {"port_id": "urn:sdx:port:ampath.net:Ampath3:50", "vlan": "300"}, + {"port_id": "urn:sdx:port:tenet.ac.za:Tenet03:50", "vlan": "any"}, + ], + } + + response = self.client.open( + f"{BASE_PATH}/l2vpn/1.0", + method="POST", + data=json.dumps(connection_request), + content_type="application/json", + ) + + print(f"POST response body is : {response.data.decode('utf-8')}") + print(f"POST Response JSON is : {response.get_json()}") + + # self.assertStatus(response, 200) + if __name__ == "__main__": unittest.main() From 7af6548a43e240b1d02db85dac31b169a57191fb Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:14:01 -0600 Subject: [PATCH 2/7] Use pce 3.0.0.dev5 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 61ff634..d0dd1e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ "pika >= 1.2.0", "dataset", "pymongo > 3.0", - "sdx-pce @ git+https://github.com/atlanticwave-sdx/pce@3.0.0.dev4", + "sdx-pce @ git+https://github.com/atlanticwave-sdx/pce@3.0.0.dev5", ] [project.optional-dependencies] From 4e8e3d7825d87fb7eaa3798c7c521d5206c46b5e Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:23:14 -0600 Subject: [PATCH 3/7] Assert that we get a 200 response --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 23d3760..53ff8a7 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -609,7 +609,7 @@ def test_issue_356(self): print(f"POST response body is : {response.data.decode('utf-8')}") print(f"POST Response JSON is : {response.get_json()}") - # self.assertStatus(response, 200) + self.assertStatus(response, 200) if __name__ == "__main__": From c0389de3585fadb38dc708d16ec81b484b443fe5 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:26:09 -0600 Subject: [PATCH 4/7] Expect "201 Created" response actually --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 53ff8a7..84bcba6 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -609,7 +609,7 @@ def test_issue_356(self): print(f"POST response body is : {response.data.decode('utf-8')}") print(f"POST Response JSON is : {response.get_json()}") - self.assertStatus(response, 200) + self.assertStatus(response, 201) if __name__ == "__main__": From e431928a355f68907afc5d516caa2ee500c2d1b4 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:39:26 -0600 Subject: [PATCH 5/7] Request a VLAN that is actually out of range --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index 84bcba6..d6aa297 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -594,7 +594,7 @@ def test_issue_356(self): connection_request = { "name": "VLAN between AMPATH/300 and TENET/300", "endpoints": [ - {"port_id": "urn:sdx:port:ampath.net:Ampath3:50", "vlan": "300"}, + {"port_id": "urn:sdx:port:ampath.net:Ampath3:50", "vlan": "30000"}, {"port_id": "urn:sdx:port:tenet.ac.za:Tenet03:50", "vlan": "any"}, ], } From 367fcfbd035d264d0fcbd2ffc5cce14fda0039ff Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:42:43 -0600 Subject: [PATCH 6/7] Return an error code also when we have a TEError --- sdx_controller/handlers/connection_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index 66244c9..0c509b8 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -168,7 +168,10 @@ def place_connection( logger.debug(f"Breakdown sent to LC, status: {status}, code: {code}") return status, code except TEError as te_err: - return te_err + # We could probably return te_err.te_code instead of 400, + # but I don't think PCE should use HTTP error codes, + # because that violates abstraction boundaries. + return f"PCE error: {te_err}", 400 except Exception as e: err = traceback.format_exc().replace("\n", ", ") logger.error(f"Error when generating/publishing breakdown: {e} - {err}") From 1a0051d2d92e902ed93f347f38e3b3d6c93fce31 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 15 Nov 2024 09:46:34 -0600 Subject: [PATCH 7/7] Expect 400 response --- sdx_controller/test/test_l2vpn_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/test/test_l2vpn_controller.py b/sdx_controller/test/test_l2vpn_controller.py index d6aa297..06acc8c 100644 --- a/sdx_controller/test/test_l2vpn_controller.py +++ b/sdx_controller/test/test_l2vpn_controller.py @@ -609,7 +609,7 @@ def test_issue_356(self): print(f"POST response body is : {response.data.decode('utf-8')}") print(f"POST Response JSON is : {response.get_json()}") - self.assertStatus(response, 201) + self.assertStatus(response, 400) if __name__ == "__main__":