Skip to content

Commit 3879913

Browse files
committed
addressing comments
1 parent b516fbb commit 3879913

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

generic_config_updater/gu_common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def _get_xpath_tokens_from_list(self, model, token_index, path_tokens, config):
544544
if len(path_tokens)-1 == token_index:
545545
return xpath_tokens
546546

547-
type_1_list_model = self._get_type_1_list_model(model, list_name)
547+
type_1_list_model = self._get_type_1_list_model(model)
548548
if type_1_list_model:
549549
new_xpath_tokens = self._get_xpath_tokens_from_type_1_list(type_1_list_model, token_index+1, path_tokens, config[path_tokens[token_index]])
550550
xpath_tokens.extend(new_xpath_tokens)
@@ -646,7 +646,8 @@ def _get_list_model(self, model, token_index, path_tokens):
646646

647647
return None
648648

649-
def _get_type_1_list_model(self, model, list_name):
649+
def _get_type_1_list_model(self, model):
650+
list_name = model['@name']
650651
if list_name not in sonic_yang_ext.Type_1_list_maps_model:
651652
return None
652653

@@ -736,7 +737,7 @@ def _get_path_tokens_from_list(self, model, token_index, xpath_tokens, config):
736737
return path_tokens
737738

738739
list_name = model['@name']
739-
type_1_list_model = self._get_type_1_list_model(model, list_name)
740+
type_1_list_model = self._get_type_1_list_model(model)
740741
if type_1_list_model:
741742
new_path_tokens = self._get_path_tokens_from_type_1_list(type_1_list_model, token_index+1, xpath_tokens, config[path_token])
742743
path_tokens.extend(new_path_tokens)
@@ -769,11 +770,15 @@ def _get_path_tokens_from_type_1_list(self, model, token_index, xpath_tokens, co
769770
if len(key_dict) > 1:
770771
raise GenericConfigUpdaterError(f"Type 1 inner list should have only 1 key in xpath, {len(key_dict)} specified. Key dictionary: {key_dict}")
771772

772-
keyName = list(key_dict.keys())[0]
773+
keyName = next(iter(key_dict.keys()))
773774
value = key_dict[keyName]
774775

775776
path_tokens = [value]
776777

778+
# If this is the last xpath token, return the path tokens we have built so far, no need for futher checks
779+
# Example:
780+
# xpath: /sonic-dot1p-tc-map:sonic-dot1p-tc-map/DOT1P_TO_TC_MAP/DOT1P_TO_TC_MAP_LIST[name='Dot1p_to_tc_map1']/DOT1P_TO_TC_MAP[dot1p='2']
781+
# path: /DOT1P_TO_TC_MAP/Dot1p_to_tc_map1/2
777782
if len(xpath_tokens)-1 == token_index:
778783
return path_tokens
779784

0 commit comments

Comments
 (0)