diff --git a/generic_config_updater/generic_updater.py b/generic_config_updater/generic_updater.py index 8ce27455bb..e8bb021808 100644 --- a/generic_config_updater/generic_updater.py +++ b/generic_config_updater/generic_updater.py @@ -17,9 +17,11 @@ def extract_scope(path): if not path: - raise Exception("Wrong patch with empty path.") + raise GenericConfigUpdaterError("Wrong patch with empty path.") pointer = jsonpointer.JsonPointer(path) - parts = pointer.parts + + # Re-escapes + parts = [jsonpointer.escape(part) for part in pointer.parts] if not parts: raise GenericConfigUpdaterError("Wrong patch with empty path.") if parts[0].startswith("asic"): diff --git a/tests/generic_config_updater/multiasic_change_applier_test.py b/tests/generic_config_updater/multiasic_change_applier_test.py index afa1b449f3..743969737d 100644 --- a/tests/generic_config_updater/multiasic_change_applier_test.py +++ b/tests/generic_config_updater/multiasic_change_applier_test.py @@ -1,7 +1,9 @@ +import jsonpointer import unittest from importlib import reload from unittest.mock import patch, MagicMock from generic_config_updater.generic_updater import extract_scope +from generic_config_updater.generic_updater import GenericConfigUpdaterError import generic_config_updater.change_applier import generic_config_updater.services_validator import generic_config_updater.gu_common @@ -49,6 +51,12 @@ def test_extract_scope_multiasic(self, mock_is_multi_asic): "/asic0123456789/PORTCHANNEL/PortChannel102/admin_status": ( True, "asic0123456789", "/PORTCHANNEL/PortChannel102/admin_status" ), + "/asic1/PORTCHANNEL_INTERFACE/PortChannel106|10.0.0.6/31": ( + True, "asic1", "/PORTCHANNEL_INTERFACE/PortChannel106|10.0.0.6/31" + ), + "/asic1/PORTCHANNEL_INTERFACE/PortChannel106|10.0.0.6~131": ( + True, "asic1", "/PORTCHANNEL_INTERFACE/PortChannel106|10.0.0.6~131" + ), "/localhost/BGP_DEVICE_GLOBAL/STATE/tsa_enabled": ( True, "localhost", "/BGP_DEVICE_GLOBAL/STATE/tsa_enabled" ), @@ -95,7 +103,11 @@ def test_extract_scope_multiasic(self, mock_is_multi_asic): scope, remainder = extract_scope(test_path) assert(scope == expectedscope) assert(remainder == expectedremainder) - except Exception: + except AssertionError: + assert(not result) + except GenericConfigUpdaterError: + assert(not result) + except jsonpointer.JsonPointerException: assert(not result) @patch('sonic_py_common.multi_asic.is_multi_asic') @@ -158,7 +170,11 @@ def test_extract_scope_singleasic(self, mock_is_multi_asic): scope, remainder = extract_scope(test_path) assert(scope == expectedscope) assert(remainder == expectedremainder) - except Exception: + except AssertionError: + assert(not result) + except GenericConfigUpdaterError: + assert(not result) + except jsonpointer.JsonPointerException: assert(not result) @patch('generic_config_updater.change_applier.get_config_db_as_json', autospec=True)