Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lifecycleservice unit test #144

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions ipu-plugin/pkg/ipuplugin/lifecycleservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ type SSHHandler interface {

type SSHHandlerImpl struct{}

type FXPHandler interface {
configureFXP(p4rtbin string) error
}

type FXPHandlerImpl struct{}

var fileSystemHandler FileSystemHandler
var networkHandler NetworkHandler
var executableHandler ExecutableHandler
var sshHandler SSHHandler
var fxpHandler FXPHandler

func initHandlers() {
if fileSystemHandler == nil {
Expand All @@ -124,6 +131,9 @@ func initHandlers() {
if sshHandler == nil {
sshHandler = &SSHHandlerImpl{}
}
if fxpHandler == nil {
fxpHandler = &FXPHandlerImpl{}
}
}

func isPF(iface string) (bool, error) {
Expand Down Expand Up @@ -478,6 +488,23 @@ func (e *ExecutableHandlerImpl) validate() bool {
return true
}

func (s *FXPHandlerImpl) configureFXP(p4rtbin string) error {
vfMacList, err := utils.GetVfMacList()

if err != nil {
return fmt.Errorf("unable to reach the IMC %v", err)
}

if len(vfMacList) == 0 {
return fmt.Errorf("no NFs initialized on the host")
}

p4rtclient.DeletePointToPointVFRules(p4rtbin, vfMacList)
p4rtclient.CreatePointToPointVFRules(p4rtbin, vfMacList)

return nil
}

func (s *LifeCycleServiceServer) Init(ctx context.Context, in *pb.InitRequest) (*pb.IpPort, error) {
initHandlers()

Expand All @@ -495,19 +522,10 @@ func (s *LifeCycleServiceServer) Init(ctx context.Context, in *pb.InitRequest) (
log.Info("not forcing state")
}

vfMacList, err := utils.GetVfMacList()

if err != nil {
return nil, status.Errorf(codes.Internal, "Unable to reach the IMC %v", err)
}

if len(vfMacList) == 0 {
return nil, status.Error(codes.Internal, "No NFs initialized on the host")
}

// Preconfigure the FXP with point-to-point rules between host VFs
p4rtclient.DeletePointToPointVFRules(s.p4rtbin, vfMacList)
p4rtclient.CreatePointToPointVFRules(s.p4rtbin, vfMacList)
if err := fxpHandler.configureFXP(s.p4rtbin); err != nil {
return nil, status.Errorf(codes.Internal, "Error when preconfiguring the FXP: %v", err)
}
}

if err := configureChannel(s.mode, s.daemonHostIp, s.daemonIpuIp); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions ipu-plugin/pkg/ipuplugin/lifecycleservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var _ = Describe("basic functionality", Serial, func() {
fileSystemHandler = &MockFileSystemHandlerImpl{}
networkHandler = &MockNetworkHandlerImpl{}
executableHandler = &MockExecutableHandlerImpl{}
fxpHandler = &MockFXPHandlerImpl{}

Describe("pf communication channel setup", Serial, func() {

Expand Down Expand Up @@ -256,3 +257,9 @@ type MockExecutableHandlerImpl struct{}
func (m *MockExecutableHandlerImpl) validate() bool {
return true
}

type MockFXPHandlerImpl struct{}

func (m *MockFXPHandlerImpl) configureFXP(p4rtbin string) error {
return nil
}
Loading