Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions translib/common_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"
"sync"

"github.com/Azure/sonic-mgmt-common/cvl"
"github.com/Azure/sonic-mgmt-common/translib/db"
"github.com/Azure/sonic-mgmt-common/translib/ocbinds"
"github.com/Azure/sonic-mgmt-common/translib/path"
Expand Down Expand Up @@ -679,7 +680,6 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
var cmnAppTs *db.TableSpec
var xfmrTblLst []string
var resultTblLst []string
var isSonicYangReq bool

for tblNm := range dbMap {
xfmrTblLst = append(xfmrTblLst, tblNm)
Expand All @@ -688,9 +688,6 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
if err != nil {
return err
}
if strings.HasPrefix(app.pathInfo.Path, "/sonic") {
isSonicYangReq = true
}

/* CVL sorted order is in child first, parent later order. CRU ops from parent first order */
for idx := len(resultTblLst) - 1; idx >= 0; idx-- {
Expand All @@ -716,6 +713,13 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
for _, tblKey := range reverOrdDbKeyLst {
tblRw := tblVal[tblKey]
log.Info("Processing Table key ", tblKey)
existingEntry, _ := d.GetEntry(cmnAppTs, db.Key{Comp: []string{tblKey}})
if existingEntry.IsPopulated() && len(tblRw.Field) == 1 && (opcode == CREATE || opcode == UPDATE) {
/*If tbl/key in result map exists in Db and the resultmap has only NULL/NULL field then don't do Db oper */
if _, nullFieldOk := tblRw.Field["NULL"]; nullFieldOk {
continue
}
}
// REDIS doesn't allow to create a table instance without any fields
if tblRw.Field == nil {
tblRw.Field = map[string]string{"NULL": "NULL"}
Expand All @@ -726,7 +730,6 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
if len(tblRw.Field) > 1 {
delete(tblRw.Field, "NULL")
}
existingEntry, _ := d.GetEntry(cmnAppTs, db.Key{Comp: []string{tblKey}})
switch opcode {
case CREATE:
if existingEntry.IsPopulated() {
Expand All @@ -746,10 +749,12 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
if tblRwDefaults, defaultOk := app.cmnAppYangDefValMap[tblNm][tblKey]; defaultOk {
log.Info("Entry ", tblKey, " doesn't exist so fill yang defined defaults - ", tblRwDefaults)
for fld, val := range tblRwDefaults.Field {
tblRw.Field[fld] = val
if _, fldOk := tblRw.Field[fld]; !fldOk {
tblRw.Field[fld] = val
}
}
}
if isSonicYangReq && len(tblRw.Field) > 1 {
if len(tblRw.Field) > 1 {
delete(tblRw.Field, "NULL")
}
log.Info("Processing Table row ", tblRw)
Expand Down Expand Up @@ -778,10 +783,12 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
if tblRwDefaults, defaultOk := app.cmnAppYangDefValMap[tblNm][tblKey]; defaultOk {
log.Info("Entry ", tblKey, " doesn't exist so fill defaults - ", tblRwDefaults)
for fld, val := range tblRwDefaults.Field {
tblRw.Field[fld] = val
if _, fldOk := tblRw.Field[fld]; !fldOk {
tblRw.Field[fld] = val
}
}
}
if isSonicYangReq && len(tblRw.Field) > 1 {
if len(tblRw.Field) > 1 {
delete(tblRw.Field, "NULL")
}
log.Info("Processing Table row ", tblRw)
Expand All @@ -799,10 +806,12 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
if tblRwDefaults, defaultOk := app.cmnAppYangDefValMap[tblNm][tblKey]; defaultOk {
log.Info("For entry ", tblKey, ", being replaced, fill defaults - ", tblRwDefaults)
for fld, val := range tblRwDefaults.Field {
tblRw.Field[fld] = val
if _, fldOk := tblRw.Field[fld]; !fldOk {
tblRw.Field[fld] = val
}
}
}
if isSonicYangReq && len(tblRw.Field) > 1 {
if len(tblRw.Field) > 1 {
delete(tblRw.Field, "NULL")
}
log.Info("Processing Table row ", tblRw)
Expand Down Expand Up @@ -842,10 +851,13 @@ func (app *CommonApp) cmnAppCRUCommonDbOpn(d *db.DB, opcode int, dbMap map[strin
}
if isTlNd && isPartialReplace(existingEntry, tblRw, auxRw) {
log.Info("Since its partial replace modifying fields - ", tblRw)
err = d.ModEntry(cmnAppTs, db.Key{Comp: []string{tblKey}}, tblRw)
if err != nil {
log.Warning("REPLACE case - d.ModEntry() failure")
return err
/*If tbl/key in result map has only NULL/NULL field then nothing to do as other fields are already present in the table instance(partialReplaceCase) */
if _, nullFieldOk := tblRw.Field["NULL"]; (len(tblRw.Field) > 1) || (len(tblRw.Field) == 1 && !nullFieldOk) {
err = d.ModEntry(cmnAppTs, db.Key{Comp: []string{tblKey}}, tblRw)
if err != nil {
log.Warning("REPLACE case - d.ModEntry() failure")
return err
}
}
if auxRwOk {
if len(auxRw.Field) > 0 {
Expand Down Expand Up @@ -976,17 +988,33 @@ func (app *CommonApp) cmnAppDelDbOpn(d *db.DB, opcode int, dbMap map[string]map[
}
err = d.DeleteEntry(cmnAppTs, db.Key{Comp: []string{tblKey}})
if err != nil {
log.Warning("DELETE case - d.DeleteEntry() failure")
return err
switch e := err.(type) {
case tlerr.TranslibCVLFailure:
if cvl.CVLRetCode(e.Code) == cvl.CVL_SEMANTIC_KEY_NOT_EXIST {
log.Infof("Ignore delete that cannot be processed for table %v key %v that does not exist. err %v", tblNm, tblKey, e.CVLErrorInfo.ConstraintErrMsg)
err = nil
} else {
log.Warning("DELETE case - d.DeleteEntry() failure")
return err
}
default:
log.Warning("DELETE case - d.DeleteEntry() failure")
return err
}
}
log.Info("Finally deleted the parent table row with key = ", tblKey)
} else {
// In case we have FillFields available in the tblRw, do not send the request to DB.
if len(tblRw.Field) == 1 {
if tblRw.Has("FillFields") {
continue
}
}
log.Info("DELETE case - fields/cols to delete hence delete only those fields.")
existingEntry, exstErr := d.GetEntry(cmnAppTs, db.Key{Comp: []string{tblKey}})
if exstErr != nil {
log.Info("Table Entry from which the fields are to be deleted does not exist")
err = exstErr
return err
log.Info("Table Entry from which the fields are to be deleted does not exist. Ignore error for non existant instance for idempotency")
continue
}
/* handle leaf-list merge if any leaf-list exists */
resTblRw := checkAndProcessLeafList(existingEntry, tblRw, DELETE, d, tblNm, tblKey)
Expand Down
64 changes: 63 additions & 1 deletion translib/transformer/test/sonic-test-xfmr.yang
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,40 @@ module sonic-test-xfmr {
leaf description {
type string;
}
leaf reset-time {
leaf reset_time {
type uint32;
default 5;
}
}
container global_sensor_timer {
leaf timer_mode {
type string;
}
leaf timer_description {
type string;
}
leaf reset_time {
type uint32;
default 5;
}
}
list TEST_SENSOR_GLOBAL_LIST {
key "device_name device_id";
leaf device_name {
type string;
}
leaf device_id {
type uint32;
}
leaf device_status {
type enumeration {
enum ON;
enum OFF;
}
}

}

}

container TEST_INTERFACE_MODE_TABLE {
Expand Down Expand Up @@ -278,5 +307,38 @@ module sonic-test-xfmr {
}
}

container TEST_CABLE_LENGTH {

description "TEST_CABLE_LENGTH to test nested list yang support";

list TEST_CABLE_LENGTH_LIST {
key "name";

leaf name {
type string {
length 1..32 {
error-message "Invalid length for the cable length list name.";
error-app-tag cable-length-invalid-list-name-length;
}
}
}
list TEST_CABLE_LENGTH {
key "port";
leaf port {
type leafref {
path "../../../../TEST_INTERFACE_MODE_TABLE/TEST_INTERFACE_MODE_TABLE_LIST/name";
}
}
leaf length {
type string {
pattern '[0-9]+m' {
error-message "Invalid cable length.";
error-app-tag cable-length-invalid-length;
}
}
}
}
}
}
}
}
Loading