-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend Udev interface to support switchdev rule
The rule is required to generate predictable names for VF representors when NIC is in switchdev mode. Signed-off-by: Yury Kulazhenkov <ykulazhenkov@nvidia.com>
- Loading branch information
1 parent
5ef3b41
commit 9ebbf41
Showing
7 changed files
with
258 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package udev | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"go.uber.org/zap/zapcore" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars" | ||
) | ||
|
||
func TestUdev(t *testing.T) { | ||
log.SetLogger(zap.New( | ||
zap.WriteTo(GinkgoWriter), | ||
zap.Level(zapcore.Level(-2)), | ||
zap.UseDevMode(true))) | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Package Udev Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
vars.SupportedVfIds = []string{"0x1017", "0x1018"} | ||
DeferCleanup(func() { | ||
vars.SupportedVfIds = []string{} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package udev | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/fakefilesystem" | ||
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/helpers" | ||
) | ||
|
||
const ( | ||
testExpectedNMUdevRule = "SUBSYSTEM==\"net\", ACTION==\"add|change|move\", " + | ||
"ATTRS{device}==\"0x1017|0x1018\", " + | ||
"IMPORT{program}=\"/etc/udev/disable-nm-sriov.sh $env{INTERFACE} 0000:d8:00.0\"" | ||
testExpectedSwitchdevUdevRule = "SUBSYSTEM==\"net\", ACTION==\"add|move\", " + | ||
"ATTRS{phys_switch_id}==\"7cfe90ff2cc0\", " + | ||
"ATTR{phys_port_name}==\"pf0vf*\", IMPORT{program}=\"/etc/udev/switchdev-vf-link-name.sh $attr{phys_port_name}\", " + | ||
"NAME=\"enp216s0f0np0_$env{NUMBER}\"" | ||
) | ||
|
||
var _ = Describe("UDEV", func() { | ||
var ( | ||
s types.UdevInterface | ||
) | ||
BeforeEach(func() { | ||
s = New(nil) | ||
}) | ||
Context("AddUdevRule", func() { | ||
It("Created", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{}) | ||
Expect(s.AddUdevRule("0000:d8:00.0")).To(BeNil()) | ||
helpers.GinkgoAssertFileContentsEquals( | ||
"/etc/udev/rules.d/10-nm-disable-0000:d8:00.0.rules", | ||
testExpectedNMUdevRule) | ||
}) | ||
It("Overwrite", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
Files: map[string][]byte{ | ||
"/etc/udev/rules.d/10-nm-disable-0000:d8:00.0.rules": []byte("something"), | ||
}, | ||
}) | ||
Expect(s.AddUdevRule("0000:d8:00.0")).To(BeNil()) | ||
helpers.GinkgoAssertFileContentsEquals( | ||
"/etc/udev/rules.d/10-nm-disable-0000:d8:00.0.rules", | ||
testExpectedNMUdevRule) | ||
}) | ||
}) | ||
Context("RemoveUdevRule", func() { | ||
It("Exist", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
Files: map[string][]byte{ | ||
"/etc/udev/rules.d/10-nm-disable-0000:d8:00.0.rules": []byte(testExpectedNMUdevRule), | ||
}, | ||
}) | ||
Expect(s.RemoveUdevRule("0000:d8:00.0")).To(BeNil()) | ||
_, err := os.Stat(filepath.Join(vars.FilesystemRoot, | ||
"/etc/udev/rules.d/10-nm-disable-0000:d8:00.0.rules")) | ||
Expect(os.IsNotExist(err)).To(BeTrue()) | ||
}) | ||
It("Not found", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
}) | ||
Expect(s.RemoveUdevRule("0000:d8:00.0")).To(BeNil()) | ||
}) | ||
}) | ||
Context("AddVfRepresentorUdevRule", func() { | ||
It("Created", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{}) | ||
Expect(s.AddVfRepresentorUdevRule("0000:d8:00.0", | ||
"enp216s0f0np0", "7cfe90ff2cc0", "p0")).To(BeNil()) | ||
helpers.GinkgoAssertFileContentsEquals( | ||
"/etc/udev/rules.d/20-switchdev-0000:d8:00.0.rules", | ||
testExpectedSwitchdevUdevRule) | ||
}) | ||
It("Overwrite", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
Files: map[string][]byte{ | ||
"/etc/udev/rules.d/20-switchdev-0000:d8:00.0.rules": []byte("something"), | ||
}, | ||
}) | ||
Expect(s.AddVfRepresentorUdevRule("0000:d8:00.0", | ||
"enp216s0f0np0", "7cfe90ff2cc0", "p0")).To(BeNil()) | ||
helpers.GinkgoAssertFileContentsEquals( | ||
"/etc/udev/rules.d/20-switchdev-0000:d8:00.0.rules", | ||
testExpectedSwitchdevUdevRule) | ||
}) | ||
}) | ||
Context("RemoveVfRepresentorUdevRule", func() { | ||
It("Exist", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
Files: map[string][]byte{ | ||
"/etc/udev/rules.d/20-switchdev-0000:d8:00.0.rules": []byte(testExpectedSwitchdevUdevRule), | ||
}, | ||
}) | ||
Expect(s.RemoveVfRepresentorUdevRule("0000:d8:00.0")).To(BeNil()) | ||
_, err := os.Stat(filepath.Join(vars.FilesystemRoot, | ||
"/etc/udev/rules.d/20-switchdev-0000:d8:00.0.rules")) | ||
Expect(os.IsNotExist(err)).To(BeTrue()) | ||
}) | ||
It("Not found", func() { | ||
helpers.GinkgoConfigureFakeFS(&fakefilesystem.FS{ | ||
Dirs: []string{"/etc/udev/rules.d"}, | ||
}) | ||
Expect(s.RemoveVfRepresentorUdevRule("0000:d8:00.0")).To(BeNil()) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters