Skip to content

Commit

Permalink
Merge pull request #369 from zeeke/udev-fix
Browse files Browse the repository at this point in the history
config-daemon: fix NM udev path
  • Loading branch information
e0ne authored Oct 13, 2022
2 parents c7a317d + 1c0bf41 commit 54c377f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ func tryCreateSwitchdevUdevRule(nodeState *sriovnetworkv1.SriovNetworkNodeState)

func tryCreateNMUdevRule() error {
glog.V(2).Infof("tryCreateNMUdevRule()")
dirPath := path.Join(filesystemRoot, "/host/etc/udev/rules.d/")
filePath := dirPath + "10-nm-unmanaged.rules"
dirPath := path.Join(filesystemRoot, "/host/etc/udev/rules.d")
filePath := path.Join(dirPath, "10-nm-unmanaged.rules")

newContent := fmt.Sprintf("ACTION==\"add|change|move\", ATTRS{device}==\"%s\", ENV{NM_UNMANAGED}=\"1\"\n", strings.Join(sriovnetworkv1.GetSupportedVfIds(), "|"))

Expand Down
28 changes: 27 additions & 1 deletion pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package daemon
import (
"context"
"flag"
"io/ioutil"
"path"
"testing"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
Expand All @@ -26,7 +28,10 @@ var FakeSupportedNicIDs corev1.ConfigMap = corev1.ConfigMap{
Name: sriovnetworkv1.SupportedNicIDConfigmap,
Namespace: namespace,
},
Data: map[string]string{},
Data: map[string]string{
"Intel_i40e_XXV710": "8086 158a 154c",
"Nvidia_mlx5_ConnectX-4": "15b3 1013 1014",
},
}

var SriovDevicePluginPod corev1.Pod = corev1.Pod{
Expand Down Expand Up @@ -95,6 +100,9 @@ var _ = Describe("Config Daemon", func() {
kubeClient := fakek8s.NewSimpleClientset(&FakeSupportedNicIDs, &SriovDevicePluginPod)
client := fakesnclientset.NewSimpleClientset()

err = sriovnetworkv1.InitNicIDMap(kubeClient, namespace)
Expect(err).ToNot(HaveOccurred())

sut = New("test-node",
client,
kubeClient,
Expand Down Expand Up @@ -222,6 +230,17 @@ var _ = Describe("Config Daemon", func() {

Expect(sut.nodeState.GetGeneration()).To(BeNumerically("==", 777))
})

It("configure udev rules on host", func() {

networkManagerUdevRulePath := path.Join(filesystemRoot, "host/etc/udev/rules.d/10-nm-unmanaged.rules")

expectedContents := `ACTION=="add|change|move", ATTRS{device}=="0x1014|0x154c", ENV{NM_UNMANAGED}="1"
SUBSYSTEM=="net", ACTION=="add|move", ATTRS{phys_switch_id}!="", ATTR{phys_port_name}=="pf*vf*", ENV{NM_UNMANAGED}="1"
`
// No need to trigger any action on config-daemon, as it checks the file in the main loop
assertFileContents(networkManagerUdevRulePath, expectedContents)
})
})
})

Expand All @@ -238,3 +257,10 @@ func updateSriovNetworkNodeState(c snclientset.Interface, nodeState *sriovnetwor
Update(context.Background(), nodeState, metav1.UpdateOptions{})
return err
}

func assertFileContents(path, contents string) {
Eventually(func() (string, error) {
ret, err := ioutil.ReadFile(path)
return string(ret), err
}, "10s").WithOffset(1).Should(Equal(contents))
}

0 comments on commit 54c377f

Please sign in to comment.