Skip to content

Commit

Permalink
fix(evpn-bridge): fix return error on no subscribers
Browse files Browse the repository at this point in the history
Signed-off-by: Saikumar, Banoth <banoth.saikumar@intel.com>
  • Loading branch information
Inbanoth authored and sandersms committed Apr 25, 2024
1 parent 6b422c4 commit 54ded65
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
15 changes: 12 additions & 3 deletions pkg/bridge/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (s *Server) createLogicalBridge(lb *pb.LogicalBridge) (*pb.LogicalBridge, e
}

// translation of pb to domain object
domainLB := infradb.NewLogicalBridge(lb)
domainLB, err := infradb.NewLogicalBridge(lb)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateLB(domainLB); err != nil {
return nil, err
Expand Down Expand Up @@ -83,7 +86,10 @@ func (s *Server) updateLogicalBridge(lb *pb.LogicalBridge) (*pb.LogicalBridge, e
}

// translation of pb to domain object
domainLB := infradb.NewLogicalBridge(lb)
domainLB, err := infradb.NewLogicalBridge(lb)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.UpdateLB(domainLB); err != nil {
return nil, err
Expand Down Expand Up @@ -132,7 +138,10 @@ func (s *Server) TestCreateLogicalBridge(lb *pb.LogicalBridge) (*pb.LogicalBridg
}

// translation of pb to domain object
domainLB := infradb.NewLogicalBridge(lb)
domainLB, err := infradb.NewLogicalBridge(lb)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateLB(domainLB); err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions pkg/infradb/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package infradb
import (
// "encoding/binary"
"encoding/binary"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -63,7 +64,7 @@ type LogicalBridge struct {
var _ EvpnObject[*pb.LogicalBridge] = (*LogicalBridge)(nil)

// NewLogicalBridge creates new Logical Bridge object from protobuf message
func NewLogicalBridge(in *pb.LogicalBridge) *LogicalBridge {
func NewLogicalBridge(in *pb.LogicalBridge) (*LogicalBridge, error) {
var vip *net.IPNet
components := make([]common.Component, 0)

Expand All @@ -77,6 +78,7 @@ func NewLogicalBridge(in *pb.LogicalBridge) *LogicalBridge {
subscribers := eventbus.EBus.GetSubscribers("logical-bridge")
if len(subscribers) == 0 {
log.Println("NewLogicalBridge(): No subscribers for Logical Bridge objects")
return &LogicalBridge{}, errors.New("no subscribers found for logical bridge")
}

for _, sub := range subscribers {
Expand All @@ -99,7 +101,7 @@ func NewLogicalBridge(in *pb.LogicalBridge) *LogicalBridge {
BridgePorts: make(map[string]bool),
MacTable: make(map[string]string),
ResourceVersion: generateVersion(),
}
}, nil
}

// ToPb transforms Logical Bridge object to protobuf message
Expand Down
7 changes: 5 additions & 2 deletions pkg/infradb/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package infradb

import (
// "fmt"
"errors"

"log"
"net"

Expand Down Expand Up @@ -77,7 +79,7 @@ type BridgePort struct {
var _ EvpnObject[*pb.BridgePort] = (*BridgePort)(nil)

// NewBridgePort creates new Bridge Port object from protobuf message
func NewBridgePort(in *pb.BridgePort) *BridgePort {
func NewBridgePort(in *pb.BridgePort) (*BridgePort, error) {
var bpType BridgePortType
var transTrunk bool
components := make([]common.Component, 0)
Expand All @@ -88,6 +90,7 @@ func NewBridgePort(in *pb.BridgePort) *BridgePort {
subscribers := eventbus.EBus.GetSubscribers("bridge-port")
if len(subscribers) == 0 {
log.Println("NewBridgePort(): No subscribers for Bridge Port objects")
return &BridgePort{}, errors.New("no subscribers found for bridge port")
}

for _, sub := range subscribers {
Expand Down Expand Up @@ -122,7 +125,7 @@ func NewBridgePort(in *pb.BridgePort) *BridgePort {
Metadata: &BridgePortMetadata{},
TransparentTrunk: transTrunk,
ResourceVersion: generateVersion(),
}
}, nil
}

// ToPb transforms Bridge Port object to protobuf message
Expand Down
7 changes: 5 additions & 2 deletions pkg/infradb/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package infradb
import (
"encoding/binary"
// "fmt"
"errors"

"log"
"net"

Expand Down Expand Up @@ -65,7 +67,7 @@ type Svi struct {
var _ EvpnObject[*pb.Svi] = (*Svi)(nil)

// NewSvi creates new SVI object from protobuf message
func NewSvi(in *pb.Svi) *Svi {
func NewSvi(in *pb.Svi) (*Svi, error) {
components := make([]common.Component, 0)
gwIPs := make([]*net.IPNet, 0)

Expand All @@ -83,6 +85,7 @@ func NewSvi(in *pb.Svi) *Svi {
subscribers := eventbus.EBus.GetSubscribers("svi")
if len(subscribers) == 0 {
log.Println("NewSvi(): No subscribers for SVI objects")
return &Svi{}, errors.New("no subscribers found for svi")
}

for _, sub := range subscribers {
Expand All @@ -106,7 +109,7 @@ func NewSvi(in *pb.Svi) *Svi {
},
Metadata: &SviMetadata{},
ResourceVersion: generateVersion(),
}
}, nil
}

// ToPb transforms Svi object to protobuf message
Expand Down
6 changes: 4 additions & 2 deletions pkg/infradb/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package infradb

import (
"encoding/binary"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -119,7 +120,7 @@ func NewVrfWithArgs(name string, vni *uint32, loopbackIP, vtepIP *net.IPNet) (*V
}

// NewVrf creates new VRF object from protobuf message
func NewVrf(in *pb.Vrf) *Vrf {
func NewVrf(in *pb.Vrf) (*Vrf, error) {
var vip *net.IPNet
components := make([]common.Component, 0)

Expand All @@ -137,6 +138,7 @@ func NewVrf(in *pb.Vrf) *Vrf {
subscribers := eventbus.EBus.GetSubscribers("vrf")
if len(subscribers) == 0 {
log.Println("NewVrf(): No subscribers for Vrf objects")
return &Vrf{}, errors.New("no subscribers found for vrf")
}

for _, sub := range subscribers {
Expand All @@ -159,7 +161,7 @@ func NewVrf(in *pb.Vrf) *Vrf {
Metadata: &VrfMetadata{},
Svis: make(map[string]bool),
ResourceVersion: generateVersion(),
}
}, nil
}

// ToPb transforms VRF object to protobuf message
Expand Down
10 changes: 8 additions & 2 deletions pkg/port/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func (s *Server) createBridgePort(bp *pb.BridgePort) (*pb.BridgePort, error) {
}

// translation of pb to domain object
domainBP := infradb.NewBridgePort(bp)
domainBP, err := infradb.NewBridgePort(bp)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateBP(domainBP); err != nil {
return nil, err
Expand Down Expand Up @@ -86,7 +89,10 @@ func (s *Server) updateBridgePort(bp *pb.BridgePort) (*pb.BridgePort, error) {
}

// translation of pb to domain object
domainBP := infradb.NewBridgePort(bp)
domainBP, err := infradb.NewBridgePort(bp)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.UpdateBP(domainBP); err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions pkg/svi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func (s *Server) createSvi(svi *pb.Svi) (*pb.Svi, error) {
}

// translation of pb to domain object
domainSvi := infradb.NewSvi(svi)
domainSvi, err := infradb.NewSvi(svi)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateSvi(domainSvi); err != nil {
return nil, err
Expand Down Expand Up @@ -87,7 +90,10 @@ func (s *Server) updateSvi(svi *pb.Svi) (*pb.Svi, error) {
}

// translation of pb to domain object
domainSvi := infradb.NewSvi(svi)
domainSvi, err := infradb.NewSvi(svi)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.UpdateSvi(domainSvi); err != nil {
return nil, err
Expand Down
15 changes: 12 additions & 3 deletions pkg/vrf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func (s *Server) createVrf(vrf *pb.Vrf) (*pb.Vrf, error) {
}

// translation of pb to domain object
domainVrf := infradb.NewVrf(vrf)
domainVrf, err := infradb.NewVrf(vrf)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateVrf(domainVrf); err != nil {
return nil, err
Expand Down Expand Up @@ -81,7 +84,10 @@ func (s *Server) updateVrf(vrf *pb.Vrf) (*pb.Vrf, error) {
}

// translation of pb to domain object
domainVrf := infradb.NewVrf(vrf)
domainVrf, err := infradb.NewVrf(vrf)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.UpdateVrf(domainVrf); err != nil {
return nil, err
Expand Down Expand Up @@ -128,7 +134,10 @@ func (s *Server) TestCreateVrf(vrf *pb.Vrf) (*pb.Vrf, error) {
}

// translation of pb to domain object
domainVrf := infradb.NewVrf(vrf)
domainVrf, err := infradb.NewVrf(vrf)
if err != nil {
return nil, err
}
// Note: The status of the object will be generated in infraDB operation not here
if err := infradb.CreateVrf(domainVrf); err != nil {
return nil, err
Expand Down

0 comments on commit 54ded65

Please sign in to comment.