Skip to content

Commit

Permalink
Improved logs
Browse files Browse the repository at this point in the history
- Changed method name from `_install_unni_flows` to `_install_flows`
  • Loading branch information
Alopalao committed Nov 21, 2024
1 parent b9f0483 commit 992e27c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
22 changes: 12 additions & 10 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,11 @@ def remove_failover_flows(self, exclude_uni_switches=True,
force=force,
)
except FlowModException as err:
log.error(f"Error deleting path, {err}")
log.error(f"Error deleting {self} failover_path flows, {err}")
try:
self.failover_path.make_vlans_available(self._controller)
except KytosTagError as err:
log.error(f"Error when removing failover flows: {err}")
log.error(f"Error removing {self} failover_path: {err}")
self.failover_path = Path([])
if sync:
self.sync()
Expand Down Expand Up @@ -732,12 +732,12 @@ def remove_current_flows(self, force=True, sync=True):
try:
self._send_flow_mods(flow_mods, "delete", force=force)
except FlowModException as err:
log.error(f"Error deleting current_path, {err}")
log.error(f"Error deleting {self} current_path flows, {err}")

try:
current_path.make_vlans_available(self._controller)
except KytosTagError as err:
log.error(f"Error when removing current path flows: {err}")
log.error(f"Error removing {self} current_path: {err}")
self.current_path = Path([])
self.deactivate()
if sync:
Expand Down Expand Up @@ -796,12 +796,14 @@ def remove_path_flows(
dpid_flows_match, 'delete', force=force, by_switch=True
)
except FlowModException as err:
log.error(f"Error deleting path, {err}")
log.error(
f"Error deleting {self} path flows, path:{path}, error={err}"
)

try:
path.make_vlans_available(self._controller)
except KytosTagError as err:
log.error(f"Error when removing path flows: {err}")
log.error(f"Error removing {self} path: {err}")

return out_flows

Expand Down Expand Up @@ -867,7 +869,7 @@ def deploy_to_path(self, path=None):

try:
if use_path:
self._install_unni_flows(use_path)
self._install_flows(use_path)
elif self.is_intra_switch():
use_path = Path()
self._install_direct_uni_flows()
Expand Down Expand Up @@ -943,7 +945,7 @@ def setup_failover_path(self):

try:
if use_path:
out_new_flows = self._install_unni_flows(
out_new_flows = self._install_flows(
use_path, skip_in=True
)
except EVCPathNotInstalled as err:
Expand Down Expand Up @@ -1086,7 +1088,7 @@ def _install_direct_uni_flows(self):
try:
self._send_flow_mods(flow_mods, "install")
except FlowModException as err:
raise EVCPathNotInstalled(f"In {dpid}, {err}") from err
raise EVCPathNotInstalled(str(err)) from err

def _prepare_nni_flows(self, path=None):
"""Prepare NNI flows."""
Expand Down Expand Up @@ -1126,7 +1128,7 @@ def _prepare_nni_flows(self, path=None):
nni_flows[in_endpoint.switch.id] = flows
return nni_flows

def _install_unni_flows(
def _install_flows(
self, path=None, skip_in=False, skip_out=False
) -> dict[str, list[dict]]:
"""Install uni and nni flows"""
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/models/test_evc_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def create_evc_inter_switch(tag_value_a=82, tag_value_z=83):
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
@patch("napps.kytos.mef_eline.models.evc.log")
@patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_direct_uni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.activate")
@patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_deploy_successfully(self, *args):
@patch("napps.kytos.mef_eline.models.evc.log")
@patch("napps.kytos.mef_eline.models.evc.EVC.discover_new_paths")
@patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.activate")
@patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
@patch("napps.kytos.mef_eline.models.EVC.sync")
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_deploy_fail(self, *args):
return_value=[],
)
@patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
@patch("napps.kytos.mef_eline.models.evc.EVC.remove_current_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.sync")
Expand Down Expand Up @@ -537,7 +537,7 @@ def test_deploy_error(self, *args):

@patch("napps.kytos.mef_eline.models.evc.emit_event")
@patch("napps.kytos.mef_eline.models.evc.EVC.get_failover_path_candidates")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.remove_path_flows")
@patch("napps.kytos.mef_eline.models.EVC.sync")
def test_setup_failover_path(self, *args):
Expand Down Expand Up @@ -635,7 +635,7 @@ def test_deploy_to_backup_path1(
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc")
@patch("napps.kytos.mef_eline.models.evc.log")
@patch("napps.kytos.mef_eline.models.path.Path.choose_vlans")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC.activate")
@patch("napps.kytos.mef_eline.models.evc.EVC.should_deploy")
@patch("napps.kytos.mef_eline.models.evc.EVC.discover_new_paths")
Expand Down Expand Up @@ -2046,20 +2046,20 @@ def test_install_direct_uni_flows_error(self, prepare_mock, send_mock):
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._send_flow_mods")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_nni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_uni_flows")
def test_install_unni_flows_error(
def test_install_flows_error(
self, prepare_uni_mock, prepare_nni_mock, send_flow_mock
):
"""Test _install_unni_flows with error"""
"""Test _install_flows with error"""
prepare_nni_mock.return_value = {'1': [1]}
prepare_uni_mock.return_value = {'2': [2]}
send_flow_mock.side_effect = FlowModException('err')
with pytest.raises(EVCPathNotInstalled):
self.evc_deploy._install_unni_flows()
self.evc_deploy._install_flows()

@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._send_flow_mods")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_nni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy._prepare_uni_flows")
def test_install_unni_flows(
def test_install_flows(
self, prepare_uni_mock, prepare_nni_mock, send_flow_mock
):
"""Test that the dictionary contains uni and nni flows sent
Expand All @@ -2068,7 +2068,7 @@ def test_install_unni_flows(
prepare_uni_mock.return_value = {
'00:02': ["flow1"], '00:01': ["flow2"]
}
out_flows = self.evc_deploy._install_unni_flows()
out_flows = self.evc_deploy._install_flows()
expected_out_fows = {
'00:01': ["flow1", "flow2"],
'00:02': ["flow1"]
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/models/test_link_protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ async def test_handle_link_up_case_2(

@patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy")
@patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.path.Path.status", EntityStatus.UP)
async def test_handle_link_up_case_3(
self,
_install_unni_flows_mocked,
_install_flows_mocked,
deploy_to_path_mocked,
deploy_mocked,
):
Expand Down Expand Up @@ -516,12 +516,12 @@ async def test_handle_link_up_case_3(
assert current_handle_link_up

@patch("napps.kytos.mef_eline.models.evc.EVCDeploy.deploy_to_path")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_unni_flows")
@patch("napps.kytos.mef_eline.models.evc.EVC._install_flows")
@patch("napps.kytos.mef_eline.models.path.Path.status", EntityStatus.DOWN)
async def test_handle_link_up_case_4(self, *args):
"""Test if not path is found a dynamic path is used."""
(
_install_unni_flows_mocked,
_install_flows_mocked,
deploy_to_path_mocked,
) = args

Expand Down

0 comments on commit 992e27c

Please sign in to comment.