From 08cae3d2f4750d98ff210e7ef8323e8e71c53fda Mon Sep 17 00:00:00 2001 From: Wen Bo Li <50884368+wenovus@users.noreply.github.com> Date: Mon, 11 Dec 2023 13:09:54 -0800 Subject: [PATCH] Fix for gnmi_set_test. (#2475) 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 https://github.com/openconfig/featureprofiles/pull/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 <44847441+sachendras@users.noreply.github.com> --- .../set/tests/gnmi_set_test/gnmi_set_test.go | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go b/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go index fd6946fdee3..13247b6abe8 100644 --- a/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go +++ b/feature/system/gnmi/set/tests/gnmi_set_test/gnmi_set_test.go @@ -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 ( @@ -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 {