Skip to content

Commit 9f8e2c1

Browse files
committed
sonic-yang-mgmt: uses clause with leaf-list not honored (PR sonic-net#21907)
When a uses clause imports a grouping, it was only processing leaf entries and ignoring leaf-list. That means that for instance in bgp route maps, route_map_in and route_map_out validations would fail. This fixes that behavior and adds test cases to ensure it doesn't regress in the future. Signed-off-by: Brad House (@bradh352)
1 parent 7df981e commit 9f8e2c1

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed

src/sonic-yang-mgmt/sonic_yang_ext.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ def _preProcessYangGrouping(self, moduleName, module):
128128

129129
for grouping in groupings:
130130
gName = grouping["@name"]
131-
gLeaf = grouping["leaf"]
132-
self.preProcessedYang['grouping'][moduleName][gName] = gLeaf
131+
self.preProcessedYang['grouping'][moduleName][gName] = dict()
132+
self.preProcessedYang['grouping'][moduleName][gName]["leaf"] = grouping.get('leaf')
133+
self.preProcessedYang['grouping'][moduleName][gName]["leaf-list"] = grouping.get('leaf-list')
133134

134135
except Exception as e:
135136
self.sysLog(msg="_preProcessYangGrouping failed:{}".format(str(e)), \
@@ -349,8 +350,11 @@ def _fillLeafDictUses(self, uses_s, table, leafDict):
349350
else:
350351
uses_module_name = table_module['@name']
351352
grouping = uses['@name'].split(':')[-1].strip()
352-
leafs = self.preProcessedYang['grouping'][uses_module_name][grouping]
353-
self._fillLeafDict(leafs, leafDict)
353+
groupdata = self.preProcessedYang['grouping'][uses_module_name][grouping]
354+
355+
self._fillLeafDict(groupdata.get('leaf'), leafDict)
356+
# leaf-lists
357+
self._fillLeafDict(groupdata.get('leaf-list'), leafDict, True)
354358
except Exception as e:
355359
self.sysLog(msg="_fillLeafDictUses failed:{}".format(str(e)), \
356360
debug=syslog.LOG_ERR, doPrint=True)

src/sonic-yang-models/tests/files/sample_config_db.json

+2
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,8 @@
18781878
},
18791879
"BGP_PEER_GROUP_AF": {
18801880
"default|PG1|ipv4_unicast": {
1881+
"route_map_in": [ "map1" ],
1882+
"route_map_out": [ "map1" ]
18811883
}
18821884
},
18831885
"BGP_GLOBALS_LISTEN_PREFIX": {

src/sonic-yang-models/tests/yang_model_tests/tests/bgp.json

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
"eStrKey" : "InvalidValue",
9898
"eStr": ["send_community"]
9999
},
100+
"BGP_NEIGHBOR_AF_ROUTE_MAP_VALID": {
101+
"desc": "Reference valid route map"
102+
},
100103
"BGP_NEIGHBOR_AF_NEG_ROUTE_MAP_NOT_EXIST": {
101104
"desc": "Reference to non-existent route-map.",
102105
"eStrKey" : "LeafRef"
@@ -141,6 +144,9 @@
141144
"eStrKey" : "InvalidValue",
142145
"eStr": ["send_community"]
143146
},
147+
"BGP_PEERGROUP_AF_ROUTE_MAP_VALID": {
148+
"desc": "Validate route-map reference in peergroup AF."
149+
},
144150
"BGP_PEERGROUP_AF_ROUTE_MAP_NOT_EXIST": {
145151
"desc": "Missing or non-existent route-map reference in peergroup AF.",
146152
"eStrKey" : "LeafRef"

src/sonic-yang-models/tests/yang_model_tests/tests_config/bgp.json

+112
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,62 @@
990990
}
991991
},
992992

