Skip to content

Commit

Permalink
Merge pull request #608 from kytos-ng/bug/uni_up
Browse files Browse the repository at this point in the history
Redeploy static EVC when link_up
  • Loading branch information
Alopalao authored Jan 22, 2025
2 parents 7276cc5 + ebd410a commit f70eb50
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Fixed
- EVCs activation now take into account UNIs statuses before trying to activate
- ``EVC.remove_current_flows()`` had its parameter ``current_path`` used when ``evc.current_path`` fails to install flows.
- ``evc.current_path`` is deleted when an error with TAG type is raised.
- Link up from UNI will deploy correctly an EVC when it does not have a path.

Added
=====
Expand Down
16 changes: 14 additions & 2 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def is_using_dynamic_path(self):
return True
return False

def handle_link_up(self, link):
def handle_link_up(self, link=None, interface=None):
"""Handle circuit when link up.
Args:
Expand All @@ -1757,6 +1757,18 @@ def handle_link_up(self, link):
lambda me: me.primary_path.is_affected_by_link(link),
lambda me: (me.deploy_to_primary_path(), 'redeploy')
),
# For this special case, it reached this point because interface
# was previously confirmed to be a UNI and both UNI are UP
(
lambda me: (me.primary_path.status == EntityStatus.UP
and interface),
lambda me: (me.deploy_to_primary_path(), 'redeploy')
),
(
lambda me: (me.backup_path.status == EntityStatus.UP
and interface),
lambda me: (me.deploy_to_backup_path(), 'redeploy')
),
# We tried to deploy(primary_path) without success.
# And in this case is up by some how. Nothing to do.
(
Expand Down Expand Up @@ -1840,7 +1852,7 @@ def try_to_handle_uni_as_link_up(self, interface: Interface) -> bool:
self.current_path.status != EntityStatus.UP
and not self.is_intra_switch()
):
succeeded = self.handle_link_up(interface)
succeeded = self.handle_link_up(interface=interface)
if succeeded:
msg = (
f"Activated {self} due to successful "
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/models/test_link_protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,64 @@ async def test_handle_link_up_case_7(self):
assert not self.evc.handle_link_up(MagicMock())
assert self.evc.deploy_to_path.call_count == 0

@patch(DEPLOY_TO_BACKUP_PATH)
@patch(DEPLOY_TO_PRIMARY_PATH)
async def test_handle_link_up_case_8(
self, deploy_primary_mock, deploy_backup_mock
):
"""Test when UNI is UP and dinamic primary_path from
EVC is UP as well."""
primary_path = [
get_link_mocked(
endpoint_a_port=9,
endpoint_b_port=10,
metadata={"s_vlan": 5},
status=EntityStatus.UP,
),
get_link_mocked(
endpoint_a_port=11,
endpoint_b_port=12,
metadata={"s_vlan": 6},
status=EntityStatus.UP,
),
]
backup_path = [
get_link_mocked(
endpoint_a_port=13,
endpoint_b_port=14,
metadata={"s_vlan": 5},
status=EntityStatus.UP,
),
get_link_mocked(
endpoint_a_port=11,
endpoint_b_port=12,
metadata={"s_vlan": 6},
status=EntityStatus.DOWN,
),
]

attributes = {
"controller": get_controller_mock(),
"name": "circuit",
"uni_a": get_uni_mocked(is_valid=True),
"uni_z": get_uni_mocked(is_valid=True),
"primary_path": primary_path,
"backup_path": backup_path,
"enabled": True,
"dynamic_backup_path": True,
}

evc = EVC(**attributes)
evc.handle_link_up(interface=evc.uni_a.interface)
assert deploy_primary_mock.call_count == 1
assert deploy_backup_mock.call_count == 0

evc.primary_path[0].status = EntityStatus.DOWN
evc.backup_path[1].status = EntityStatus.UP
evc.handle_link_up(interface=evc.uni_a.interface)
assert deploy_primary_mock.call_count == 1
assert deploy_backup_mock.call_count == 1

async def test_get_interface_from_switch(self):
"""Test get_interface_from_switch"""
interface = id_to_interface_mock('00:01:1')
Expand Down

0 comments on commit f70eb50

Please sign in to comment.