@@ -544,7 +544,7 @@ def _get_xpath_tokens_from_list(self, model, token_index, path_tokens, config):
544
544
if len (path_tokens )- 1 == token_index :
545
545
return xpath_tokens
546
546
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 )
548
548
if type_1_list_model :
549
549
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 ]])
550
550
xpath_tokens .extend (new_xpath_tokens )
@@ -646,7 +646,8 @@ def _get_list_model(self, model, token_index, path_tokens):
646
646
647
647
return None
648
648
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' ]
650
651
if list_name not in sonic_yang_ext .Type_1_list_maps_model :
651
652
return None
652
653
@@ -736,7 +737,7 @@ def _get_path_tokens_from_list(self, model, token_index, xpath_tokens, config):
736
737
return path_tokens
737
738
738
739
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 )
740
741
if type_1_list_model :
741
742
new_path_tokens = self ._get_path_tokens_from_type_1_list (type_1_list_model , token_index + 1 , xpath_tokens , config [path_token ])
742
743
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
769
770
if len (key_dict ) > 1 :
770
771
raise GenericConfigUpdaterError (f"Type 1 inner list should have only 1 key in xpath, { len (key_dict )} specified. Key dictionary: { key_dict } " )
771
772
772
- keyName = list ( key_dict .keys ())[ 0 ]
773
+ keyName = next ( iter ( key_dict .keys ()))
773
774
value = key_dict [keyName ]
774
775
775
776
path_tokens = [value ]
776
777
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
777
782
if len (xpath_tokens )- 1 == token_index :
778
783
return path_tokens
779
784
0 commit comments