Skip to content

Commit 15ef7ab

Browse files
committed
sonic-yang-mgmt: uses clause with leaf-list not honored
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 a693520 commit 15ef7ab

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
@@ -1874,6 +1874,8 @@
18741874
},
18751875
"BGP_PEER_GROUP_AF": {
18761876
"default|PG1|ipv4_unicast": {
1877+
"route_map_in": [ "map1" ],
1878+
"route_map_out": [ "map1" ]
18771879
}
18781880
},
18791881
"BGP_GLOBALS_LISTEN_PREFIX": {

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

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
"eStrKey" : "InvalidValue",
9191
"eStr": ["send_community"]
9292
},
93+
"BGP_NEIGHBOR_AF_ROUTE_MAP_VALID": {
94+
"desc": "Reference valid route map"
95+
},
9396
"BGP_NEIGHBOR_AF_NEG_ROUTE_MAP_NOT_EXIST": {
9497
"desc": "Reference to non-existent route-map.",
9598
"eStrKey" : "LeafRef"
@@ -134,6 +137,9 @@
134137
"eStrKey" : "InvalidValue",
135138
"eStr": ["send_community"]
136139
},
140+
"BGP_PEERGROUP_AF_ROUTE_MAP_VALID": {
141+
"desc": "Validate route-map reference in peergroup AF."
142+
},
137143
"BGP_PEERGROUP_AF_ROUTE_MAP_NOT_EXIST": {
138144
"desc": "Missing or non-existent route-map reference in peergroup AF.",
139145
"eStrKey" : "LeafRef"

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

+112
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,62 @@
948948
}
949949
},
950950

951+
"BGP_NEIGHBOR_AF_ROUTE_MAP_VALID": {
952+
"sonic-route-map:sonic-route-map": {
953+
"sonic-route-map:ROUTE_MAP_SET": {
954+
"ROUTE_MAP_SET_LIST": [
955+
{
956+
"name": "ALLOW"
957+
}
958+
]
959+
},
960+
"sonic-route-map:ROUTE_MAP": {
961+
"ROUTE_MAP_LIST": [
962+
{
963+
"name": "ALLOW",
964+
"stmt_name": 1,
965+
"route_operation": "permit"
966+
}
967+
]
968+
}
969+
},
970+
"sonic-bgp-global:sonic-bgp-global": {
971+
"sonic-bgp-global:BGP_GLOBALS": {
972+
"BGP_GLOBALS_LIST": [
973+
{
974+
"vrf_name": "default",
975+
"local_asn": 65001
976+
}
977+
]
978+
}
979+
},
980+
"sonic-bgp-neighbor:sonic-bgp-neighbor": {
981+
"sonic-bgp-neighbor:BGP_NEIGHBOR": {
982+
"BGP_NEIGHBOR_LIST": [
983+
{
984+
"vrf_name": "default",
985+
"neighbor": "20.0.0.1",
986+
"local_asn": 1,
987+
"name": "BGP nbr 1",
988+
"asn": 65003
989+
}
990+
]
991+
},
992+
"sonic-bgp-neighbor:BGP_NEIGHBOR_AF": {
993+
"BGP_NEIGHBOR_AF_LIST": [
994+
{
995+
"vrf_name": "default",
996+
"neighbor": "20.0.0.1",
997+
"afi_safi": "ipv4_unicast",
998+
"admin_status": "up",
999+
"route_map_in": [ "ALLOW" ],
1000+
"route_map_out": [ "ALLOW" ]
1001+
}
1002+
]
1003+
}
1004+
}
1005+
},
1006+
9511007
"BGP_NEIGHBOR_AF_NEG_INVALID_MAP_IN": {
9521008
"sonic-route-map:sonic-route-map": {
9531009
"sonic-route-map:ROUTE_MAP_SET": {
@@ -1306,6 +1362,62 @@
13061362
}
13071363
},
13081364

1365+
"BGP_PEERGROUP_AF_ROUTE_MAP_VALID": {
1366+
"sonic-route-map:sonic-route-map": {
1367+
"sonic-route-map:ROUTE_MAP_SET": {
1368+
"ROUTE_MAP_SET_LIST": [
1369+
{
1370+
"name": "ALLOW"
1371+
}
1372+
]
1373+
},
1374+
"sonic-route-map:ROUTE_MAP": {
1375+
"ROUTE_MAP_LIST": [
1376+
{
1377+
"name": "ALLOW",
1378+
"stmt_name": 1,
1379+
"route_operation": "permit"
1380+
}
1381+
]
1382+
}
1383+
},
1384+
"sonic-bgp-global:sonic-bgp-global": {
1385+
"sonic-bgp-global:BGP_GLOBALS": {
1386+
"BGP_GLOBALS_LIST": [
1387+
{
1388+
"vrf_name": "default",
1389+
"local_asn": 65001
1390+
}
1391+
]
1392+
}
1393+
},
1394+
"sonic-bgp-peergroup:sonic-bgp-peergroup": {
1395+
"sonic-bgp-peergroup:BGP_PEER_GROUP": {
1396+
"BGP_PEER_GROUP_LIST": [
1397+
{
1398+
"vrf_name": "default",
1399+
"peer_group_name": "PG1",
1400+
"local_asn": 1,
1401+
"name": "BGP PeerGroup 01",
1402+
"asn": 65003
1403+
}
1404+
]
1405+
},
1406+
"sonic-bgp-peergroup:BGP_PEER_GROUP_AF": {
1407+
"BGP_PEER_GROUP_AF_LIST": [
1408+
{
1409+
"vrf_name": "default",
1410+
"peer_group_name": "PG1",
1411+
"afi_safi": "ipv4_unicast",
1412+
"admin_status": "up",
1413+
"route_map_in": [ "ALLOW" ],
1414+
"route_map_out": [ "ALLOW" ]
1415+
}
1416+
]
1417+
}
1418+
}
1419+
},
1420+
13091421
"BGP_PEERGROUP_AF_ROUTE_MAP_NOT_EXIST": {
13101422
"sonic-bgp-global:sonic-bgp-global": {
13111423
"sonic-bgp-global:BGP_GLOBALS": {

0 commit comments

Comments
 (0)