Skip to content

Commit 2f2f3e2

Browse files
bhavini-gadaGitHub Enterprise
authored and
GitHub Enterprise
committed
Merge pull request sonic-net#64 from e-sonic/SNC-16388
Fix to support REST top-level del from pim/global for RP alone config
2 parents 11578d1 + 72cda11 commit 2f2f3e2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

translib/transformer/xfmr_pim.go

+51
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,21 @@ func hdl_post_xfmr_pim_rp_address_del_(inParams *XfmrParams, niName string, retD
13541354
log.Info("After PIM Post-Transformer PIM_GLOBALS_RENDEZVOUS_POINT handler ==> retDbDataMap : ", (*retDbDataMap))
13551355
}
13561356

1357+
func pim_add_null_null_attr_to_pim_globals(pimGblKey string, inParams *XfmrParams) {
1358+
resMap := make(map[string]map[string]db.Value)
1359+
pimGblMap := make(map[string]db.Value)
1360+
pimGblMap[pimGblKey] = db.Value{Field: map[string]string{}}
1361+
resMap["PIM_GLOBALS"] = pimGblMap
1362+
1363+
if inParams.subOpDataMap[UPDATE] != nil && (*inParams.subOpDataMap[UPDATE])[db.ConfigDB] != nil {
1364+
mapCopy((*inParams.subOpDataMap[UPDATE])[db.ConfigDB], resMap)
1365+
} else {
1366+
subOpMap := make(map[db.DBNum]map[string]map[string]db.Value)
1367+
subOpMap[db.ConfigDB] = resMap
1368+
inParams.subOpDataMap[UPDATE] = &subOpMap
1369+
}
1370+
}
1371+
13571372
func pim_hdl_post_xfmr(inParams *XfmrParams, retDbDataMap *map[string]map[string]db.Value) error {
13581373
var err error
13591374

@@ -1399,6 +1414,42 @@ func pim_hdl_post_xfmr(inParams *XfmrParams, retDbDataMap *map[string]map[string
13991414
}
14001415
}
14011416

1417+
/*
1418+
For REST-delete @ URI: pim/global to cleanup rendezvous-points as well along with other pim/global containers,
1419+
PIM_GLOBALS table is expected to have a valid entry in DB. But attributes directly under PIM_GLOBALS are not mandatory.
1420+
To fix those cases,
1421+
(1) Adding NULL/NULL attribute to PIM_GLOBALS entry on PIM_GLOBALS_RENDEZVOUS_POINT CRU. This addition internally creates
1422+
the PIM_GLOBALS entry, if not present in DB
1423+
(2) Internally adding NULL/NULL attribute to the PIM_GLOBALS entry on leaf delete to
1424+
make sure PIM_GLOBALS entry is not deleted by infra-code on last-leaf delete.
1425+
*/
1426+
if (inParams.oper == CREATE || inParams.oper == REPLACE || inParams.oper == UPDATE) && (retDbDataMap != nil) {
1427+
depTblsNeedClnup := []string{"PIM_GLOBALS_RENDEZVOUS_POINT"} /* Add future tables under pim/global container to this list */
1428+
if _, ok := (*retDbDataMap)["PIM_GLOBALS"]; !ok {
1429+
addedPimGblKeys := make(map[string]bool)
1430+
for _, depTbl := range depTblsNeedClnup {
1431+
if depTblData, ok := (*retDbDataMap)[depTbl]; ok {
1432+
for depTblKey := range depTblData {
1433+
keyPtrn := strings.Split(depTblKey, "|")
1434+
pimGblKey := keyPtrn[0] + "|" + keyPtrn[1]
1435+
if _, ok := addedPimGblKeys[pimGblKey]; !ok {
1436+
pim_add_null_null_attr_to_pim_globals(pimGblKey, inParams)
1437+
addedPimGblKeys[pimGblKey] = true
1438+
}
1439+
}
1440+
}
1441+
}
1442+
}
1443+
} else if (inParams.oper == DELETE) && (inParams.dbDataMap != nil) {
1444+
if pimGblData, ok := (*inParams.dbDataMap)[db.ConfigDB]["PIM_GLOBALS"]; ok {
1445+
for pimGblKey := range pimGblData {
1446+
if pimGblVal, ok := pimGblData[pimGblKey]; ok && (len(pimGblVal.Field) > 0) {
1447+
pim_add_null_null_attr_to_pim_globals(pimGblKey, inParams)
1448+
}
1449+
}
1450+
}
1451+
}
1452+
14021453
return err
14031454
}
14041455

0 commit comments

Comments
 (0)