Skip to content

Commit

Permalink
Merge pull request #378 from atlanticwave-sdx/375-stricter-connection…
Browse files Browse the repository at this point in the history
…-field-check-and-error-codes

375 stricter connection field check and error codes
  • Loading branch information
YufengXin authored Jan 15, 2025
2 parents 08118d2 + c1530a9 commit 73b1c2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"pika >= 1.2.0",
"dataset",
"pymongo > 3.0",
"sdx-pce @ git+https://github.com/atlanticwave-sdx/[email protected].dev5",
"sdx-pce @ git+https://github.com/atlanticwave-sdx/[email protected].dev6",
]

[project.optional-dependencies]
Expand Down
22 changes: 16 additions & 6 deletions sdx_controller/handlers/connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from sdx_pce.load_balancing.te_solver import TESolver
from sdx_pce.topology.temanager import TEManager
from sdx_pce.utils.exceptions import TEError
from sdx_pce.utils.exceptions import RequestValidationError, TEError

from sdx_controller.messaging.topic_queue_producer import TopicQueueProducer
from sdx_controller.models.simple_link import SimpleLink
Expand Down Expand Up @@ -143,12 +143,22 @@ def place_connection(
graph = te_manager.generate_graph_te()
if graph is None:
return "No SDX topology found", 424
try:
traffic_matrix = te_manager.generate_traffic_matrix(
connection_request=connection_request
)
except RequestValidationError as request_err:
err = traceback.format_exc().replace("\n", ", ")
logger.error(
f"Error when parsing and validating request: {request_err} - {err}"
)
return f"Error: {request_err}", request_err.request_code

traffic_matrix = te_manager.generate_traffic_matrix(
connection_request=connection_request
)
if traffic_matrix is None:
return "Could not generate a traffic matrix", 402
return (
"Request does not have a valid JSON or body is incomplete/incorrect",
400,
)

logger.info(f"Generated graph: '{graph}', traffic matrix: '{traffic_matrix}'")

Expand All @@ -175,7 +185,7 @@ def place_connection(
# 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
return f"PCE error: {te_err}", te_err.te_code
except Exception as e:
err = traceback.format_exc().replace("\n", ", ")
logger.error(f"Error when generating/publishing breakdown: {e} - {err}")
Expand Down
5 changes: 3 additions & 2 deletions sdx_controller/test/test_l2vpn_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ def test_place_connection_v2_with_three_topologies_400_response(self):
"Failure",
)
self.assertEqual(
response.get_json().get("reason"), "Could not generate a traffic matrix"
response.get_json().get("reason"),
"Request does not have a valid JSON or body is incomplete/incorrect",
)

# Returned connection ID should be different from the original
Expand Down Expand Up @@ -609,7 +610,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, 400)
self.assertStatus(response, 410)


if __name__ == "__main__":
Expand Down

0 comments on commit 73b1c2b

Please sign in to comment.