Skip to content

Commit

Permalink
test: add more mockup test for vrf and bridge
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 28, 2023
1 parent 6a99325 commit bfea91c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (s *Server) CreateLogicalBridge(_ context.Context, in *pb.CreateLogicalBrid
}
// Example: ip link add vxlan-<LB-vlan-id> type vxlan id <LB-vni> local <vtep-ip> dstport 4789 nolearning proxy
myip := make(net.IP, 4)
// TODO: remove hard-coded 167772260 == "10.0.0.100"
binary.BigEndian.PutUint32(myip, 167772260)
// TODO: remove hard-coded 167772162 == "10.0.0.2"
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: resourceID}, VxlanId: int(*in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
log.Printf("Creating Vxlan %v", vxlan)
// TODO: take Port from proto instead of hard-coded
Expand Down
21 changes: 21 additions & 0 deletions pkg/evpn/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ package evpn

import (
"context"
"encoding/binary"
"errors"
"fmt"
"log"
"net"
"reflect"
"strings"
"testing"

"github.com/vishvananda/netlink"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -121,6 +125,14 @@ func Test_CreateLogicalBridge(t *testing.T) {
"unable to find key br-tenant",
false,
},
"failed LinkAdd call": {
testLogicalBridgeID,
&testLogicalBridge,
nil,
codes.Unknown,
"Failed to call LinkAdd",
false,
},
}

// run tests
Expand Down Expand Up @@ -157,6 +169,15 @@ func Test_CreateLogicalBridge(t *testing.T) {
if strings.Contains(name, "LinkByName") {
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(nil, errors.New(tt.errMsg)).Once()
}
if strings.Contains(name, "LinkAdd") {
// myip := net.ParseIP("10.0.0.2")
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(errors.New(tt.errMsg)).Once()
}

request := &pb.CreateLogicalBridgeRequest{LogicalBridge: tt.in, LogicalBridgeId: tt.id}
response, err := client.CreateLogicalBridge(ctx, request)
Expand Down
13 changes: 13 additions & 0 deletions pkg/evpn/vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func Test_CreateVrf(t *testing.T) {
"Failed to call LinkAdd",
false,
},
"failed LinkSetUp call": {
testVrfID,
&testVrf,
nil,
codes.Unknown,
"Failed to call LinkSetUp",
false,
},
}

// run tests
Expand Down Expand Up @@ -162,6 +170,11 @@ func Test_CreateVrf(t *testing.T) {
vrf := &netlink.Vrf{LinkAttrs: netlink.LinkAttrs{Name: testVrfID}, Table: 1001}
mockNetlink.EXPECT().LinkAdd(vrf).Return(errors.New(tt.errMsg)).Once()
}
if strings.Contains(tt.errMsg, "LinkSetUp") {
vrf := &netlink.Vrf{LinkAttrs: netlink.LinkAttrs{Name: testVrfID}, Table: 1001}
mockNetlink.EXPECT().LinkAdd(vrf).Return(nil).Once()
mockNetlink.EXPECT().LinkSetUp(vrf).Return(errors.New(tt.errMsg)).Once()
}
if tt.out != nil && !tt.exist {
vrf := &netlink.Vrf{LinkAttrs: netlink.LinkAttrs{Name: testVrfID}, Table: 1000}
mockNetlink.EXPECT().LinkAdd(vrf).Return(nil).Once()
Expand Down

0 comments on commit bfea91c

Please sign in to comment.