Skip to content

Commit

Permalink
Merge pull request openshift#598 from ykulazhenkov/pr-dputis-wrapper
Browse files Browse the repository at this point in the history
Add wrapper for utils package from sriov-device-plugin
  • Loading branch information
zeeke authored Feb 1, 2024
2 parents 36394ac + a7a885a commit 9648745
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 38 deletions.
78 changes: 78 additions & 0 deletions pkg/host/internal/lib/dputils/dputils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package dputils

import (
dputils "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
)

func New() DPUtilsLib {
return &libWrapper{}
}

//go:generate ../../../../../bin/mockgen -destination mock/mock_dputils.go -source dputils.go
type DPUtilsLib interface {
// GetNetNames returns host net interface names as string for a PCI device from its pci address
GetNetNames(pciAddr string) ([]string, error)
// GetDriverName returns current driver attached to a pci device from its pci address
GetDriverName(pciAddr string) (string, error)
// GetVFID returns VF ID index (within specific PF) based on PCI address
GetVFID(pciAddr string) (vfID int, err error)
// IsSriovVF check if a pci device has link to a PF
IsSriovVF(pciAddr string) bool
// IsSriovPF check if a pci device SRIOV capable given its pci address
IsSriovPF(pciAddr string) bool
// GetSriovVFcapacity returns SRIOV VF capacity
GetSriovVFcapacity(pf string) int
// GetVFconfigured returns number of VF configured for a PF
GetVFconfigured(pf string) int
// SriovConfigured returns true if sriov_numvfs reads > 0 else false
SriovConfigured(addr string) bool
// GetVFList returns a List containing PCI addr for all VF discovered in a given PF
GetVFList(pf string) (vfList []string, err error)
}

type libWrapper struct{}

// GetNetNames returns host net interface names as string for a PCI device from its pci address
func (w *libWrapper) GetNetNames(pciAddr string) ([]string, error) {
return dputils.GetNetNames(pciAddr)
}

// GetDriverName returns current driver attached to a pci device from its pci address
func (w *libWrapper) GetDriverName(pciAddr string) (string, error) {
return dputils.GetDriverName(pciAddr)
}

// GetVFID returns VF ID index (within specific PF) based on PCI address
func (w *libWrapper) GetVFID(pciAddr string) (vfID int, err error) {
return dputils.GetVFID(pciAddr)
}

// IsSriovVF check if a pci device has link to a PF
func (w *libWrapper) IsSriovVF(pciAddr string) bool {
return dputils.IsSriovVF(pciAddr)
}

// IsSriovPF check if a pci device SRIOV capable given its pci address
func (w *libWrapper) IsSriovPF(pciAddr string) bool {
return dputils.IsSriovPF(pciAddr)
}

// GetSriovVFcapacity returns SRIOV VF capacity
func (w *libWrapper) GetSriovVFcapacity(pf string) int {
return dputils.GetSriovVFcapacity(pf)
}

// GetVFconfigured returns number of VF configured for a PF
func (w *libWrapper) GetVFconfigured(pf string) int {
return dputils.GetVFconfigured(pf)
}

// SriovConfigured returns true if sriov_numvfs reads > 0 else false
func (w *libWrapper) SriovConfigured(addr string) bool {
return dputils.SriovConfigured(addr)
}

// GetVFList returns a List containing PCI addr for all VF discovered in a given PF
func (w *libWrapper) GetVFList(pf string) (vfList []string, err error) {
return dputils.GetVFList(pf)
}
164 changes: 164 additions & 0 deletions pkg/host/internal/lib/dputils/mock/mock_dputils.go

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

15 changes: 9 additions & 6 deletions pkg/host/internal/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import (
"github.com/cenkalti/backoff"
"sigs.k8s.io/controller-runtime/pkg/log"

dputils "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"

"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
dputilsPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
)

type network struct {
utilsHelper utils.CmdInterface
dputilsLib dputilsPkg.DPUtilsLib
}

func New(utilsHelper utils.CmdInterface) types.NetworkInterface {
return &network{utilsHelper: utilsHelper}
func New(utilsHelper utils.CmdInterface, dputilsLib dputilsPkg.DPUtilsLib) types.NetworkInterface {
return &network{
utilsHelper: utilsHelper,
dputilsLib: dputilsLib,
}
}

// TryToGetVirtualInterfaceName get the interface name of a virtio interface
Expand Down Expand Up @@ -61,7 +64,7 @@ func (n *network) TryToGetVirtualInterfaceName(pciAddr string) string {
}

func (n *network) TryGetInterfaceName(pciAddr string) string {
names, err := dputils.GetNetNames(pciAddr)
names, err := n.dputilsLib.GetNetNames(pciAddr)
if err != nil || len(names) < 1 {
return ""
}
Expand Down Expand Up @@ -152,7 +155,7 @@ func (n *network) SetNetdevMTU(pciAddr string, mtu int) error {
}
b := backoff.NewConstantBackOff(1 * time.Second)
err := backoff.Retry(func() error {
ifaceName, err := dputils.GetNetNames(pciAddr)
ifaceName, err := n.dputilsLib.GetNetNames(pciAddr)
if err != nil {
log.Log.Error(err, "SetNetdevMTU(): fail to get interface name", "device", pciAddr)
return err
Expand Down
Loading

0 comments on commit 9648745

Please sign in to comment.