Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Ondatra version & refactor g_protocol_test #2523

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 27 additions & 109 deletions feature/system/tests/system_base_test/g_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,167 +18,85 @@ package system_base_test

import (
"context"
"crypto/tls"
"fmt"
"testing"
"time"

"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/binding"
"github.com/openconfig/ondatra/knebind/creds"
"github.com/openconfig/ondatra/binding/introspect"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

gpb "github.com/openconfig/gnmi/proto/gnmi"
spb "github.com/openconfig/gnoi/system"
authzpb "github.com/openconfig/gnsi/authz"
gribipb "github.com/openconfig/gribi/v1/proto/service"
tpb "github.com/openconfig/kne/proto/topo"
p4rtpb "github.com/p4lang/p4runtime/go/p4/v1"
)

func resolveService(t *testing.T, dut *ondatra.DUTDevice, serviceName string, wantPort uint32) string {
func dialConn(t *testing.T, dut *ondatra.DUTDevice, svc introspect.Service, wantPort uint32) *grpc.ClientConn {
t.Helper()
var servDUT interface {
Service(string) (*tpb.Service, error)
}
if err := binding.DUTAs(dut.RawAPIs().BindingDUT(), &servDUT); err != nil {
t.Skipf("DUT does not support Service function: %v", err)
}
if serviceName == "gnoi" || serviceName == "gnsi" {
if svc == introspect.GNOI || svc == introspect.GNSI {
// Renaming service name due to gnoi and gnsi always residing on same port as gnmi.
serviceName = "gnmi"
svc = introspect.GNMI
}
s, err := servDUT.Service(serviceName)
if err != nil {
t.Fatal(err)
dialer := introspect.DUTDialer(t, dut, introspect.GNMI)
if dialer.DevicePort != int(wantPort) {
t.Fatalf("DUT is not listening on correct port for %q: got %d, want %d", svc, dialer.DevicePort, wantPort)
}
if s.GetInside() != wantPort {
t.Fatalf("DUT is not listening on correct port for %q: got %d, want %d", serviceName, s.GetInside(), wantPort)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := dialer.Dial(ctx)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", dialer.DialTarget)
}
return fmt.Sprintf("%s:%d", s.GetOutsideIp(), s.GetOutside())

}

type rpcCredentials struct {
*creds.UserPass
}

func (r *rpcCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{
"username": "admin",
"password": "admin",
}, nil
}

func (r *rpcCredentials) RequireTransportSecurity() bool {
return true
return conn
}

// TestGNMIClient validates that the DUT listens on standard gNMI Port.
func TestGNMIClient(t *testing.T) {
dut := ondatra.DUT(t, "dut")
target := resolveService(t, dut, "gnmi", 9339)
credOpts := []grpc.DialOption{grpc.WithBlock(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true}))} // NOLINT
creds := &rpcCredentials{}
credOpts = append(credOpts, grpc.WithPerRPCCredentials(creds))
t.Logf("gNMI standard port test: %q", target)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, target, credOpts...)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", target)
}
conn := dialConn(t, dut, introspect.GNMI, 9339)
c := gpb.NewGNMIClient(conn)
if _, err := c.Get(context.Background(), &gpb.GetRequest{}); err != nil {
t.Fatalf("gnmi.Get failed: %v", err)
}
}

// TestGNOIClient validates that the DUT listens on standard gNMI Port.
// TestGNOIClient validates that the DUT listens on standard gNOI Port.
func TestGNOIClient(t *testing.T) {
dut := ondatra.DUT(t, "dut")
target := resolveService(t, dut, "gnoi", 9339)
credOpts := []grpc.DialOption{grpc.WithBlock(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true}))} // NOLINT
creds := &rpcCredentials{}
credOpts = append(credOpts, grpc.WithPerRPCCredentials(creds))

t.Logf("gNOI standard port test: %q", target)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, target, credOpts...)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", target)
}
conn := dialConn(t, dut, introspect.GNOI, 9339)
c := spb.NewSystemClient(conn)
_, err = c.Ping(context.Background(), &spb.PingRequest{})
if err != nil {
t.Fatalf("gnoi.system.Time failed: %v", err)
if _, err := c.Ping(context.Background(), &spb.PingRequest{}); err != nil {
t.Fatalf("gnoi.system.Ping failed: %v", err)
}
}

