Skip to content

Commit

Permalink
Merge pull request #430 from kytos-ng/fix/disjoint_paths
Browse files Browse the repository at this point in the history
Fixed early return
  • Loading branch information
Alopalao authored Feb 7, 2024
2 parents 47e4cd4 + 88d4652 commit 820d024
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_disjoint_paths(
unwanted_switches.discard(circuit.uni_z.interface.switch.id)

length_unwanted = (len(unwanted_links) + len(unwanted_switches))
if not unwanted_links or not unwanted_switches:
if not unwanted_links:
return None

paths = cls.get_paths(circuit, max_paths=cutoff,
Expand Down
77 changes: 77 additions & 0 deletions tests/unit/models/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,83 @@ def test_get_disjoint_paths(self, mock_requests_post, mock_shared):
[link.id for link in expected_disjoint_path]
)

@patch("requests.post")
def test_get_disjoint_paths_simple_evc(self, mock_requests_post):
"""Test get_disjoint_paths method for simple EVCs."""
controller = MagicMock()
controller.get_interface_by_id.side_effect = id_to_interface_mock
DynamicPathManager.set_controller(controller)

evc = MagicMock()
evc.secondary_constraints = {
"spf_attribute": "hop",
"spf_max_path_cost": 20,
"mandatory_metrics": {
"ownership": "red"
}
}
evc.uni_a.interface.id = "1"
evc.uni_z.interface.id = "2"
evc.uni_a.interface.switch.id = "00:00:00:00:00:00:00:01"
evc.uni_z.interface.switch.id = "00:00:00:00:00:00:00:05"

mock_paths = {
"paths": [
{
"cost": 5,
"hops": [
"00:00:00:00:00:00:00:01:1",
"00:00:00:00:00:00:00:01",
"00:00:00:00:00:00:00:01:3",
"00:00:00:00:00:00:00:02:2",
"00:00:00:00:00:00:00:02",
"00:00:00:00:00:00:00:02:1"
]
},
{
"cost": 8,
"hops": [
"00:00:00:00:00:00:00:01:1",
"00:00:00:00:00:00:00:01",
"00:00:00:00:00:00:00:01:4",
"00:00:00:00:00:00:00:03:3",
"00:00:00:00:00:00:00:03",
"00:00:00:00:00:00:00:03:2",
"00:00:00:00:00:00:00:02:3",
"00:00:00:00:00:00:00:02",
"00:00:00:00:00:00:00:02:1"
]
},
]
}
current_path = [
Link(
id_to_interface_mock("00:00:00:00:00:00:00:01:3"),
id_to_interface_mock("00:00:00:00:00:00:00:02:2")
),
]
expected_disjoint_path = [
Link(
id_to_interface_mock("00:00:00:00:00:00:00:01:4"),
id_to_interface_mock("00:00:00:00:00:00:00:03:3")
),
Link(
id_to_interface_mock("00:00:00:00:00:00:00:02:3"),
id_to_interface_mock("00:00:00:00:00:00:00:03:2")
),
]

mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = mock_paths
mock_requests_post.return_value = mock_response
paths = list(DynamicPathManager.get_disjoint_paths(evc, current_path))
assert len(paths) == 1
assert (
[link.id for link in paths[0]] ==
[link.id for link in expected_disjoint_path]
)

def test_get_shared_components(self):
"""Test get_shared_components"""
mock_path = {"hops": [
Expand Down

0 comments on commit 820d024

Please sign in to comment.