Skip to content
Snippets Groups Projects

Draft: Resolve "Deal with read-only fields in YANG"

Closed Ghost User requested to merge 258-deal-with-read-only-fields-in-yang into develop
2 files
+ 14
41
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -16,7 +16,6 @@ import (
@@ -16,7 +16,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
"github.com/openconfig/ygot/ytypes"
log "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
@@ -123,41 +122,25 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
@@ -123,41 +122,25 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
return customerrs.NoNewChangesError{Original: payload.Original, Modified: payload.Modified}
return customerrs.NoNewChangesError{Original: payload.Original, Modified: payload.Modified}
}
}
var json []byte
if op := ctx.Value(types.CtxKeyOperation); op == ppb.ApiOperation_API_OPERATION_UPDATE || op == ppb.ApiOperation_API_OPERATION_REPLACE {
if op := ctx.Value(types.CtxKeyOperation); op == ppb.ApiOperation_API_OPERATION_UPDATE || op == ppb.ApiOperation_API_OPERATION_REPLACE {
rootCopy, err := ygot.DeepCopy(schema.Root)
if err != nil {
return err
}
 
filteredUpdates := make([]*gpb.Update, 0)
for _, u := range diff.Update {
for _, u := range diff.Update {
opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
rootSchema := schema.RootSchema()
if err := g.SetNode(schema.RootSchema(), rootCopy, u.GetPath(), u.GetVal(), opts...); err != nil {
pathString, err := ygot.PathToString(u.GetPath())
 
if err != nil {
return err
return err
}
}
 
entry := rootSchema.Find(pathString)
 
if !entry.ReadOnly() {
 
filteredUpdates = append(filteredUpdates, u)
 
}
}
}
ygot.PruneEmptyBranches(rootCopy)
diff.Update = filteredUpdates
opts := []ytypes.GetNodeOpt{
&ytypes.GetHandleWildcards{},
}
nodes, err := ytypes.GetNode(schema.RootSchema(), rootCopy, path, opts...)
if err != nil {
return err
}
if len(nodes) == 0 || err != nil || util.IsValueNil(nodes[0].Data) {
return customerrs.PathNotFoundError{Path: path, Err: err}
}
json, err = ygot.Marshal7951(nodes[0].Data, &ygot.RFC7951JSONConfig{AppendModuleName: true})
if err != nil {
return err
}
}
}
req, err := createSetRequest(ctx, diff, json, path)
req, err := createSetRequest(ctx, diff)
if err != nil {
if err != nil {
return err
return err
}
}
@@ -167,25 +150,15 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
@@ -167,25 +150,15 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb.
return err
return err
}
}
func createSetRequest(ctx context.Context, diff *gpb.Notification, json []byte, path *gpb.Path) (*gpb.SetRequest, error) {
func createSetRequest(ctx context.Context, diff *gpb.Notification) (*gpb.SetRequest, error) {
op := ctx.Value(types.CtxKeyOperation)
op := ctx.Value(types.CtxKeyOperation)
req := &gpb.SetRequest{}
req := &gpb.SetRequest{}
if diff.Update != nil {
if diff.Update != nil {
switch op {
switch op {
case ppb.ApiOperation_API_OPERATION_UPDATE:
case ppb.ApiOperation_API_OPERATION_UPDATE:
req.Update = []*gpb.Update{{
req.Update = diff.Update
Path: path,
Val: &gpb.TypedValue{
Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json},
},
}}
case ppb.ApiOperation_API_OPERATION_REPLACE:
case ppb.ApiOperation_API_OPERATION_REPLACE:
req.Replace = []*gpb.Update{{
req.Replace = diff.Update
Path: path,
Val: &gpb.TypedValue{
Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json},
},
}}
default:
default:
return nil, &customerrs.OperationNotSupportedError{Op: op}
return nil, &customerrs.OperationNotSupportedError{Op: op}
}
}
Loading