Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

375 stricter connection field check and error codes #378

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -139,12 +139,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 @@ -171,7 +181,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
Loading