Skip to content

Commit

Permalink
update to ondatra/gnoi api (openconfig#2265)
Browse files Browse the repository at this point in the history
* update to ondatra/gnoi api

* Update p4rt_daemon_failure_test.go

formatting file

* format file
  • Loading branch information
prinikasn authored Oct 24, 2023
1 parent ce55ad3 commit 74a8884
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
gpb "github.com/openconfig/gnmi/proto/gnmi"
gnps "github.com/openconfig/gnoi/system"
"github.com/openconfig/gnoigo/system"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnmi/oc/acl"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ondatra/ixnet"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
Expand Down Expand Up @@ -906,13 +908,8 @@ func findProcessByName(t *testing.T, dut *ondatra.DUTDevice, pName string) uint6
// gNOIKillProcess kills a daemon on the DUT, given its name and pid.
func gNOIKillProcess(t *testing.T, dut *ondatra.DUTDevice, pName string, pID uint32) {
t.Helper()
gnoiClient := dut.RawAPIs().GNOI(t)
killRequest := &gnps.KillProcessRequest{Name: pName, Pid: pID, Signal: gnps.KillProcessRequest_SIGNAL_TERM, Restart: true}
killResponse, err := gnoiClient.System().KillProcess(context.Background(), killRequest)
killResponse := gnoi.Execute(t, dut, system.NewKillProcessOperation().Name(pName).PID(pID).Signal(gnps.KillProcessRequest_SIGNAL_TERM).Restart(true))
t.Logf("Got kill process response: %v\n\n", killResponse)
if err != nil {
t.Fatalf("Failed to execute gNOI Kill Process, error received: %v", err)
}
}

// setBgpPolicy is used to configure routing policy on DUT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import (
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/otgutils"
gnps "github.com/openconfig/gnoi/system"
"github.com/openconfig/gnoigo/system"
grps "github.com/openconfig/gribi/v1/proto/service"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
)
Expand Down Expand Up @@ -249,13 +251,8 @@ func verifyGRIBIGet(ctx context.Context, t *testing.T, clientA *gribi.Client, du

// gNOIKillProcess kills a daemon on the DUT, given its name and pid.
func gNOIKillProcess(ctx context.Context, t *testing.T, args *testArgs, pName string, pID uint32) {
gnoiClient := args.dut.RawAPIs().GNOI(t)
killRequest := &gnps.KillProcessRequest{Name: pName, Pid: pID, Signal: gnps.KillProcessRequest_SIGNAL_TERM, Restart: true}
killResponse, err := gnoiClient.System().KillProcess(context.Background(), killRequest)
killResponse := gnoi.Execute(t, args.dut, system.NewKillProcessOperation().Name(pName).PID(pID).Signal(gnps.KillProcessRequest_SIGNAL_TERM).Restart(true))
t.Logf("Got kill process response: %v\n\n", killResponse)
if err != nil {
t.Fatalf("Failed to execute gNOI Kill Process, error received: %v", err)
}
}

// findProcessByName uses telemetry to find out the PID of a process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/otgutils"
"github.com/openconfig/gnoigo/system"
"github.com/openconfig/gribigo/chk"
"github.com/openconfig/gribigo/constants"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/binding"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/testt"
"github.com/openconfig/ygot/ygot"

fpb "github.com/openconfig/gnoi/file"
spb "github.com/openconfig/gnoi/system"
aftspb "github.com/openconfig/gribi/v1/proto/service"
)

Expand Down Expand Up @@ -625,17 +626,11 @@ func TestRouteAdditionDuringFailover(t *testing.T) {
awaitSwitchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

gnoiClient := dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
}
t.Logf("switchoverRequest: %v", switchoverRequest)

// Concurrently run switchover and gribi route addition in ipBlock2.
virtualIPsBlock2 := createIPv4Entries(t, ipBlock2FlowArgs.ipBlock)

