Skip to content

Commit d93a012

Browse files
authored
Merge pull request k8snetworkplumbingwg#852 from SchSeba/bug_remove_nic_config_from_host
Remove vf configuration file from host
2 parents 0844242 + 70e7645 commit d93a012

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

pkg/host/internal/sriov/sriov.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ func (s *sriov) getConfigureAndReset(storeManager store.ManagerInterface, interf
658658
}
659659
}
660660

661-
if !configured && ifaceStatus.NumVfs > 0 {
661+
if !configured {
662662
toBeResetted = append(toBeResetted, ifaceStatus)
663663
}
664664
}
@@ -824,8 +824,10 @@ func (s *sriov) checkForConfigAndReset(ifaceStatus sriovnetworkv1.InterfaceExt,
824824
return err
825825
}
826826

827-
if err = s.ResetSriovDevice(ifaceStatus); err != nil {
828-
return err
827+
if ifaceStatus.NumVfs > 0 {
828+
if err = s.ResetSriovDevice(ifaceStatus); err != nil {
829+
return err
830+
}
829831
}
830832

831833
// remove pf status from host

pkg/host/internal/sriov/sriov_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,13 @@ var _ = Describe("SRIOV", func() {
241241
hostMock.EXPECT().HasDriver("0000:d8:00.3").Return(true, "vfio-pci").Times(2)
242242
hostMock.EXPECT().UnbindDriverIfNeeded("0000:d8:00.3", false).Return(nil)
243243
hostMock.EXPECT().BindDpdkDriver("0000:d8:00.3", "vfio-pci").Return(nil)
244+
hostMock.EXPECT().RemoveDisableNMUdevRule("0000:d8:00.1").Return(nil)
245+
hostMock.EXPECT().RemoveVfRepresentorUdevRule("0000:d8:00.1").Return(nil)
246+
hostMock.EXPECT().RemovePersistPFNameUdevRule("0000:d8:00.1").Return(nil)
244247

245248
storeManagerMode.EXPECT().SaveLastPfAppliedStatus(gomock.Any()).Return(nil)
249+
storeManagerMode.EXPECT().RemovePfAppliedStatus(gomock.Any()).Return(nil)
250+
storeManagerMode.EXPECT().LoadPfsStatus("0000:d8:00.1").Return(&sriovnetworkv1.Interface{ExternallyManaged: false}, true, nil)
246251

247252
Expect(s.ConfigSriovInterfaces(storeManagerMode,
248253
[]sriovnetworkv1.Interface{{

test/conformance/tests/test_sriov_operator.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,54 @@ var _ = Describe("[sriov] operator", Ordered, func() {
17111711
})
17121712
})
17131713

1714+
Context("Daemon reset with shutdown", Ordered, func() {
1715+
var testNode string
1716+
var policy *sriovv1.SriovNetworkNodePolicy
1717+
resourceName := "resetresource"
1718+
1719+
BeforeAll(func() {
1720+
isSingleNode, err := cluster.IsSingleNode(clients)
1721+
Expect(err).ToNot(HaveOccurred())
1722+
if isSingleNode {
1723+
Skip("test not supported for single node")
1724+
}
1725+
1726+
sriovInfos, err := cluster.DiscoverSriov(clients, operatorNamespace)
1727+
Expect(err).ToNot(HaveOccurred())
1728+
Expect(len(sriovInfos.Nodes)).ToNot(BeZero())
1729+
testNode = sriovInfos.Nodes[0]
1730+
iface, err := sriovInfos.FindOneSriovDevice(testNode)
1731+
Expect(err).ToNot(HaveOccurred())
1732+
1733+
policy, err = network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, iface.Name, testNode, 5, resourceName, "netdevice")
1734+
Expect(err).ToNot(HaveOccurred())
1735+
WaitForSRIOVStable()
1736+
})
1737+
1738+
It("should remove interface configuration from host even after reboot", func() {
1739+
By("force rebooting the node")
1740+
_, errOutput, err := runCommandOnConfigDaemon(testNode, "chroot", "/host", "reboot")
1741+
Expect(err).ToNot(HaveOccurred(), errOutput)
1742+
By("removing the policy")
1743+
err = clients.Delete(context.Background(), policy)
1744+
Expect(err).ToNot(HaveOccurred())
1745+
1746+
By("waiting for node to be not ready")
1747+
waitForNodeCondition(testNode, corev1.NodeReady, corev1.ConditionUnknown)
1748+
1749+
By("waiting for node to be ready")
1750+
waitForNodeCondition(testNode, corev1.NodeReady, corev1.ConditionTrue)
1751+
1752+
WaitForSRIOVStable()
1753+
By("Checking files on the host")
1754+
output, errOutput, err := runCommandOnConfigDaemon(testNode, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l")
1755+
Expect(err).ToNot(HaveOccurred(), errOutput)
1756+
Expect(strings.HasPrefix(output, "0")).Should(BeTrue())
1757+
output, errOutput, err = runCommandOnConfigDaemon(testNode, "/bin/bash", "-c", "ls /host/etc/udev/rules.d/ | grep 10-nm-disable | wc -l")
1758+
Expect(err).ToNot(HaveOccurred(), errOutput)
1759+
Expect(strings.HasPrefix(output, "0")).Should(BeTrue())
1760+
})
1761+
})
17141762
})
17151763
})
17161764

@@ -2403,3 +2451,16 @@ func getInterfaceFromNodeStateByPciAddress(node, pciAddress string) *sriovv1.Int
24032451
Expect(found).To(BeTrue())
24042452
return intf
24052453
}
2454+
2455+
func waitForNodeCondition(nodeName string, conditionType corev1.NodeConditionType, conditionStatus corev1.ConditionStatus) {
2456+
EventuallyWithOffset(1, func(g Gomega) bool {
2457+
node, err := clients.CoreV1Interface.Nodes().Get(context.Background(), nodeName, metav1.GetOptions{})
2458+
g.Expect(err).ToNot(HaveOccurred())
2459+
for _, con := range node.Status.Conditions {
2460+
if con.Type == conditionType && con.Status == conditionStatus {
2461+
return true
2462+
}
2463+
}
2464+
return false
2465+
}, waitingTime, 1*time.Second).Should(BeTrue())
2466+
}

0 commit comments

Comments
 (0)