Skip to content

Commit

Permalink
fix(evpn): fix required and optional parameter check in evpn pkg
Browse files Browse the repository at this point in the history
Signed-off-by: atulpatel261194 <Atul.Patel@intel.com>
  • Loading branch information
atulpatel261194 authored and sandersms committed Apr 12, 2024
1 parent eda92b2 commit e4af793
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cmd/network/evpn-logical-brige.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func ListLogicalBridges() *cobra.Command {
func UpdateLogicalBridge() *cobra.Command {
var addr string
var name string
var allowMissing bool
var updateMask []string
cmd := &cobra.Command{
Use: "update-lb",
Expand All @@ -204,7 +205,7 @@ func UpdateLogicalBridge() *cobra.Command {
}
defer cancel()

lb, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask)
lb, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask, allowMissing)
if err != nil {
log.Fatalf("failed to update logical bridge: %v", err)
}
Expand All @@ -215,6 +216,7 @@ func UpdateLogicalBridge() *cobra.Command {
cmd.Flags().StringVar(&name, "name", "", "name of the logical bridge")
cmd.Flags().StringSliceVar(&updateMask, "update-mask", nil, "update mask")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")
cmd.Flags().BoolVarP(&allowMissing, "allowMissing", "a", false, "Specify allow missing")

return cmd
}
12 changes: 11 additions & 1 deletion network/bridge_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package network

import (
"context"
"errors"
"fmt"
"log"
"net"
Expand All @@ -25,7 +26,9 @@ func (c evpnClientImpl) CreateBridgePort(ctx context.Context, name string, mac s
return nil, err
}
defer closer()

if mac == "" || bridgePortType == "" {
return nil, errors.New("required parameter [mac, bridgePortType] wasn't passed ")
}
client := c.getEvpnBridgePortClient(conn)
macBytes, err := net.ParseMAC(mac)
if err != nil {
Expand Down Expand Up @@ -67,6 +70,9 @@ func (c evpnClientImpl) DeleteBridgePort(ctx context.Context, name string, allow
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}
client := c.getEvpnBridgePortClient(conn)
data, err := client.DeleteBridgePort(ctx, &pb.DeleteBridgePortRequest{
Name: resourceIDToFullName("ports", name),
Expand All @@ -89,6 +95,10 @@ func (c evpnClientImpl) GetBridgePort(ctx context.Context, name string) (*pb.Bri
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}

client := c.getEvpnBridgePortClient(conn)
data, err := client.GetBridgePort(ctx, &pb.GetBridgePortRequest{
Name: resourceIDToFullName("ports", name),
Expand Down
2 changes: 1 addition & 1 deletion network/evpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type EvpnClient interface {
DeleteLogicalBridge(ctx context.Context, name string, allowMissing bool) (*emptypb.Empty, error)
GetLogicalBridge(ctx context.Context, name string) (*pb.LogicalBridge, error)
ListLogicalBridges(ctx context.Context, pageSize int32, pageToken string) (*pb.ListLogicalBridgesResponse, error)
UpdateLogicalBridge(ctx context.Context, name string, updateMask []string) (*pb.LogicalBridge, error)
UpdateLogicalBridge(ctx context.Context, name string, updateMask []string, allowMissing bool) (*pb.LogicalBridge, error)

// Bridge Port Interfaces
CreateBridgePort(ctx context.Context, name string, mac string, bridgePortType string, logicalBridges []string) (*pb.BridgePort, error)
Expand Down
9 changes: 8 additions & 1 deletion network/logical_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (c evpnClientImpl) DeleteLogicalBridge(ctx context.Context, name string, al
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}
client := c.getEvpnLogicalBridgeClient(conn)

data, err := client.DeleteLogicalBridge(ctx, &pb.DeleteLogicalBridgeRequest{
Expand All @@ -90,6 +93,9 @@ func (c evpnClientImpl) GetLogicalBridge(ctx context.Context, name string) (*pb.
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}
client := c.getEvpnLogicalBridgeClient(conn)

data, err := client.GetLogicalBridge(ctx, &pb.GetLogicalBridgeRequest{
Expand Down Expand Up @@ -127,7 +133,7 @@ func (c evpnClientImpl) ListLogicalBridges(ctx context.Context, pageSize int32,
}

// UpdateLogicalBridge update Logical Bridge on OPI server
func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, updateMask []string) (*pb.LogicalBridge, error) {
func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, updateMask []string, allowMissing bool) (*pb.LogicalBridge, error) {
conn, closer, err := c.NewConn()
if err != nil {
log.Printf("error creating connection: %s\n", err)
Expand All @@ -142,6 +148,7 @@ func (c evpnClientImpl) UpdateLogicalBridge(ctx context.Context, name string, up
data, err := client.UpdateLogicalBridge(ctx, &pb.UpdateLogicalBridgeRequest{
LogicalBridge: Bridge,
UpdateMask: &fieldmaskpb.FieldMask{Paths: updateMask},
AllowMissing: allowMissing,
})
if err != nil {
log.Printf("error Update logical bridge: %s\n", err)
Expand Down
2 changes: 1 addition & 1 deletion network/logical_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestUpdateLogicalBridge(t *testing.T) {
},
)

response, err := c.UpdateLogicalBridge(context.Background(), name, updateMask)
response, err := c.UpdateLogicalBridge(context.Background(), name, updateMask, allowMissing)

assert.Equal(t, tt.wantErr, err)
assert.Equal(t, tt.wantConnClosed, connClosed)
Expand Down
15 changes: 15 additions & 0 deletions network/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package network

import (
"context"
"errors"
"fmt"
"log"
"net"
Expand All @@ -27,6 +28,10 @@ func (c evpnClientImpl) CreateSvi(ctx context.Context, name string, vrf string,

client := c.getEvpnSVIClient(conn)

if vrf == "" || mac == "" || len(gwIPs) == 0 {
return nil, errors.New("one of the required together parameter [vrf, mac, gwIPs] wasn't passed ")
}

gwPrefixes, err := parseIPPrefixes(gwIPs)
if err != nil {
log.Printf("error parsing GwIPs: %s\n", err)
Expand Down Expand Up @@ -66,6 +71,11 @@ func (c evpnClientImpl) DeleteSvi(ctx context.Context, name string, allowMissing
return nil, err
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}

client := c.getEvpnSVIClient(conn)
data, err := client.DeleteSvi(ctx, &pb.DeleteSviRequest{
Name: resourceIDToFullName("svis", name),
Expand All @@ -87,6 +97,11 @@ func (c evpnClientImpl) GetSvi(ctx context.Context, name string) (*pb.Svi, error
return nil, err
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}

client := c.getEvpnSVIClient(conn)
data, err := client.GetSvi(ctx, &pb.GetSviRequest{
Name: resourceIDToFullName("svis", name),
Expand Down
17 changes: 13 additions & 4 deletions network/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ func (c evpnClientImpl) CreateVrf(ctx context.Context, name string, vni *uint32,
defer closer()

client := c.getEvpnVRFClient(conn)
if loopbackIP == "" {
return nil, errors.New("required together parameter [loopbackIP] wasn't passed ")
}
ipLoopback, err := parseIPAndPrefix(loopbackIP)
if err != nil {
log.Printf("parseIPAndPrefix: error creating vrf: %s\n", err)
return nil, err
}
if (vni == nil && vtepIP != "") || (vni != nil && vtepIP == "") {
return nil, errors.New("one of the required together parameter [vni, vtep] wasn't passed ")
}

if vni != nil && vtepIP != "" {
ipVtep, err = parseIPAndPrefix(vtepIP)
if err != nil {
Expand Down Expand Up @@ -69,6 +68,11 @@ func (c evpnClientImpl) DeleteVrf(ctx context.Context, name string, allowMissing
return nil, err
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}

client := c.getEvpnVRFClient(conn)
data, err := client.DeleteVrf(ctx, &pb.DeleteVrfRequest{
Name: resourceIDToFullName("vrfs", name),
Expand All @@ -90,6 +94,11 @@ func (c evpnClientImpl) GetVrf(ctx context.Context, name string) (*pb.Vrf, error
return nil, err
}
defer closer()

if name == "" {
return nil, errors.New("required parameter [name] wasn't passed ")
}

client := c.getEvpnVRFClient(conn)
data, err := client.GetVrf(ctx, &pb.GetVrfRequest{
Name: resourceIDToFullName("vrfs", name),
Expand Down

0 comments on commit e4af793

Please sign in to comment.