Skip to content

Commit

Permalink
fix(port): raise new error
Browse files Browse the repository at this point in the history
Fixes #95

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 8, 2023
1 parent d801aa4 commit 768abd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/evpn/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (s *Server) CreateBridgePort(_ context.Context, in *pb.CreateBridgePortRequ
log.Printf("Already existing BridgePort with id %v", in.BridgePort.Name)
return obj, nil
}
// for Access type, the LogicalBridge list must have only one item
length := len(in.BridgePort.Spec.LogicalBridges)
if in.BridgePort.Spec.Ptype == pb.BridgePortType_ACCESS && length > 1 {
msg := fmt.Sprintf("ACCESS type must have single LogicalBridge and not (%d)", length)
log.Print(msg)
return nil, status.Errorf(codes.InvalidArgument, msg)
}
// not found, so create a new one
bridgeName := "br-tenant"
// get tenant bridge device by name
Expand Down
16 changes: 15 additions & 1 deletion pkg/evpn/port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
testBridgePort = pb.BridgePort{
Spec: &pb.BridgePortSpec{
MacAddress: []byte{0xCB, 0xB8, 0x33, 0x4C, 0x88, 0x4F},
Ptype: pb.BridgePortType_ACCESS,
Ptype: pb.BridgePortType_TRUNK,
LogicalBridges: []string{"Japan", "Australia", "Germany"},
},
}
Expand Down Expand Up @@ -60,6 +60,20 @@ func Test_CreateBridgePort(t *testing.T) {
"",
true,
},
"access port and list bridge": {
testBridgePortID,
&pb.BridgePort{
Spec: &pb.BridgePortSpec{
MacAddress: []byte{0xCB, 0xB8, 0x33, 0x4C, 0x88, 0x4F},
Ptype: pb.BridgePortType_ACCESS,
LogicalBridges: []string{"Japan", "Australia", "Germany"},
},
},
nil,
codes.InvalidArgument,
fmt.Sprintf("ACCESS type must have single LogicalBridge and not (%d)", len(testBridgePort.Spec.LogicalBridges)),
false,
},
}

// run tests
Expand Down

0 comments on commit 768abd3

Please sign in to comment.