Skip to content

Commit 03d6884

Browse files
committed
Remove vf configuration file from host
In case a policy gets removed when a node is rebooting after the reboot the number of virtual functions will be 0 and we will not remove the related configuration files from the host. This commit fixes that issue Signed-off-by: Sebastian Sch <sebassch@gmail.com>
1 parent 9ddf872 commit 03d6884

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,72 @@ var _ = Describe("[sriov] operator", func() {
17221722
})
17231723
})
17241724

1725+
Context("Daemon reset with shutdown", Ordered, func() {
1726+
var testNode string
1727+
var policy *sriovv1.SriovNetworkNodePolicy
1728+
resourceName := "resetresource"
1729+
1730+
BeforeAll(func() {
1731+
isSingleNode, err := cluster.IsSingleNode(clients)
1732+
Expect(err).ToNot(HaveOccurred())
1733+
if isSingleNode {
1734+
Skip("test not supported for single node")
1735+
}
1736+
1737+
sriovInfos, err := cluster.DiscoverSriov(clients, operatorNamespace)
1738+
Expect(err).ToNot(HaveOccurred())
1739+
Expect(len(sriovInfos.Nodes)).ToNot(BeZero())
1740+
testNode = sriovInfos.Nodes[0]
1741+
iface, err := sriovInfos.FindOneSriovDevice(testNode)
1742+
Expect(err).ToNot(HaveOccurred())
1743+
1744+
policy, err = network.CreateSriovPolicy(clients, "test-policy-", operatorNamespace, iface.Name, testNode, 5, resourceName, "netdevice")
1745+
Expect(err).ToNot(HaveOccurred())
1746+
WaitForSRIOVStable()
1747+
})
1748+
1749+
It("should remove interface configuration from host even after reboot", func() {
1750+
By("force rebooting the node")
1751+
_, errOutput, err := runCommandOnConfigDaemon(testNode, "chroot", "/host", "reboot")
1752+
Expect(err).ToNot(HaveOccurred(), errOutput)
1753+
By("removing the policy")
1754+
err = clients.Delete(context.Background(), policy)
1755+
Expect(err).ToNot(HaveOccurred())
1756+
1757+
By("waiting for node to be not ready")
1758+
Eventually(func(g Gomega) bool {
1759+
node, err := clients.CoreV1Interface.Nodes().Get(context.Background(), testNode, metav1.GetOptions{})
1760+
g.Expect(err).ToNot(HaveOccurred())
1761+
for _, con := range node.Status.Conditions {
1762+
if con.Type == corev1.NodeReady && con.Status != corev1.ConditionTrue {
1763+
return true
1764+
}
1765+
}
1766+
return false
1767+
}, waitingTime, 1*time.Second).Should(BeTrue())
1768+
1769+
By("waiting for node to be ready")
1770+
Eventually(func(g Gomega) bool {
1771+
node, err := clients.CoreV1Interface.Nodes().Get(context.Background(), testNode, metav1.GetOptions{})
1772+
g.Expect(err).ToNot(HaveOccurred())
1773+
for _, con := range node.Status.Conditions {
1774+
if con.Type == corev1.NodeReady && con.Status == corev1.ConditionTrue {
1775+
return true
1776+
}
1777+
}
1778+
return false
1779+
}, waitingTime, 1*time.Second).Should(BeTrue())
1780+
1781+
WaitForSRIOVStable()
1782+
By("Checking files on the host")
1783+
output, errOutput, err := runCommandOnConfigDaemon(testNode, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l")
1784+
Expect(err).ToNot(HaveOccurred(), errOutput)
1785+
Expect(strings.HasPrefix(output, "0")).Should(BeTrue())
1786+
output, errOutput, err = runCommandOnConfigDaemon(testNode, "/bin/bash", "-c", "ls /host/etc/udev/rules.d/ | grep 10-nm-disable | wc -l")
1787+
Expect(err).ToNot(HaveOccurred(), errOutput)
1788+
Expect(strings.HasPrefix(output, "0")).Should(BeTrue())
1789+
})
1790+
})
17251791
})
17261792
})
17271793

0 commit comments

Comments
 (0)