Skip to content

Commit

Permalink
some gnmi.Get() call is replaced by gnmi.Watch() call (#1932)
Browse files Browse the repository at this point in the history
* some gnmi.Get() call is replaced by gnmi.Watch() call

* implemented the changes according to the comments
  • Loading branch information
abhijit-dhar authored Dec 27, 2024
1 parent 6c9012b commit cb4b08b
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions feature/gribi/otg_tests/get_rpc_test/get_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
)

Expand Down Expand Up @@ -316,8 +317,17 @@ func testIPv4LeaderActive(ctx context.Context, t *testing.T, args *testArgs) {
// Verify the above entries are active through AFT Telemetry.
for ip := range ateDstNetCIDR {
ipv4Path := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(args.dut)).Afts().Ipv4Entry(ateDstNetCIDR[ip])
if got, want := gnmi.Get(t, args.dut, ipv4Path.State()).GetPrefix(), ateDstNetCIDR[ip]; got != want {
t.Errorf("ipv4-entry/state/prefix got %s, want %s", got, want)
lastValue, ok := gnmi.Watch(t, args.dut, ipv4Path.State(), time.Minute, func(v *ygnmi.Value[*oc.NetworkInstance_Afts_Ipv4Entry]) bool {
return v.IsPresent()
}).Await(t)

if !ok {
t.Fatalf("gnmi.Watch() failed value received = %s", lastValue)
}

ipv4, _ := lastValue.Val()
if got, want := ipv4.GetPrefix(), ateDstNetCIDR[ip]; got != want {
t.Fatalf("ipv4-entry/state/prefix got %s, want %s", got, want)
}
}

Expand Down Expand Up @@ -345,9 +355,18 @@ func testIPv4LeaderActive(ctx context.Context, t *testing.T, args *testArgs) {
gnmi.Update(t, args.dut, niProto.Config(), static)
validateGetRPC(ctx, t, args.clientA)
for ip := range ateDstNetCIDR {
ipv4Path := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(args.dut)).Afts().Ipv4Entry(ateDstNetCIDR[ip])
if got, want := gnmi.Get(t, args.dut, ipv4Path.State()).GetPrefix(), ateDstNetCIDR[ip]; got != want {
t.Errorf("ipv4-entry/state/prefix got %s, want %s", got, want)
ipv4Path := gnmi.OC().NetworkInstance(deviations.DefaultNetworkInstance(args.dut)).Afts().Ipv4Entry(ateDstNetCIDR[ip])
lastValue, ok := gnmi.Watch(t, args.dut, ipv4Path.State(), time.Minute, func(v *ygnmi.Value[*oc.NetworkInstance_Afts_Ipv4Entry]) bool {
return v.IsPresent()
}).Await(t)

if !ok {
t.Fatalf("gnmi.Watch() failed value received = %s", lastValue)
}

ipv4, _ := lastValue.Val()
if got, want := ipv4.GetPrefix(), ateDstNetCIDR[ip]; got != want {
t.Fatalf("ipv4-entry/state/prefix got %s, want %s", got, want)
}
}

Expand Down

0 comments on commit cb4b08b

Please sign in to comment.