Skip to content
14 changes: 11 additions & 3 deletions generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ def create_path(self, tokens):
return JsonPointer.from_parts(tokens).path

def has_path(self, doc, path):
return JsonPointer(path).get(doc, default=None) is not None
return self.get_from_path(doc, path) is not None

def get_from_path(self, doc, path):
return JsonPointer(path).get(doc, default=None)

def is_config_different(self, path, current, target):
return self.get_from_path(current, path) != self.get_from_path(target, path)

def get_xpath_tokens(self, xpath):
"""
Expand Down Expand Up @@ -548,7 +554,8 @@ def _get_xpath_tokens_from_leaf(self, model, token_index, path_tokens, config):
# Source: Check examples in https://netopeer.liberouter.org/doc/libyang/master/html/howto_x_path.html
return [f"{token}[.='{value}']"]

raise ValueError("Token not found")
raise ValueError(f"Path token not found.\n model: {model}\n token_index: {token_index}\n " + \
f"path_tokens: {path_tokens}\n config: {config}")

def _extractKey(self, tableKey, keys):
keyList = keys.split()
Expand Down Expand Up @@ -712,7 +719,8 @@ def _get_path_tokens_from_leaf(self, model, token_index, xpath_tokens, config):
list_idx = list_config.index(leaf_list_value)
return [leaf_list_name, list_idx]

raise Exception("no leaf")
raise ValueError(f"Xpath token not found.\n model: {model}\n token_index: {token_index}\n " + \
f"xpath_tokens: {xpath_tokens}\n config: {config}")

def _extract_key_dict(self, list_token):
# Example: VLAN_MEMBER_LIST[name='Vlan1000'][port='Ethernet8']
Expand Down
Loading