Skip to content

Commit

Permalink
feat(frr): make it an interface and create mockery
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 Oct 16, 2023
1 parent 5d1f231 commit 9dafc65
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 42 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ fmt:
mock-generate:
@echo " > Starting mock code generation..."
# Generate mocks for exported interfaces
mockery --config=utils/mocks/.mockery.yaml --name=Frr --dir pkg/utils --output pkg/utils/mocks --boilerplate-file pkg/utils/mocks/boilerplate.txt --with-expecter
mockery --config=utils/mocks/.mockery.yaml --name=Netlink --dir pkg/utils --output pkg/utils/mocks --boilerplate-file pkg/utils/mocks/boilerplate.txt --with-expecter
2 changes: 2 additions & 0 deletions pkg/evpn/evpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Server struct {
Vrfs map[string]*pe.Vrf
Pagination map[string]int
nLink utils.Netlink
frr utils.Frr
tracer trace.Tracer
}

Expand All @@ -60,6 +61,7 @@ func NewServerWithArgs(nLink utils.Netlink) *Server {
Vrfs: make(map[string]*pe.Vrf),
Pagination: make(map[string]int),
nLink: nLink,
frr: utils.NewFrrWrapper(),
tracer: otel.Tracer(""),
}
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/evpn/svi_frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"fmt"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
"github.com/opiproject/opi-evpn-bridge/pkg/utils"
)

func (s *Server) frrCreateSviRequest(ctx context.Context, in *pb.CreateSviRequest, vrfName, vlanName string) error {
if in.Svi.Spec.EnableBgp {
fmt.Printf("TODO: add configuration for <%s:%s> here, see issue #233", vrfName, vlanName)
// data, err := utils.FrrBgpCmd(ctx, fmt.Sprintf(
// data, err := s.frr.FrrBgpCmd(ctx, fmt.Sprintf(
// `configure terminal
// router bgp 65000 vrf %s
// bgp disable-ebgp-connected-route-check" \
Expand All @@ -32,7 +31,7 @@ func (s *Server) frrCreateSviRequest(ctx context.Context, in *pb.CreateSviReques
// }
}
// check FRR for debug
data, err := utils.FrrZebraCmd(ctx, "show vrf")
data, err := s.frr.FrrZebraCmd(ctx, "show vrf")
fmt.Printf("FrrZebraCmd: %v:%v", data, err)
if err != nil {
return err
Expand All @@ -42,7 +41,7 @@ func (s *Server) frrCreateSviRequest(ctx context.Context, in *pb.CreateSviReques

func (s *Server) frrDeleteSviRequest(ctx context.Context, obj *pb.Svi, vrfName, vlanName string) error {
if obj.Spec.EnableBgp {
data, err := utils.FrrBgpCmd(ctx, fmt.Sprintf(
data, err := s.frr.FrrBgpCmd(ctx, fmt.Sprintf(
`configure terminal
router bgp 65000 vrf %s
no neighbor %s peer-group
Expand Down
11 changes: 5 additions & 6 deletions pkg/evpn/vrf_frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import (
"path"

pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
"github.com/opiproject/opi-evpn-bridge/pkg/utils"
)

func (s *Server) frrCreateVrfRequest(ctx context.Context, in *pb.CreateVrfRequest) error {
vrfName := path.Base(in.Vrf.Name)
if in.Vrf.Spec.Vni != nil {
data, err := utils.FrrZebraCmd(ctx, fmt.Sprintf(
data, err := s.frr.FrrZebraCmd(ctx, fmt.Sprintf(
`configure terminal
vrf %s
vni %d
Expand All @@ -28,7 +27,7 @@ func (s *Server) frrCreateVrfRequest(ctx context.Context, in *pb.CreateVrfReques
}
}
if in.Vrf.Spec.Vni != nil {
data, err := utils.FrrBgpCmd(ctx, fmt.Sprintf(
data, err := s.frr.FrrBgpCmd(ctx, fmt.Sprintf(
`configure terminal
router bgp 65000 vrf %s
no bgp log-neighbor-changes
Expand All @@ -53,7 +52,7 @@ func (s *Server) frrCreateVrfRequest(ctx context.Context, in *pb.CreateVrfReques
}
}
// check FRR for debug
data, err := utils.FrrZebraCmd(ctx, "show vrf")
data, err := s.frr.FrrZebraCmd(ctx, "show vrf")
fmt.Printf("FrrZebraCmd: %v:%v", data, err)
if err != nil {
return err
Expand All @@ -64,7 +63,7 @@ func (s *Server) frrCreateVrfRequest(ctx context.Context, in *pb.CreateVrfReques
func (s *Server) frrDeleteVrfRequest(ctx context.Context, obj *pb.Vrf) error {
vrfName := path.Base(obj.Name)
if obj.Spec.Vni != nil {
data, err := utils.FrrBgpCmd(ctx, fmt.Sprintf(
data, err := s.frr.FrrBgpCmd(ctx, fmt.Sprintf(
`configure terminal
no router bgp 65000 vrf %s
exit`, vrfName))
Expand All @@ -74,7 +73,7 @@ func (s *Server) frrDeleteVrfRequest(ctx context.Context, obj *pb.Vrf) error {
}
}
if obj.Spec.Vni != nil {
data, err := utils.FrrZebraCmd(ctx, fmt.Sprintf(
data, err := s.frr.FrrZebraCmd(ctx, fmt.Sprintf(
`configure terminal
no vrf %s
exit`, vrfName))
Expand Down
285 changes: 285 additions & 0 deletions pkg/utils/mocks/Frr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9dafc65

Please sign in to comment.