Skip to content

Commit

Permalink
Fix for gnmi_set_test. (openconfig#2475)
Browse files Browse the repository at this point in the history
There was a breaking change to the schemaless queries in ygnmi that caused it.

This is a short-term fix. The longterm fix is at
openconfig#2472 but there was a
bug exposed that needed to be addressed first.

Tested manually that the SetRequest JSON now contains "config" leaves.

Co-authored-by: sachendras <[email protected]>
  • Loading branch information
wenovus and sachendras authored Dec 11, 2023
1 parent 157a5ae commit 08cae3d
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/netutil"
"github.com/openconfig/ygnmi/schemaless"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
)

var (
Expand Down Expand Up @@ -895,15 +895,66 @@ var (
)

func init() {
var err error
interfacesQuery, err = schemaless.NewConfig[*Interfaces]("/interfaces", "openconfig")
// TODO(wenovus): Remove this workaround using ygnmi's Map() API once
// SetBatch is fixed for Map() API.
interfacesQuery = ygnmi.NewConfigQuery[*Interfaces](
"",
false,
true,
true,
false,
false,
false,
createPS("/interfaces"),
func(vgs ygot.ValidatedGoStruct) (*Interfaces, bool) {
return new(Interfaces), true
},
func() ygot.ValidatedGoStruct {
return nil
},
func() *ytypes.Schema { return nil },
nil,
nil,
)
networkInstancesQuery = ygnmi.NewConfigQuery[*NetworkInstances](
"",
false,
true,
true,
false,
false,
false,
createPS("/network-instances"),
func(vgs ygot.ValidatedGoStruct) (*NetworkInstances, bool) {
return new(NetworkInstances), true
},
func() ygot.ValidatedGoStruct {
return nil
},
func() *ytypes.Schema { return nil },
nil,
nil,
)
}

func createPS(path string) ygnmi.PathStruct {
root := ygnmi.NewDeviceRootBase()
root.PutCustomData(ygnmi.OriginOverride, "openconfig")

var ps ygnmi.PathStruct = root
protoPath, err := ygot.StringToStructuredPath(path)
if err != nil {
panic(err)
}
networkInstancesQuery, err = schemaless.NewConfig[*NetworkInstances]("/network-instances", "openconfig")
if err != nil {
panic(err)
for _, elem := range protoPath.Elem {
keys := map[string]interface{}{}
for key, val := range elem.Key {
keys[key] = val
}
ps = ygnmi.NewNodePath([]string{elem.Name}, keys, ps)
}

return ps
}

type Interfaces struct {
Expand Down

0 comments on commit 08cae3d

Please sign in to comment.