993+
"BGP_NEIGHBOR_AF_ROUTE_MAP_VALID": {
994+
"sonic-route-map:sonic-route-map": {
995+
"sonic-route-map:ROUTE_MAP_SET": {
996+
"ROUTE_MAP_SET_LIST": [
997+
{
998+
"name": "ALLOW"
999+
}
1000+
]
1001+
},
1002+
"sonic-route-map:ROUTE_MAP": {
1003+
"ROUTE_MAP_LIST": [
1004+
{
1005+
"name": "ALLOW",
1006+
"stmt_name": 1,
1007+
"route_operation": "permit"
1008+
}
1009+
]
1010+
}
1011+
},
1012+
"sonic-bgp-global:sonic-bgp-global": {
1013+
"sonic-bgp-global:BGP_GLOBALS": {
1014+
"BGP_GLOBALS_LIST": [
1015+
{
1016+
"vrf_name": "default",
1017+
"local_asn": 65001
1018+
}
1019+
]
1020+
}
1021+
},
1022+
"sonic-bgp-neighbor:sonic-bgp-neighbor": {
1023+
"sonic-bgp-neighbor:BGP_NEIGHBOR": {
1024+
"BGP_NEIGHBOR_LIST": [
1025+
{
1026+
"vrf_name": "default",
1027+
"neighbor": "20.0.0.1",
1028+
"local_asn": 1,
1029+
"name": "BGP nbr 1",
1030+
"asn": 65003
1031+
}
1032+
]
1033+
},
1034+
"sonic-bgp-neighbor:BGP_NEIGHBOR_AF": {
1035+
"BGP_NEIGHBOR_AF_LIST": [
1036+
{
1037+
"vrf_name": "default",
1038+
"neighbor": "20.0.0.1",
1039+
"afi_safi": "ipv4_unicast",
1040+
"admin_status": "up",
1041+
"route_map_in": [ "ALLOW" ],
1042+
"route_map_out": [ "ALLOW" ]
1043+
}
1044+
]
1045+
}
1046+
}
1047+
},
1048+
9931049
"BGP_NEIGHBOR_AF_NEG_INVALID_MAP_IN": {
9941050
"sonic-route-map:sonic-route-map": {
9951051
"sonic-route-map:ROUTE_MAP_SET": {
@@ -1348,6 +1404,62 @@
13481404
}
13491405
},
13501406

1407+
"BGP_PEERGROUP_AF_ROUTE_MAP_VALID": {
1408+
"sonic-route-map:sonic-route-map": {
1409+
"sonic-route-map:ROUTE_MAP_SET": {
1410+
"ROUTE_MAP_SET_LIST": [
1411+
{
1412+
"name": "ALLOW"
1413+
}
1414+
]
1415+
},
1416+
"sonic-route-map:ROUTE_MAP": {
1417+
"ROUTE_MAP_LIST": [
1418+
{
1419+
"name": "ALLOW",
1420+
"stmt_name": 1,
1421+
"route_operation": "permit"
1422+
}
1423+
]
1424+
}
1425+
},
1426+
"sonic-bgp-global:sonic-bgp-global": {
1427+
"sonic-bgp-global:BGP_GLOBALS": {
1428+
"BGP_GLOBALS_LIST": [
1429+
{
1430+
"vrf_name": "default",
1431+
"local_asn": 65001
1432+
}
1433+
]
1434+
}
1435+
},
1436+
"sonic-bgp-peergroup:sonic-bgp-peergroup": {
1437+
"sonic-bgp-peergroup:BGP_PEER_GROUP": {
1438+
"BGP_PEER_GROUP_LIST": [
1439+
{
1440+
"vrf_name": "default",
1441+
"peer_group_name": "PG1",
1442+
"local_asn": 1,
1443+
"name": "BGP PeerGroup 01",
1444+
"asn": 65003
1445+
}
1446+
]
1447+
},
1448+
"sonic-bgp-peergroup:BGP_PEER_GROUP_AF": {
1449+
"BGP_PEER_GROUP_AF_LIST": [
1450+
{
1451+
"vrf_name": "default",
1452+
"peer_group_name": "PG1",
1453+
"afi_safi": "ipv4_unicast",
1454+
"admin_status": "up",
1455+
"route_map_in": [ "ALLOW" ],
1456+
"route_map_out": [ "ALLOW" ]
1457+
}
1458+
]
1459+
}
1460+
}
1461+
},
1462+
13511463
"BGP_PEERGROUP_AF_ROUTE_MAP_NOT_EXIST": {
13521464
"sonic-bgp-global:sonic-bgp-global": {
13531465
"sonic-bgp-global:BGP_GLOBALS": {

0 commit comments

Comments
 (0)