Skip to content

Commit

Permalink
Merge pull request sonic-net#64 from e-sonic/SNC-16388
Browse files Browse the repository at this point in the history
Fix to support REST top-level del from pim/global for RP alone config
  • Loading branch information
bhavini-gada authored and GitHub Enterprise committed Mar 3, 2022
2 parents 11578d1 + 72cda11 commit 2f2f3e2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions translib/transformer/xfmr_pim.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,21 @@ func hdl_post_xfmr_pim_rp_address_del_(inParams *XfmrParams, niName string, retD
log.Info("After PIM Post-Transformer PIM_GLOBALS_RENDEZVOUS_POINT handler ==> retDbDataMap : ", (*retDbDataMap))
}

func pim_add_null_null_attr_to_pim_globals(pimGblKey string, inParams *XfmrParams) {
resMap := make(map[string]map[string]db.Value)
pimGblMap := make(map[string]db.Value)
pimGblMap[pimGblKey] = db.Value{Field: map[string]string{}}
resMap["PIM_GLOBALS"] = pimGblMap

if inParams.subOpDataMap[UPDATE] != nil && (*inParams.subOpDataMap[UPDATE])[db.ConfigDB] != nil {
mapCopy((*inParams.subOpDataMap[UPDATE])[db.ConfigDB], resMap)
} else {
subOpMap := make(map[db.DBNum]map[string]map[string]db.Value)
subOpMap[db.ConfigDB] = resMap
inParams.subOpDataMap[UPDATE] = &subOpMap
}
}

func pim_hdl_post_xfmr(inParams *XfmrParams, retDbDataMap *map[string]map[string]db.Value) error {
var err error

Expand Down Expand Up @@ -1399,6 +1414,42 @@ func pim_hdl_post_xfmr(inParams *XfmrParams, retDbDataMap *map[string]map[string
}
}

/*
For REST-delete @ URI: pim/global to cleanup rendezvous-points as well along with other pim/global containers,
PIM_GLOBALS table is expected to have a valid entry in DB. But attributes directly under PIM_GLOBALS are not mandatory.
To fix those cases,
(1) Adding NULL/NULL attribute to PIM_GLOBALS entry on PIM_GLOBALS_RENDEZVOUS_POINT CRU. This addition internally creates
the PIM_GLOBALS entry, if not present in DB
(2) Internally adding NULL/NULL attribute to the PIM_GLOBALS entry on leaf delete to
make sure PIM_GLOBALS entry is not deleted by infra-code on last-leaf delete.
*/
if (inParams.oper == CREATE || inParams.oper == REPLACE || inParams.oper == UPDATE) && (retDbDataMap != nil) {
depTblsNeedClnup := []string{"PIM_GLOBALS_RENDEZVOUS_POINT"} /* Add future tables under pim/global container to this list */
if _, ok := (*retDbDataMap)["PIM_GLOBALS"]; !ok {
addedPimGblKeys := make(map[string]bool)
for _, depTbl := range depTblsNeedClnup {
if depTblData, ok := (*retDbDataMap)[depTbl]; ok {
for depTblKey := range depTblData {
keyPtrn := strings.Split(depTblKey, "|")
pimGblKey := keyPtrn[0] + "|" + keyPtrn[1]
if _, ok := addedPimGblKeys[pimGblKey]; !ok {
pim_add_null_null_attr_to_pim_globals(pimGblKey, inParams)
addedPimGblKeys[pimGblKey] = true
}
}
}
}
}
} else if (inParams.oper == DELETE) && (inParams.dbDataMap != nil) {
if pimGblData, ok := (*inParams.dbDataMap)[db.ConfigDB]["PIM_GLOBALS"]; ok {
for pimGblKey := range pimGblData {
if pimGblVal, ok := pimGblData[pimGblKey]; ok && (len(pimGblVal.Field) > 0) {
pim_add_null_null_attr_to_pim_globals(pimGblKey, inParams)
}
}
}
}

return err
}

Expand Down

0 comments on commit 2f2f3e2

Please sign in to comment.