// Check for coredumps in the DUT and validate that none are present on DUT before switchover.
gnoiClient := dut.RawAPIs().GNOI(t)
coreFileCheck(t, dut, gnoiClient, sysConfigTime, false)

wg := new(sync.WaitGroup)
Expand All @@ -649,11 +644,8 @@ func TestRouteAdditionDuringFailover(t *testing.T) {

go func() {
defer wg.Done()
switchoverResponse, err := gnoiClient.System().SwitchControlProcessor(context.Background(), switchoverRequest)
if err != nil {
t.Logf("Failed to perform control processor switchover with unexpected err: %v", err)
}
t.Logf("gnoiClient.System().SwitchControlProcessor() response: %v, err: %v", switchoverResponse, err)
switchoverResponse := gnoi.Execute(t, dut, system.NewSwitchControlProcessorOperation().Path(cmp.GetSubcomponentPath(secondaryBeforeSwitch, deviations.GNOISubcomponentPath(dut))))
t.Logf("swtichover process response: %v", switchoverResponse)
}()
wg.Wait()
t.Log("Concurrent switchover and route addition is completed, validate switchoverStatus now.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/otgutils"
"github.com/openconfig/gnoigo/system"
gpb "github.com/openconfig/gribi/v1/proto/service"
"github.com/openconfig/gribigo/chk"
"github.com/openconfig/gribigo/constants"
Expand All @@ -40,11 +41,11 @@ import (
"github.com/openconfig/ondatra/binding"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/testt"
"github.com/openconfig/ygot/ygot"

fpb "github.com/openconfig/gnoi/file"
spb "github.com/openconfig/gnoi/system"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -585,13 +586,6 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
switchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

var gnoiClient binding.GNOIClients = dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
}
t.Logf("switchoverRequest: %v", switchoverRequest)

entriesBefore := checkNIHasNEntries(ctx, client, deviations.DefaultNetworkInstance(dut), t)

// Concurrently run switchover and gribi route flush.
Expand All @@ -608,11 +602,8 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
}("gRIBi Flush")

go func(msg string) {
switchoverResponse, err := gnoiClient.System().SwitchControlProcessor(context.Background(), switchoverRequest)
if err != nil {
t.Logf("Failed to perform control processor switchover with unexpected err: %v", err)
}
t.Logf("gnoiClient.System().SwitchControlProcessor() response: %v, err: %v", switchoverResponse, err)
switchoverResponse := gnoi.Execute(t, dut, system.NewSwitchControlProcessorOperation().Path(cmp.GetSubcomponentPath(secondaryBeforeSwitch, deviations.GNOISubcomponentPath(dut))))
t.Logf("gnoiClient.System().SwitchControlProcessor() response: %v", switchoverResponse)
}("Master Switchover")

// Check the response of gribi flush call. If-else loop for further verification
Expand Down Expand Up @@ -680,7 +671,7 @@ func TestRouteRemovalDuringFailover(t *testing.T) {

// Check for coredumps in the DUT and validate that none are present post failover.
// Reconnect gnoi connection after switchover.
gnoiClient, err = dut.RawAPIs().BindingDUT().DialGNOI(context.Background())
gnoiClient, err := dut.RawAPIs().BindingDUT().DialGNOI(context.Background())
if err != nil {
t.Fatalf("Error dialing gNOI: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package p4rt_daemon_failure_test

import (
"context"
"fmt"
"testing"
"time"
Expand All @@ -26,10 +25,12 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/p4rtutils"
"github.com/openconfig/gnoigo/system"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"

Expand Down Expand Up @@ -281,18 +282,8 @@ func TestP4RTDaemonFailure(t *testing.T) {
t.Fatal(err)
}

c := dut.RawAPIs().GNOI(t)
req := &syspb.KillProcessRequest{
Name: p4rtD,
Pid: uint32(pID),
Signal: syspb.KillProcessRequest_SIGNAL_TERM,
Restart: true,
}
resp, err := c.System().KillProcess(context.Background(), req)
resp := gnoi.Execute(t, dut, system.NewKillProcessOperation().Name(p4rtD).PID(uint32(pID)).Signal(syspb.KillProcessRequest_SIGNAL_TERM).Restart(true))
t.Logf("Got kill process response: %v", resp)
if err != nil {
t.Fatalf("Failed to execute gNOI.KillProcess, error received: %v", err)
}

// let traffic keep running for another 10 seconds.
time.Sleep(10 * time.Second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/otgutils"
"github.com/openconfig/gnoigo/system"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/ondatra"
"github.com/openconfig/testt"
"github.com/openconfig/ygot/ygot"

spb "github.com/openconfig/gnoi/system"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ygnmi/ygnmi"
)

Expand Down Expand Up @@ -327,17 +328,8 @@ func TestSupFailure(t *testing.T) {
t.Fatalf("Controller %q did not become switchover-ready before test.", primaryBeforeSwitch)
}

gnoiClient := dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
}
t.Logf("switchoverRequest: %v", switchoverRequest)
switchoverResponse, err := gnoiClient.System().SwitchControlProcessor(context.Background(), switchoverRequest)
if err != nil {
t.Fatalf("Failed to perform control processor switchover with unexpected err: %v", err)
}
t.Logf("gnoiClient.System().SwitchControlProcessor() response: %v, err: %v", switchoverResponse, err)
switchoverResponse := gnoi.Execute(t, dut, system.NewSwitchControlProcessorOperation().Path(cmp.GetSubcomponentPath(secondaryBeforeSwitch, deviations.GNOISubcomponentPath(dut))))
t.Logf("gnoiClient.System().SwitchControlProcessor() response: %v", switchoverResponse)

startSwitchover := time.Now()
t.Logf("Wait for new Primary controller to boot up by polling the telemetry output.")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/networkop/meshnet-cni v0.3.1-0.20230525201116-d7c306c635cf // indirect
github.com/open-traffic-generator/ixia-c-operator v0.3.4 // indirect
github.com/openconfig/gnoigo v0.0.0-20231012221859-8e2e9ed42daf // indirect
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70 // indirect
github.com/openconfig/lemming/operator v0.2.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,8 @@ github.com/openconfig/gnmi v0.10.0 h1:kQEZ/9ek3Vp2Y5IVuV2L/ba8/77TgjdXg505QXvYmg
github.com/openconfig/gnmi v0.10.0/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E=
github.com/openconfig/gnoi v0.1.0 h1:7Odq6UyieHuXW3PYfDBj/dUWgFrL9KVMm0iooQoFLdw=
github.com/openconfig/gnoi v0.1.0/go.mod h1:ZMRwQ7maVNSOjie3Jn67fW5WY7UDrFSiYSlV/GxthQs=
github.com/openconfig/gnoigo v0.0.0-20231012221859-8e2e9ed42daf h1:dBfRZxlBin+uce9hhUktwogTnvt5DUhSLL24M8vi8fg=
github.com/openconfig/gnoigo v0.0.0-20231012221859-8e2e9ed42daf/go.mod h1:zF1zdUBtlwkzecPyNQk5GSlY+wtjObWeDUE2fA/9UFE=
github.com/openconfig/gnsi v1.2.3 h1:Y/fBMQOn5xqdo9xuT7AK2YHSRejx/ws4sDOMBCHQG6w=
github.com/openconfig/gnsi v1.2.3/go.mod h1:QikTHkm468uc2rq/kVhETfyZ6FPeM+zitubrHBbB0HE=
github.com/openconfig/gocloser v0.0.0-20220310182203-c6c950ed3b0b h1:NSYuxdlOWLldNpid1dThR6Dci96juXioUguMho6aliI=
Expand Down

0 comments on commit 74a8884

Please sign in to comment.