Skip to content

Commit

Permalink
Use simplified RawAPIs calls to fetch default clients (openconfig#2104)
Browse files Browse the repository at this point in the history
* Use simplified RawAPIs calls to fetch default/existing clients

* Fix route_removal_during_failover_tests
  • Loading branch information
greg-dennis authored Sep 11, 2023
1 parent 88b828f commit c40bd73
Show file tree
Hide file tree
Showing 67 changed files with 99 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func configACLNative(t testing.TB, d *ondatra.DUTDevice, name string) {
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
t.Fatalf("Unexpected error configuring SRL ACL: %v", err)
}
Expand Down Expand Up @@ -618,7 +618,7 @@ func configAdmitAllACLNative(t testing.TB, d *ondatra.DUTDevice, name string) {
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbDelRequest); err != nil {
t.Fatalf("Unexpected error removing SRL ACL: %v", err)
}
Expand Down Expand Up @@ -667,7 +667,7 @@ func configACLInterfaceNative(t *testing.T, d *ondatra.DUTDevice, ifName string)
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
t.Fatalf("Unexpected error configuring interface ACL: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func juniperCLI() string {
func configureRegexPolicy(t *testing.T, dut *ondatra.DUTDevice) {
t.Helper()
var config string
gnmiClient := dut.RawAPIs().GNMI().Default(t)
gnmiClient := dut.RawAPIs().GNMI(t)

switch dut.Vendor() {
case ondatra.JUNIPER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func configACLNative(t testing.TB, d *ondatra.DUTDevice, name string) {
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
t.Fatalf("Unexpected error configuring SRL ACL: %v", err)
}
Expand Down Expand Up @@ -761,7 +761,7 @@ func configAdmitAllACLNative(t testing.TB, d *ondatra.DUTDevice, name string) {
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbDelRequest); err != nil {
t.Fatalf("Unexpected error removing SRL ACL: %v", err)
}
Expand Down Expand Up @@ -810,7 +810,7 @@ func configACLInterfaceNative(t *testing.T, d *ondatra.DUTDevice, ifName string)
},
},
}
gnmiClient := d.RawAPIs().GNMI().Default(t)
gnmiClient := d.RawAPIs().GNMI(t)
if _, err := gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
t.Fatalf("Unexpected error configuring interface ACL: %v", err)
}
Expand Down Expand Up @@ -906,7 +906,7 @@ 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().Default(t)
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)
t.Logf("Got kill process response: %v\n\n", killResponse)
Expand Down Expand Up @@ -1275,7 +1275,7 @@ func TestTrafficWithGracefulRestart(t *testing.T) {
})