// TestGNSIClient validates that the DUT listens on standard gNMI Port.
// TestGNSIClient validates that the DUT listens on standard gNSI Port.
func TestGNSIClient(t *testing.T) {
dut := ondatra.DUT(t, "dut")
target := resolveService(t, dut, "gnsi", 9339)
credOpts := []grpc.DialOption{grpc.WithBlock(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true}))} // NOLINT
creds := &rpcCredentials{}
credOpts = append(credOpts, grpc.WithPerRPCCredentials(creds))

t.Logf("gNSI standard port test: %q", target)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, target, credOpts...)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", target)
}
conn := dialConn(t, dut, introspect.GNSI, 9339)
c := authzpb.NewAuthzClient(conn)
_, err = c.Get(context.Background(), &authzpb.GetRequest{})
if err != nil {
if _, err := c.Get(context.Background(), &authzpb.GetRequest{}); err != nil {
t.Fatalf("gnsi.authz.Get failed: %v", err)
}
}

// TestGRIBIClient validates that the DUT listens on standard gNMI Port.
// TestGRIBIClient validates that the DUT listens on standard gRIBI Port.
func TestGRIBIClient(t *testing.T) {
dut := ondatra.DUT(t, "dut")
target := resolveService(t, dut, "gribi", 9340)
credOpts := []grpc.DialOption{grpc.WithBlock(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true}))} // NOLINT
creds := &rpcCredentials{}
credOpts = append(credOpts, grpc.WithPerRPCCredentials(creds))

t.Logf("gRIBI standard port test: %q", target)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, target, credOpts...)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", target)
}
conn := dialConn(t, dut, introspect.GRIBI, 9340)
c := gribipb.NewGRIBIClient(conn)
_, err = c.Get(context.Background(), &gribipb.GetRequest{})
if err != nil {
if _, err := c.Get(context.Background(), &gribipb.GetRequest{}); err != nil {
t.Fatalf("gribi.Get failed: %v", err)
}
}

// TestP4RTClient validates that the DUT listens on standard gNMI Port.
// TestP4RTClient validates that the DUT listens on standard P4RT Port.
func TestP4RTClient(t *testing.T) {
dut := ondatra.DUT(t, "dut")
target := resolveService(t, dut, "p4rt", 9559)
credOpts := []grpc.DialOption{grpc.WithBlock(), grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true}))} // NOLINT
creds := &rpcCredentials{}
credOpts = append(credOpts, grpc.WithPerRPCCredentials(creds))

t.Logf("P4RT standard port test: %q", target)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, target, credOpts...)
if err != nil {
t.Fatalf("grpc.Dial failed to: %q", target)
}
conn := dialConn(t, dut, introspect.P4RT, 9559)
c := p4rtpb.NewP4RuntimeClient(conn)
_, err = c.Capabilities(context.Background(), &p4rtpb.CapabilitiesRequest{})
if err != nil {
if _, err := c.Capabilities(context.Background(), &p4rtpb.CapabilitiesRequest{}); err != nil {
t.Fatalf("p4rt.Capabilites failed: %v", err)
}
}
29 changes: 16 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ require (
github.com/openconfig/gnoigo v0.0.0-20231026010722-87413fdb22e7
github.com/openconfig/gnsi v1.2.3
github.com/openconfig/gocloser v0.0.0-20220310182203-c6c950ed3b0b
github.com/openconfig/goyang v1.4.4
github.com/openconfig/goyang v1.4.5
github.com/openconfig/gribi v1.0.0
github.com/openconfig/gribigo v0.0.0-20231031140438-9a293da13ff9
github.com/openconfig/kne v0.1.14
github.com/openconfig/models-ci v1.0.2-0.20231113233730-f0986391428e
github.com/openconfig/ondatra v0.4.6
github.com/openconfig/ondatra v0.4.8
github.com/openconfig/replayer v0.0.0-20231031192218-5462382820d4
github.com/openconfig/testt v0.0.0-20220311054427-efbb1a32ec07
github.com/openconfig/ygnmi v0.11.0
github.com/openconfig/ygot v0.29.17
github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e
github.com/protocolbuffers/txtpbfmt v0.0.0-20220608084003-fc78c767cd6a
golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/text v0.14.0
google.golang.org/api v0.153.0
google.golang.org/grpc v1.60.0
google.golang.org/protobuf v1.31.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -49,7 +49,7 @@ require (
)

require (
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go v0.111.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
Expand All @@ -68,7 +68,8 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand Down Expand Up @@ -122,26 +123,28 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.1 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/srl-labs/srl-controller v0.6.0 // indirect
github.com/srl-labs/srlinux-scrapli v0.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading
Loading