Skip to content

Commit

Permalink
Merge branch 'main' into refactor-policytest
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus authored Jun 12, 2024
2 parents d13b9d0 + 683cacf commit 2b3b9f5
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 52 deletions.
7 changes: 5 additions & 2 deletions .github/linters/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
run:
timeout: 60m
skip-dirs:
issues:
exclude-dirs:
- gnmi/oc
- integration_tests # Loading ondatra is very slow
issues:
exclude:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gosec
- goconst
- path: gribi/gribi.go
text: "grpc.Dial is deprecated" # TODO(https://github.com/openconfig/lemming/issues/433): bgp/tests/local_tests -- TestRoutePropagation fails.
linters:
disable-all: true
enable:
Expand Down
4 changes: 2 additions & 2 deletions bgp/tests/local_tests/session_establish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var (

func ygnmiClient(t *testing.T, target, dialTarget string) *ygnmi.Client {
t.Helper()
conn, err := grpc.Dial(dialTarget, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(dialTarget, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func newLemming(t *testing.T, id uint, as uint32, connectedIntfs []*AddIntfActio
configureInterface(t, intf, l.GNMI())
}

conn, err := grpc.Dial(gribiTarget, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(gribiTarget, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dataplane/luciusctl/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ func dial() (*grpc.ClientConn, error) {
opts = grpc.WithTransportCredentials(insecure.NewCredentials())
}

return grpc.Dial(viper.GetString("address"), opts)
return grpc.NewClient(viper.GetString("address"), opts)
}
2 changes: 1 addition & 1 deletion dataplane/luciusctl/sai/sai.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ func dial() (*grpc.ClientConn, error) {
opts = grpc.WithTransportCredentials(insecure.NewCredentials())
}

return grpc.Dial(viper.GetString("address"), opts)
return grpc.NewClient(viper.GetString("address"), opts)
}
18 changes: 9 additions & 9 deletions dataplane/saiserver/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ func (vlan *vlan) CreateVlanMember(ctx context.Context, r *saipb.CreateVlanMembe
ObjectId: &fwdpb.ObjectId{Id: fmt.Sprint(r.GetBridgePortId())},
})
if err != nil {
log.Infof("Failed to find NID for port id=%d: %v", r.GetBridgePortId(), err)
return nil, err
}
vlanReq := fwdconfig.TableEntryAddRequest(vlan.dataplane.ID(), VlanTable).AppendEntry(
Expand Down Expand Up @@ -934,17 +935,16 @@ func (vlan *vlan) RemoveVlanMember(ctx context.Context, r *saipb.RemoveVlanMembe
if member == nil {
return nil, fmt.Errorf("cannot find member with OID %d", r.GetOid())
}
defVOid, ok := vlan.oidByVId[DefaultVlanId]
if !ok {
return nil, fmt.Errorf("cannot find default VLAN.")
}
// Move the port back to the default VLAN.
_, err := attrmgr.InvokeAndSave(ctx, vlan.mgr, vlan.CreateVlanMember, &saipb.CreateVlanMemberRequest{
VlanId: proto.Uint64(defVOid),
BridgePortId: proto.Uint64(member.PortID),
VlanTaggingMode: saipb.VlanTaggingMode_VLAN_TAGGING_MODE_UNTAGGED.Enum(),
nid, err := vlan.dataplane.ObjectNID(ctx, &fwdpb.ObjectNIDRequest{
ContextId: &fwdpb.ContextId{Id: vlan.dataplane.ID()},
ObjectId: &fwdpb.ObjectId{Id: fmt.Sprint(member.PortID)},
})
if err != nil {
log.Infof("Failed to find NID for port id=%d: %v", member.PortID, err)
return nil, err
}
if _, err := vlan.dataplane.TableEntryRemove(ctx, fwdconfig.TableEntryRemoveRequest(vlan.dataplane.ID(), VlanTable).AppendEntry(
fwdconfig.EntryDesc(fwdconfig.ExactEntry(fwdconfig.PacketFieldBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_PACKET_PORT_INPUT).WithUint64(nid.GetNid())))).Build()); err != nil {
return nil, err
}
return &saipb.RemoveVlanMemberResponse{}, nil
Expand Down
2 changes: 1 addition & 1 deletion dataplane/saiserver/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func newTestServer(t testing.TB, newSrvFn func(mgr *attrmgr.AttrMgr, srv *grpc.S
log.Fatalf("failed to serve forwarding server: %v", err)
}
}()
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions dataplane/saiserver/vlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TestVlanOperations(t *testing.T) {
t.Fatalf("Failed to create a non-default VLAN")
}

// Remove one port from the non-default VLAN, and ensure it is moved to the default VLAN.
// Remove one port from the non-default VLAN.
_, err = c.RemoveVlanMember(ctx, &saipb.RemoveVlanMemberRequest{
Oid: testVLANMembers[0],
})
Expand All @@ -244,7 +244,7 @@ func TestVlanOperations(t *testing.T) {
if err != nil {
t.Fatalf("Failed to get members of default VLAN: %v", err)
}
if len(testm) != 1 && len(defaultm) != 3 {
if len(testm) != 1 && len(defaultm) != 2 {
t.Errorf("Failed to remove a non-default VLAN member")
}

Expand All @@ -259,8 +259,8 @@ func TestVlanOperations(t *testing.T) {
if err != nil {
t.Fatalf("Failed to get members of the default VLAN: %v", err)
}
// Ensure all of the 4 ports are now under the default VLAN.
if len(defaultm) != 4 {
// Ensure the default VLAN only has 2 members.
if len(defaultm) != 2 {
t.Errorf("Failed to remove the non-default VLAN")
}
}
Expand Down
2 changes: 1 addition & 1 deletion dataplane/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (d *Dataplane) Start(ctx context.Context, c gpb.GNMIClient, target string)

// FwdClient gets a gRPC client to the packet forwarding engine.
func (d *Dataplane) Conn() (grpc.ClientConnInterface, error) {
conn, err := grpc.Dial(d.lis.Addr().String(), grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(d.lis.Addr().String(), grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("failed to dial server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dataplane/standalone/packetio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const addr = "10.0.2.2:50000"

//export StartSink
func StartSink() {
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 2 additions & 5 deletions dataplane/standalone/pkthandler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"os/signal"
"syscall"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -39,11 +38,8 @@ const (
var portFile = flag.String("port_file", "/etc/sonic/pktio_ports.json", "File at which to include hostif info, for debugging only")

func main() {
ctx, cancelFn := context.WithTimeout(context.Background(), time.Minute)
defer cancelFn()

log.Info("dialing packetio server")
conn, err := grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Exit(err)
}
Expand All @@ -54,6 +50,7 @@ func main() {
if err != nil {
log.Exit(err)
}

ctx, cancel := context.WithCancel(context.Background())

sigCh := make(chan os.Signal, 1)
Expand Down
3 changes: 2 additions & 1 deletion dataplane/standalone/pkthandler/pktiohandler/pktiohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,15 @@ func (m *PacketIOMgr) queueRead(id uint64, done chan struct{}) {
default:
n, err := p.Read(buf)
if err != nil || n == 0 {
time.Sleep(time.Millisecond)
continue
}
pkt := &pktiopb.Packet{
HostPort: id,
Frame: buf[0:n],
}
m.sendQueue.Write(pkt)
time.Sleep(time.Microsecond)
time.Sleep(time.Millisecond)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion gnmi/gnmi_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func BenchmarkGNMISet(b *testing.B) {
b.Fatalf("cannot start server, got err: %v", err)
}
defer gnmiServer.c.Stop()
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
b.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions gnmi/gnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func testSetSubSetup(t *testing.T, prefix, path *gpb.Path, useSet, config bool)
t.Fatalf("cannot start server, got err: %v", err)
}

conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down Expand Up @@ -751,7 +751,7 @@ func TestSetYGNMI(t *testing.T) {
}
t.Logf("Running gNMI server on %s", addr)
defer gnmiServer.c.Stop()
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down Expand Up @@ -840,7 +840,7 @@ func TestSetWithAuth(t *testing.T) {
t.Fatalf("cannot start server, got err: %v", err)
}
defer gnmiServer.c.Stop()
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down Expand Up @@ -907,7 +907,7 @@ func TestSTREAM(t *testing.T) {
wg.Add(1)
go func(ctx context.Context, cfn func()) {
defer cfn()
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
sendErr = fmt.Errorf("cannot dial gNMI server, %v", err)
return
Expand Down Expand Up @@ -1124,7 +1124,7 @@ func TestSubscribeWithAuth(t *testing.T) {
},
})
defer gnmiServer.c.Stop()
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion gnsi/pathz/pathz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func start(t testing.TB) (pathzpb.PathzClient, func()) {

go s.Serve(l)

conn, err := grpc.Dial(l.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(l.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed dial server: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion gribi/gribi.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func New(s *grpc.Server, gClient gpb.GNMIClient, target string, root *oc.Root, s
// - root, if specified, will be used to populate connected routes into the RIB
// manager. Note this is intended to be used for unit/standalone device testing.
func createGRIBIServer(gClient gpb.GNMIClient, target string, root *oc.Root, sysribAddr string) (*server.Server, error) {
gzebraConn, err := grpc.DialContext(context.Background(), sysribAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
gzebraConn, err := grpc.Dial(sysribAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("cannot dial to sysrib, %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions internal/binding/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *gnsiClient) Pathz() pathzpb.PathzClient { return pathzpb.NewPathzClient
// DialGNMI returns a gNMI client for the dut.
func (l *localLemming) DialGNMI(ctx context.Context, opts ...grpc.DialOption) (gpb.GNMIClient, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
if err != nil {
return nil, err
}
Expand All @@ -124,7 +124,7 @@ func (l *localLemming) DialGNMI(ctx context.Context, opts ...grpc.DialOption) (g
// DialGNOI returns a gNOI client for the dut.
func (l *localLemming) DialGNOI(ctx context.Context, opts ...grpc.DialOption) (gnoigo.Clients, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
if err != nil {
return nil, err
}
Expand All @@ -134,7 +134,7 @@ func (l *localLemming) DialGNOI(ctx context.Context, opts ...grpc.DialOption) (g
// DialGNSI returns a gNSI client for the dut.
func (l *localLemming) DialGNSI(ctx context.Context, opts ...grpc.DialOption) (binding.GNSIClients, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(l.addr, fmt.Sprint(gnmiPort)), opts...)
if err != nil {
return nil, err
}
Expand All @@ -144,7 +144,7 @@ func (l *localLemming) DialGNSI(ctx context.Context, opts ...grpc.DialOption) (b
// DialGRIBI returns a gRIBI client for the dut.
func (l *localLemming) DialGRIBI(ctx context.Context, opts ...grpc.DialOption) (grpb.GRIBIClient, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(l.addr, fmt.Sprint(gribiPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(l.addr, fmt.Sprint(gribiPort)), opts...)
if err != nil {
return nil, err
}
Expand All @@ -154,7 +154,7 @@ func (l *localLemming) DialGRIBI(ctx context.Context, opts ...grpc.DialOption) (
// DataplaneConn returns a gRPC conn for the dataplane
func (l *localLemming) DataplaneConn(ctx context.Context, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
return grpc.DialContext(ctx, net.JoinHostPort(l.addr, fmt.Sprint(dataplanePort)), opts...)
return grpc.NewClient(net.JoinHostPort(l.addr, fmt.Sprint(dataplanePort)), opts...)
}

type localMagna struct {
Expand All @@ -165,7 +165,7 @@ type localMagna struct {
// DialGNMI returns a gNMI client for the dut.
func (m *localMagna) DialGNMI(ctx context.Context, opts ...grpc.DialOption) (gpb.GNMIClient, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(m.addr, fmt.Sprint(gnmiPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(m.addr, fmt.Sprint(gnmiPort)), opts...)
if err != nil {
return nil, err
}
Expand All @@ -175,7 +175,7 @@ func (m *localMagna) DialGNMI(ctx context.Context, opts ...grpc.DialOption) (gpb
// DialOTG returns a OTH client for the dut.
func (m *localMagna) DialOTG(ctx context.Context, opts ...grpc.DialOption) (gosnappi.Api, error) {
opts = append(opts, grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.DialContext(ctx, net.JoinHostPort(m.addr, fmt.Sprint(otgPort)), opts...)
conn, err := grpc.NewClient(net.JoinHostPort(m.addr, fmt.Sprint(otgPort)), opts...)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions lemming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
func TestFakeGNMI(t *testing.T) {
f := startLemming(t)
defer f.Stop()
conn, err := grpc.Dial(f.GNMIAddr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.GNMIAddr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestStop(t *testing.T) {
func TestFakeGNOI(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.GNMIAddr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.GNMIAddr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestGNSI(t *testing.T) {
t.Run(desc, func(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand All @@ -219,7 +219,7 @@ func TestGNSI(t *testing.T) {
t.Run(desc, func(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand All @@ -238,7 +238,7 @@ func TestGNSI(t *testing.T) {
t.Run(desc, func(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand All @@ -257,7 +257,7 @@ func TestGNSI(t *testing.T) {
t.Run(desc, func(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand All @@ -276,7 +276,7 @@ func TestGNSI(t *testing.T) {
t.Run(desc, func(t *testing.T) {
f := startLemming(t)
defer f.stop()
conn, err := grpc.Dial(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(f.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("failed to Dial fake: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion sysrib/static_connected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestStaticRouteAndIntfs(t *testing.T) {
t.Fatalf("cannot create ygnmi client: %v", err)
}

conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(local.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(local.NewCredentials()))
if err != nil {
t.Fatalf("cannot dial gNMI server, %v", err)
}
Expand Down
Loading

0 comments on commit 2b3b9f5

Please sign in to comment.