t.Run("Disable LLGR on dut.", func(t *testing.T) {
gnmiClient := dut.RawAPIs().GNMI().Default(t)
gnmiClient := dut.RawAPIs().GNMI(t)
config := disableLLGRConf(dut, dutAS)
t.Logf("Push the CLI config:%s", dut.Vendor())
gpbSetRequest := buildCliConfigRequest(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ 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().Default(t)
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)
t.Logf("Got kill process response: %v\n\n", killResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestRouteAdditionDuringFailover(t *testing.T) {
ate := ondatra.ATE(t, "ate")

ctx := context.Background()
gribic := dut.RawAPIs().GRIBI().Default(t)
gribic := dut.RawAPIs().GRIBI(t)
dp1 := dut.Port(t, "port1")
ap1 := ate.Port(t, "port1")
top := ate.Topology().New()
Expand Down Expand Up @@ -597,7 +597,7 @@ func TestRouteAdditionDuringFailover(t *testing.T) {
awaitSwitchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

gnoiClient := dut.RawAPIs().GNOI().Default(t)
gnoiClient := dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"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/raw"
Expand Down Expand Up @@ -455,7 +456,7 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
ate := ondatra.ATE(t, "ate")

ctx := context.Background()
gribic := dut.RawAPIs().GRIBI().Default(t)
gribic := dut.RawAPIs().GRIBI(t)
dp1 := dut.Port(t, "port1")
ap1 := ate.Port(t, "port1")
top := ate.Topology().New()
Expand Down Expand Up @@ -557,7 +558,7 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
switchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

gnoiClient := dut.RawAPIs().GNOI().Default(t)
var gnoiClient binding.GNOIClients = dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ 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().Default(t)
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)
t.Logf("Got kill process response: %v\n\n", killResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func TestRouteAdditionDuringFailover(t *testing.T) {
ate := ondatra.ATE(t, "ate")

ctx := context.Background()
gribic := dut.RawAPIs().GRIBI().Default(t)
gribic := dut.RawAPIs().GRIBI(t)
dp1 := dut.Port(t, "port1")
ap1 := ate.Port(t, "port1")
top := ate.OTG().NewConfig(t)
Expand Down Expand Up @@ -628,7 +628,7 @@ func TestRouteAdditionDuringFailover(t *testing.T) {
awaitSwitchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

gnoiClient := dut.RawAPIs().GNOI().Default(t)
gnoiClient := dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"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/raw"
Expand Down Expand Up @@ -478,7 +479,7 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
ate := ondatra.ATE(t, "ate")

ctx := context.Background()
gribic := dut.RawAPIs().GRIBI().Default(t)
gribic := dut.RawAPIs().GRIBI(t)
dp1 := dut.Port(t, "port1")
ap1 := ate.Port(t, "port1")
top := ate.OTG().NewConfig(t)
Expand Down Expand Up @@ -588,7 +589,7 @@ func TestRouteRemovalDuringFailover(t *testing.T) {
switchoverReady(t, dut, primaryBeforeSwitch)
t.Logf("Controller %q is ready for switchover before test.", primaryBeforeSwitch)

gnoiClient := dut.RawAPIs().GNOI().Default(t)
var gnoiClient binding.GNOIClients = dut.RawAPIs().GNOI(t)
useNameOnly := deviations.GNOISubcomponentPath(dut)
switchoverRequest := &spb.SwitchControlProcessorRequest{
ControlProcessor: cmp.GetSubcomponentPath(secondaryBeforeSwitch, useNameOnly),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func New(t testing.TB) (*TestSession, error) {
s := &TestSession{}
s.DUT = ondatra.DUT(t, "dut")
var err error
s.DUTClient, err = ygnmi.NewClient(s.DUT.RawAPIs().GNMI().Default(t), ygnmi.WithTarget(s.DUT.ID()))
s.DUTClient, err = ygnmi.NewClient(s.DUT.RawAPIs().GNMI(t), ygnmi.WithTarget(s.DUT.ID()))
if err != nil {
return nil, fmt.Errorf("unable to connect to gNMI on %v: %w", s.DUT, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func New(t testing.TB) (*TestSession, error) {
s := &TestSession{}
s.DUT = ondatra.DUT(t, "dut")
var err error
s.DUTClient, err = ygnmi.NewClient(s.DUT.RawAPIs().GNMI().Default(t), ygnmi.WithTarget(s.DUT.ID()))
s.DUTClient, err = ygnmi.NewClient(s.DUT.RawAPIs().GNMI(t), ygnmi.WithTarget(s.DUT.ID()))
if err != nil {
return nil, fmt.Errorf("unable to connect to gNMI on %v: %w", s.DUT, err)
}
Expand Down
2 changes: 1 addition & 1 deletion feature/experimental/p4rt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This document specifies the requirements for p4rt test implementation.
function, which sets up the `StreamTermErr` channel required to check errors
when the p4rt stream terminates.

4. Tests should make use of Ondatra Raw API `dut.RawAPIs().P4RT().Default(t)`
4. Tests should make use of Ondatra Raw API `dut.RawAPIs().P4RT(t)`
during client instantiation.

5. Tests should log Stream Termination errors populated in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ func TestP4rtConnect(t *testing.T) {

// Setup two different clients for different FAPs
client1 := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := client1.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := client1.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

client2 := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := client2.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := client2.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@ func TestPacketIn(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ func TestPacketOut(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ func TestPacketIn(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ func TestPacketOut(t *testing.T) {
gnmi.Replace(t, dut, gnmi.OC().Lldp().Enabled().Config(), false)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestP4RTDaemonFailure(t *testing.T) {
t.Fatal(err)
}

c := dut.RawAPIs().GNOI().Default(t)
c := dut.RawAPIs().GNOI(t)
req := &syspb.KillProcessRequest{
Name: p4rtD,
Pid: uint32(pID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func TestP4rtPerformance(t *testing.T) {
configureDeviceID(t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ func TestPacketIn(t *testing.T) {
top.Push(t).StartProtocols(t)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestPacketOut(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ func TestP4rtConnect(t *testing.T) {

// Setup two different clients for different FAPs
client1 := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := client1.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := client1.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

client2 := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := client2.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := client2.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,12 @@ func TestPacketIn(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ func TestPacketOut(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ func TestPacketIn(t *testing.T) {
configureDeviceID(ctx, t, dut)

leader := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := leader.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

follower := p4rt_client.NewP4RTClient(&p4rt_client.P4RTClientParameters{})
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT().Default(t)); err != nil {
if err := follower.P4rtClientSet(dut.RawAPIs().P4RT(t)); err != nil {
t.Fatalf("Could not initialize p4rt client: %v", err)
}

Expand Down
Loading

0 comments on commit c40bd73

Please sign in to comment.