From 992e27ccb2cc74495eb22341b6f8d780329df2d1 Mon Sep 17 00:00:00 2001 From: Aldo Ortega Date: Thu, 21 Nov 2024 11:33:04 -0500 Subject: [PATCH] Improved logs - Changed method name from `_install_unni_flows` to `_install_flows` --- models/evc.py | 22 ++++++++++++---------- tests/unit/models/test_evc_deploy.py | 20 ++++++++++---------- tests/unit/models/test_link_protection.py | 8 ++++---- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/models/evc.py b/models/evc.py index 924ad446..6fd075c2 100644 --- a/models/evc.py +++ b/models/evc.py @@ -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() @@ -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: @@ -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 @@ -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() @@ -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: @@ -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.""" @@ -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""" diff --git a/tests/unit/models/test_evc_deploy.py b/tests/unit/models/test_evc_deploy.py index 17890362..6d892676 100644 --- a/tests/unit/models/test_evc_deploy.py +++ b/tests/unit/models/test_evc_deploy.py @@ -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") @@ -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") @@ -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") @@ -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): @@ -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") @@ -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 @@ -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"] diff --git a/tests/unit/models/test_link_protection.py b/tests/unit/models/test_link_protection.py index 814c0fbc..436a517c 100644 --- a/tests/unit/models/test_link_protection.py +++ b/tests/unit/models/test_link_protection.py @@ -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, ): @@ -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