From a5530994dfd98871b00127a0abdf309f4501f826 Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Tue, 26 Mar 2024 10:49:23 +0300 Subject: [PATCH] Create instance of IB interface in the host object Signed-off-by: amaslennikov --- pkg/helper/host.go | 6 +++++- pkg/helper/mock/mock_helper.go | 14 ++++++++++++++ pkg/host/internal/sriov/sriov_test.go | 15 +++++++-------- pkg/host/manager.go | 14 +++++++++++--- pkg/host/mock/mock_host.go | 14 ++++++++++++++ pkg/platforms/platforms.go | 8 +++++++- pkg/plugins/k8s/k8s_plugin_test.go | 2 +- 7 files changed, 59 insertions(+), 14 deletions(-) diff --git a/pkg/helper/host.go b/pkg/helper/host.go index 5829d161a8..2e93a30d3d 100644 --- a/pkg/helper/host.go +++ b/pkg/helper/host.go @@ -35,7 +35,11 @@ func NewHostHelpers(utilsHelper utils.CmdInterface, func NewDefaultHostHelpers() (HostHelpersInterface, error) { utilsHelper := utils.New() mlxHelper := mlx.New(utilsHelper) - hostManager := host.NewHostManager(utilsHelper) + hostManager, err := host.NewHostManager(utilsHelper) + if err != nil { + log.Log.Error(err, "failed to create host manager") + return nil, err + } storeManager, err := store.NewManager() if err != nil { log.Log.Error(err, "failed to create store manager") diff --git a/pkg/helper/mock/mock_helper.go b/pkg/helper/mock/mock_helper.go index 03cd37efde..1d4c5678f2 100644 --- a/pkg/helper/mock/mock_helper.go +++ b/pkg/helper/mock/mock_helper.go @@ -195,6 +195,20 @@ func (mr *MockHostHelpersInterfaceMockRecorder) ConfigSriovInterfaces(storeManag return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostHelpersInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, skipVFConfiguration) } +// ConfigureVfGUID mocks base method. +func (m *MockHostHelpersInterface) ConfigureVfGUID(vfAddr, pfAddr string, vfID int, pfLink netlink.Link) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConfigureVfGUID", vfAddr, pfAddr, vfID, pfLink) + ret0, _ := ret[0].(error) + return ret0 +} + +// ConfigureVfGUID indicates an expected call of ConfigureVfGUID. +func (mr *MockHostHelpersInterfaceMockRecorder) ConfigureVfGUID(vfAddr, pfAddr, vfID, pfLink interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureVfGUID", reflect.TypeOf((*MockHostHelpersInterface)(nil).ConfigureVfGUID), vfAddr, pfAddr, vfID, pfLink) +} + // CreateVDPADevice mocks base method. func (m *MockHostHelpersInterface) CreateVDPADevice(pciAddr, vdpaType string) error { m.ctrl.T.Helper() diff --git a/pkg/host/internal/sriov/sriov_test.go b/pkg/host/internal/sriov/sriov_test.go index 67e069b6fb..dd8179e9dd 100644 --- a/pkg/host/internal/sriov/sriov_test.go +++ b/pkg/host/internal/sriov/sriov_test.go @@ -13,6 +13,7 @@ import ( . "github.com/onsi/gomega" sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" + infinibandMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/infiniband/mock" dputilsMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils/mock" netlinkMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink/mock" hostMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/mock" @@ -29,8 +30,8 @@ var _ = Describe("SRIOV", func() { dputilsLibMock *dputilsMockPkg.MockDPUtilsLib hostMock *hostMockPkg.MockHostManagerInterface storeManagerMode *hostStoreMockPkg.MockManagerInterface - - testCtrl *gomock.Controller + infinibandMock *infinibandMockPkg.MockInfinibandInterface + testCtrl *gomock.Controller testError = fmt.Errorf("test") ) @@ -40,8 +41,9 @@ var _ = Describe("SRIOV", func() { dputilsLibMock = dputilsMockPkg.NewMockDPUtilsLib(testCtrl) hostMock = hostMockPkg.NewMockHostManagerInterface(testCtrl) storeManagerMode = hostStoreMockPkg.NewMockManagerInterface(testCtrl) + infinibandMock = infinibandMockPkg.NewMockInfinibandInterface(testCtrl) - s = New(nil, hostMock, hostMock, hostMock, hostMock, nil, netlinkLibMock, dputilsLibMock) + s = New(nil, hostMock, hostMock, hostMock, hostMock, infinibandMock, netlinkLibMock, dputilsLibMock) }) AfterEach(func() { @@ -191,16 +193,13 @@ var _ = Describe("SRIOV", func() { pfLinkMock.EXPECT().Attrs().Return(&netlink.LinkAttrs{OperState: netlink.OperDown}) netlinkLibMock.EXPECT().LinkSetUp(pfLinkMock).Return(nil) - dputilsLibMock.EXPECT().GetVFID("0000:d8:00.2").Return(0, nil).Times(2) - hostMock.EXPECT().Unbind("0000:d8:00.2").Return(nil) + dputilsLibMock.EXPECT().GetVFID("0000:d8:00.2").Return(0, nil).Times(1) hostMock.EXPECT().HasDriver("0000:d8:00.2").Return(true, "test").Times(2) hostMock.EXPECT().UnbindDriverIfNeeded("0000:d8:00.2", true).Return(nil) hostMock.EXPECT().BindDefaultDriver("0000:d8:00.2").Return(nil) hostMock.EXPECT().SetNetdevMTU("0000:d8:00.2", 2000).Return(nil) - vf0LinkMock := netlinkMockPkg.NewMockLink(testCtrl) - netlinkLibMock.EXPECT().LinkSetVfNodeGUID(vf0LinkMock, 0, gomock.Any()).Return(nil) - netlinkLibMock.EXPECT().LinkSetVfPortGUID(vf0LinkMock, 0, gomock.Any()).Return(nil) netlinkLibMock.EXPECT().LinkList().Return(nil, nil).AnyTimes() + infinibandMock.EXPECT().ConfigureVfGUID(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() storeManagerMode.EXPECT().SaveLastPfAppliedStatus(gomock.Any()).Return(nil) diff --git a/pkg/host/manager.go b/pkg/host/manager.go index a79331b533..661434548d 100644 --- a/pkg/host/manager.go +++ b/pkg/host/manager.go @@ -1,6 +1,7 @@ package host import ( + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/infiniband" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/kernel" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/ethtool" @@ -24,6 +25,7 @@ type HostManagerInterface interface { types.UdevInterface types.SriovInterface types.VdpaInterface + types.InfinibandInterface } type hostManager struct { @@ -34,9 +36,10 @@ type hostManager struct { types.UdevInterface types.SriovInterface types.VdpaInterface + types.InfinibandInterface } -func NewHostManager(utilsInterface utils.CmdInterface) HostManagerInterface { +func NewHostManager(utilsInterface utils.CmdInterface) (HostManagerInterface, error) { dpUtils := dputils.New() netlinkLib := netlink.New() ethtoolLib := ethtool.New() @@ -45,7 +48,11 @@ func NewHostManager(utilsInterface utils.CmdInterface) HostManagerInterface { sv := service.New(utilsInterface) u := udev.New(utilsInterface) v := vdpa.New(k, netlinkLib) - sr := sriov.New(utilsInterface, k, n, u, v, netlinkLib, dpUtils) + ib, err := infiniband.New(netlinkLib, k, n) + sr := sriov.New(utilsInterface, k, n, u, v, ib, netlinkLib, dpUtils) + if err != nil { + return nil, err + } return &hostManager{ utilsInterface, @@ -55,5 +62,6 @@ func NewHostManager(utilsInterface utils.CmdInterface) HostManagerInterface { u, sr, v, - } + ib, + }, nil } diff --git a/pkg/host/mock/mock_host.go b/pkg/host/mock/mock_host.go index 3613dedb11..f0d8f3d863 100644 --- a/pkg/host/mock/mock_host.go +++ b/pkg/host/mock/mock_host.go @@ -165,6 +165,20 @@ func (mr *MockHostManagerInterfaceMockRecorder) ConfigSriovInterfaces(storeManag return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigSriovInterfaces", reflect.TypeOf((*MockHostManagerInterface)(nil).ConfigSriovInterfaces), storeManager, interfaces, ifaceStatuses, skipVFConfiguration) } +// ConfigureVfGUID mocks base method. +func (m *MockHostManagerInterface) ConfigureVfGUID(vfAddr, pfAddr string, vfID int, pfLink netlink.Link) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConfigureVfGUID", vfAddr, pfAddr, vfID, pfLink) + ret0, _ := ret[0].(error) + return ret0 +} + +// ConfigureVfGUID indicates an expected call of ConfigureVfGUID. +func (mr *MockHostManagerInterfaceMockRecorder) ConfigureVfGUID(vfAddr, pfAddr, vfID, pfLink interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureVfGUID", reflect.TypeOf((*MockHostManagerInterface)(nil).ConfigureVfGUID), vfAddr, pfAddr, vfID, pfLink) +} + // CreateVDPADevice mocks base method. func (m *MockHostManagerInterface) CreateVDPADevice(pciAddr, vdpaType string) error { m.ctrl.T.Helper() diff --git a/pkg/platforms/platforms.go b/pkg/platforms/platforms.go index 19c74cef30..3320dbaaca 100644 --- a/pkg/platforms/platforms.go +++ b/pkg/platforms/platforms.go @@ -1,6 +1,8 @@ package platforms import ( + "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/openshift" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/openstack" @@ -24,7 +26,11 @@ func NewDefaultPlatformHelper() (Interface, error) { return nil, err } utilsHelper := utils.New() - hostManager := host.NewHostManager(utilsHelper) + hostManager, err := host.NewHostManager(utilsHelper) + if err != nil { + log.Log.Error(err, "failed to create host manager") + return nil, err + } openstackContext := openstack.New(hostManager) return &platformHelper{ diff --git a/pkg/plugins/k8s/k8s_plugin_test.go b/pkg/plugins/k8s/k8s_plugin_test.go index 28a2e85c1f..b4344b95fc 100644 --- a/pkg/plugins/k8s/k8s_plugin_test.go +++ b/pkg/plugins/k8s/k8s_plugin_test.go @@ -79,7 +79,7 @@ var _ = Describe("K8s plugin", func() { testCtrl = gomock.NewController(GinkgoT()) hostHelper = mock_helper.NewMockHostHelpersInterface(testCtrl) - realHostMgr := host.NewHostManager(hostHelper) + realHostMgr, _ := host.NewHostManager(hostHelper) // proxy some functions to real host manager to simplify testing and to additionally validate manifests for _, f := range []string{