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

Healing #31

Merged
merged 11 commits into from
Dec 14, 2020
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
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,12 @@ issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: ./
linters:
- gocritic
text: "sloppyReassign: re-assignment to `err` can be replaced with `err :="
- path: ./
linters:
- gocritic
- govet
text: "shadow: declaration of \"err\" shadows declaration"
6 changes: 3 additions & 3 deletions pkg/networkservice/common/mechanisms/vfio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package vfio
import (
"context"
"os"
"path"
"path/filepath"

"github.com/golang/protobuf/ptypes/empty"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *vfioClient) Request(ctx context.Context, request *networkservice.Networ
}

if err := unix.Mknod(
path.Join(c.vfioDir, vfioDevice),
filepath.Join(c.vfioDir, vfioDevice),
unix.S_IFCHR|mknodPerm,
int(unix.Mkdev(mech.GetVfioMajor(), mech.GetVfioMinor())),
); err != nil && !os.IsExist(err) {
Expand All @@ -78,7 +78,7 @@ func (c *vfioClient) Request(ctx context.Context, request *networkservice.Networ

igid := mech.GetParameters()[vfio.IommuGroupKey]
if err := unix.Mknod(
path.Join(c.vfioDir, igid),
filepath.Join(c.vfioDir, igid),
unix.S_IFCHR|mknodPerm,
int(unix.Mkdev(mech.GetDeviceMajor(), mech.GetDeviceMinor())),
); err != nil && !os.IsExist(err) {
Expand Down
132 changes: 0 additions & 132 deletions pkg/networkservice/common/mechanisms/vfio/client_linux_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//+build !windows

package vfio_test

import (
"context"
"net/url"
"os"
"path"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"
"golang.org/x/sys/unix"
"google.golang.org/grpc"

Expand All @@ -34,7 +37,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/stretchr/testify/assert"

"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/mechanisms/vfio"
)
Expand All @@ -46,7 +48,7 @@ const (
func testServer(ctx context.Context, tmpDir string) (grpc.ClientConnInterface, error) {
socketURL := &url.URL{
Scheme: "unix",
Path: path.Join(tmpDir, serverSocket),
Path: filepath.Join(tmpDir, serverSocket),
}

server := grpc.NewServer()
Expand All @@ -66,17 +68,17 @@ func testServer(ctx context.Context, tmpDir string) (grpc.ClientConnInterface, e
return grpc.DialContext(ctx, socketURL.String(), grpc.WithInsecure())
}

func TestVfioClient_Request(t *testing.T) {
func TestVFIOClient_Request(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
defer cancel()

tmpDir := path.Join(os.TempDir(), t.Name())
tmpDir := filepath.Join(os.TempDir(), t.Name())
err := os.MkdirAll(tmpDir, 0750)
assert.Nil(t, err)
require.NoError(t, err)
defer func() { _ = os.RemoveAll(tmpDir) }()

cc, err := testServer(ctx, tmpDir)
assert.Nil(t, err)
require.NoError(t, err)

client := chain.NewNetworkServiceClient(
vfio.NewClient(tmpDir, cgroupDir),
Expand All @@ -86,25 +88,25 @@ func TestVfioClient_Request(t *testing.T) {
conn, err := client.Request(ctx, &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{},
})
assert.Nil(t, err)
require.NoError(t, err)

mech := vfiomech.ToMechanism(conn.GetMechanism())
assert.NotNil(t, mech)
assert.Equal(t, cgroupDir, mech.GetCgroupDir())
require.NotNil(t, mech)
require.Equal(t, cgroupDir, mech.GetCgroupDir())

info := new(unix.Stat_t)

err = unix.Stat(path.Join(tmpDir, vfioDevice), info)
assert.Nil(t, err)
assert.Equal(t, uint32(1), unix.Major(uint64(info.Rdev)))
assert.Equal(t, uint32(2), unix.Minor(uint64(info.Rdev)))
err = unix.Stat(filepath.Join(tmpDir, vfioDevice), info)
require.NoError(t, err)
require.Equal(t, uint32(1), vfio.Major(info.Rdev))
require.Equal(t, uint32(2), vfio.Minor(info.Rdev))

err = unix.Stat(path.Join(tmpDir, iommuGroupString), info)
assert.Nil(t, err)
assert.Equal(t, uint32(3), unix.Major(uint64(info.Rdev)))
assert.Equal(t, uint32(4), unix.Minor(uint64(info.Rdev)))
err = unix.Stat(filepath.Join(tmpDir, iommuGroupString), info)
require.NoError(t, err)
require.Equal(t, uint32(3), vfio.Major(info.Rdev))
require.Equal(t, uint32(4), vfio.Minor(info.Rdev))

assert.Nil(t, ctx.Err())
require.NoError(t, ctx.Err())
}

type vfioForwarderStub struct {
Expand Down
43 changes: 0 additions & 43 deletions pkg/networkservice/common/mechanisms/vfio/client_windows.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/networkservice/common/mechanisms/vfio/const_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//+build !windows

package vfio_test

const (
Expand Down
Loading