Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slash in path. #3573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions generic_config_updater/generic_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
20 changes: 18 additions & 2 deletions tests/generic_config_updater/multiasic_change_applier_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,6 +27,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"
),
Expand Down Expand Up @@ -71,7 +79,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')
Expand Down Expand Up @@ -134,7 +146,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.ChangeApplier._get_running_config', autospec=True)
Expand Down
Loading