Skip to content

Commit

Permalink
Add test for sriov.DiscoverSriovDevices function
Browse files Browse the repository at this point in the history
Signed-off-by: Yury Kulazhenkov <ykulazhenkov@nvidia.com>
  • Loading branch information
ykulazhenkov committed May 3, 2024
1 parent 7ac48ee commit 46bfbc2
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/jaypipes/ghw v0.9.0
github.com/jaypipes/pcidb v1.0.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/sriov-network-device-plugin v0.0.0-20221127172732-a5a7395122e3
github.com/k8snetworkplumbingwg/sriovnet v1.2.0
Expand Down Expand Up @@ -90,7 +91,6 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/govdpa v0.1.4 // indirect
Expand Down
29 changes: 29 additions & 0 deletions pkg/host/internal/lib/ghw/ghw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ghw

import (
"github.com/jaypipes/ghw"
)

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

//go:generate ../../../../../bin/mockgen -destination mock/mock_ghw.go -source ghw.go
type GHWLib interface {
// PCI returns a pointer to an Info that provide methods to access info about devices
PCI() (Info, error)
}

// Info interface provide methods to access info about devices
type Info interface {
// ListDevices returns a list of pointers to Device structs present on the
// host system
ListDevices() []*ghw.PCIDevice
}

type libWrapper struct{}

// PCI returns a pointer to an Info that provide methods to access info about devices
func (w *libWrapper) PCI() (Info, error) {
return ghw.PCI()
}
88 changes: 88 additions & 0 deletions pkg/host/internal/lib/ghw/mock/mock_ghw.go

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

8 changes: 6 additions & 2 deletions pkg/host/internal/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
dputilsPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils"
ghwPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/ghw"
netlinkPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink"
sriovnetPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/sriovnet"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/store"
Expand All @@ -40,6 +41,7 @@ type sriov struct {
netlinkLib netlinkPkg.NetlinkLib
dputilsLib dputilsPkg.DPUtilsLib
sriovnetLib sriovnetPkg.SriovnetLib
ghwLib ghwPkg.GHWLib
}

func New(utilsHelper utils.CmdInterface,
Expand All @@ -49,7 +51,8 @@ func New(utilsHelper utils.CmdInterface,
vdpaHelper types.VdpaInterface,
netlinkLib netlinkPkg.NetlinkLib,
dputilsLib dputilsPkg.DPUtilsLib,
sriovnetLib sriovnetPkg.SriovnetLib) types.SriovInterface {
sriovnetLib sriovnetPkg.SriovnetLib,
ghwLib ghwPkg.GHWLib) types.SriovInterface {
return &sriov{utilsHelper: utilsHelper,
kernelHelper: kernelHelper,
networkHelper: networkHelper,
Expand All @@ -58,6 +61,7 @@ func New(utilsHelper utils.CmdInterface,
netlinkLib: netlinkLib,
dputilsLib: dputilsLib,
sriovnetLib: sriovnetLib,
ghwLib: ghwLib,
}
}

Expand Down Expand Up @@ -217,7 +221,7 @@ func (s *sriov) DiscoverSriovDevices(storeManager store.ManagerInterface) ([]sri
log.Log.V(2).Info("DiscoverSriovDevices")
pfList := []sriovnetworkv1.InterfaceExt{}

pci, err := ghw.PCI()
pci, err := s.ghwLib.PCI()
if err != nil {
return nil, fmt.Errorf("DiscoverSriovDevices(): error getting PCI info: %v", err)
}
Expand Down
Loading

0 comments on commit 46bfbc2

Please sign in to comment.