diff --git a/pkg/evpn/bridge_test.go b/pkg/evpn/bridge_test.go index ab00224a..3942bb58 100644 --- a/pkg/evpn/bridge_test.go +++ b/pkg/evpn/bridge_test.go @@ -133,6 +133,30 @@ func Test_CreateLogicalBridge(t *testing.T) { "Failed to call LinkAdd", false, }, + "failed LinkSetMaster call": { + testLogicalBridgeID, + &testLogicalBridge, + nil, + codes.Unknown, + "Failed to call LinkSetMaster", + false, + }, + "failed LinkSetUp call": { + testLogicalBridgeID, + &testLogicalBridge, + nil, + codes.Unknown, + "Failed to call LinkSetUp", + false, + }, + "failed BridgeVlanAdd call": { + testLogicalBridgeID, + &testLogicalBridge, + nil, + codes.Unknown, + "Failed to call BridgeVlanAdd", + false, + }, } // run tests @@ -166,10 +190,9 @@ func Test_CreateLogicalBridge(t *testing.T) { } // TODO: refactor this mocking - if strings.Contains(name, "LinkByName") { + if strings.Contains(name, "failed LinkByName") { mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(nil, errors.New(tt.errMsg)).Once() - } - if strings.Contains(name, "LinkAdd") { + } else if strings.Contains(name, "failed LinkAdd") { // myip := net.ParseIP("10.0.0.2") myip := make(net.IP, 4) binary.BigEndian.PutUint32(myip, 167772162) @@ -177,6 +200,33 @@ func Test_CreateLogicalBridge(t *testing.T) { 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() + } else if strings.Contains(name, "failed LinkSetMaster") { + 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(nil).Once() + mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(errors.New(tt.errMsg)).Once() + } else if strings.Contains(name, "failed LinkSetUp") { + 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(nil).Once() + mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(nil).Once() + mockNetlink.EXPECT().LinkSetUp(vxlan).Return(errors.New(tt.errMsg)).Once() + } else if strings.Contains(name, "failed BridgeVlanAdd") { + 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(nil).Once() + mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(nil).Once() + mockNetlink.EXPECT().LinkSetUp(vxlan).Return(nil).Once() + mockNetlink.EXPECT().BridgeVlanAdd(vxlan, uint16(testLogicalBridge.Spec.VlanId), true, true, false, false).Return(errors.New(tt.errMsg)).Once() } request := &pb.CreateLogicalBridgeRequest{LogicalBridge: tt.in, LogicalBridgeId: tt.id}