Skip to content

Commit d34e85b

Browse files
authored
Merge pull request #962 from zeeke/us/pf-shutdown
e2e: Refactor `PF shutdown` test case
2 parents 4d29425 + 90b11c8 commit d34e85b

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

test/conformance/tests/test_policy_configuration.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,15 @@ var _ = Describe("[sriov] operator", Ordered, func() {
456456
})
457457
Context("PF shutdown", func() {
458458
// 29398
459-
It("Should be able to create pods successfully if PF is down.Pods are able to communicate with each other on the same node", func() {
459+
It("Should be able to create pods successfully on a NIC with NO_CARRIER. Pods are able to communicate with each other on the same node", func() {
460460
if cluster.VirtualCluster() {
461461
// https://bugzilla.redhat.com/show_bug.cgi?id=2214976
462462
Skip("Bug in IGB driver")
463463
}
464464

465465
resourceName := testResourceName
466466
var testNode string
467-
var unusedSriovDevice *sriovv1.InterfaceExt
467+
var noCarrierSriovDevice *sriovv1.InterfaceExt
468468

469469
if discovery.Enabled() {
470470
Skip("PF Shutdown test not enabled in discovery mode")
@@ -473,17 +473,15 @@ var _ = Describe("[sriov] operator", Ordered, func() {
473473
testNode = sriovInfos.Nodes[0]
474474
sriovDeviceList, err := sriovInfos.FindSriovDevices(testNode)
475475
Expect(err).ToNot(HaveOccurred())
476-
unusedSriovDevices, err := findUnusedSriovDevices(testNode, sriovDeviceList)
476+
noCarrierSriovDevices, err := findNoCarrierSriovDevices(testNode, sriovDeviceList)
477477
if err != nil {
478478
Skip(err.Error())
479479
}
480-
unusedSriovDevice = unusedSriovDevices[0]
480+
noCarrierSriovDevice = noCarrierSriovDevices[0]
481481

482-
By("Using device " + unusedSriovDevice.Name + " on node " + testNode)
482+
By("Using device " + noCarrierSriovDevice.Name + " on node " + testNode)
483483

484-
defer changeNodeInterfaceState(testNode, unusedSriovDevices[0].Name, true)
485-
Expect(err).ToNot(HaveOccurred())
486-
createSriovPolicy(unusedSriovDevice.Name, testNode, 2, resourceName)
484+
createSriovPolicy(noCarrierSriovDevice.Name, testNode, 2, resourceName)
487485

488486
ipam := `{
489487
"type":"host-local",
@@ -492,10 +490,10 @@ var _ = Describe("[sriov] operator", Ordered, func() {
492490
"rangeEnd":"10.10.10.181"
493491
}`
494492

495-
err = network.CreateSriovNetwork(clients, unusedSriovDevice, sriovNetworkName, namespaces.Test, operatorNamespace, resourceName, ipam)
493+
err = network.CreateSriovNetwork(clients, noCarrierSriovDevice, sriovNetworkName, namespaces.Test, operatorNamespace, resourceName, ipam)
496494
Expect(err).ToNot(HaveOccurred())
497495
waitForNetAttachDef(sriovNetworkName, namespaces.Test)
498-
changeNodeInterfaceState(testNode, unusedSriovDevice.Name, false)
496+
499497
pod := createTestPod(testNode, []string{sriovNetworkName})
500498
ips, err := network.GetSriovNicIPs(pod, "net1")
501499
Expect(err).ToNot(HaveOccurred())

test/conformance/tests/test_sriov_operator.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,29 +1543,6 @@ func getDriver(ethtoolstdout string) string {
15431543
return ""
15441544
}
15451545

1546-
func changeNodeInterfaceState(testNode string, ifcName string, enable bool) {
1547-
state := "up"
1548-
if !enable {
1549-
state = "down"
1550-
}
1551-
podDefinition := pod.RedefineAsPrivileged(
1552-
pod.RedefineWithRestartPolicy(
1553-
pod.RedefineWithCommand(
1554-
pod.DefineWithHostNetwork(testNode),
1555-
[]string{"ip", "link", "set", "dev", ifcName, state}, []string{},
1556-
),
1557-
corev1.RestartPolicyNever,
1558-
),
1559-
)
1560-
createdPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
1561-
Expect(err).ToNot(HaveOccurred())
1562-
Eventually(func() corev1.PodPhase {
1563-
runningPod, err := clients.Pods(namespaces.Test).Get(context.Background(), createdPod.Name, metav1.GetOptions{})
1564-
Expect(err).ToNot(HaveOccurred())
1565-
return runningPod.Status.Phase
1566-
}, 3*time.Minute, 1*time.Second).Should(Equal(corev1.PodSucceeded))
1567-
}
1568-
15691546
func discoverResourceForMainSriov(nodes *cluster.EnabledNodes) (*sriovv1.InterfaceExt, string, string, bool) {
15701547
for _, node := range nodes.Nodes {
15711548
nodeDevices, err := nodes.FindSriovDevices(node)
@@ -1690,6 +1667,33 @@ func isDefaultRouteInterface(intfName string, routes []string) bool {
16901667
return false
16911668
}
16921669

1670+
func findNoCarrierSriovDevices(testNode string, sriovDevices []*sriovv1.InterfaceExt) ([]*sriovv1.InterfaceExt, error) {
1671+
filteredDevices := []*sriovv1.InterfaceExt{}
1672+
1673+
for _, device := range sriovDevices {
1674+
stdout, stderr, err := runCommandOnConfigDaemon(testNode, "/bin/bash", "-c", fmt.Sprintf("ip link show %s", device.Name))
1675+
if err != nil {
1676+
fmt.Printf("Can't query link state for device [%s]: %s", device.Name, err.Error())
1677+
continue
1678+
}
1679+
1680+
if len(stdout) == 0 {
1681+
fmt.Printf("Can't query link state for device [%s]: stderr:[%s]", device.Name, stderr)
1682+
continue
1683+
}
1684+
1685+
// Check for NO-CARRIER state
1686+
if strings.Contains(stdout, "NO-CARRIER") {
1687+
filteredDevices = append(filteredDevices, device)
1688+
}
1689+
}
1690+
if len(filteredDevices) == 0 {
1691+
return nil, fmt.Errorf("no carrier sriov devices not found")
1692+
}
1693+
1694+
return filteredDevices, nil
1695+
}
1696+
16931697
// podVFIndexInHost retrieves the vf index on the host network namespace related to the given
16941698
// interface that was passed to the pod, using the name in the pod's namespace.
16951699
func podVFIndexInHost(hostNetPod *corev1.Pod, targetPod *corev1.Pod, interfaceName string) (int, error) {

0 commit comments

Comments
 (0)