From 72cda1166d8576c794a55166f96e12c9d855b6e8 Mon Sep 17 00:00:00 2001 From: Rathnasabapathy Velautharaj Date: Wed, 23 Feb 2022 19:41:08 -0800 Subject: [PATCH] Fix to support REST top-level del from pim/global for RP alone config --- translib/transformer/xfmr_pim.go | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/translib/transformer/xfmr_pim.go b/translib/transformer/xfmr_pim.go index d6ee19fc9..e57107223 100644 --- a/translib/transformer/xfmr_pim.go +++ b/translib/transformer/xfmr_pim.go @@ -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 @@ -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 }