Skip to content

Commit

Permalink
e2e: Refactor to waitForPodRunning
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Panattoni <apanatto@redhat.com>
  • Loading branch information
zeeke committed Jul 19, 2024
1 parent 9e1699b commit 32123e1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 65 deletions.
1 change: 0 additions & 1 deletion test/conformance/test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ func TestTest(t *testing.T) {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
RunSpecs(t, "SRIOV Operator conformance tests")
}

8 changes: 4 additions & 4 deletions test/conformance/tests/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package tests

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/clean"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var sriovInfos *cluster.EnabledNodes


var _ = BeforeSuite(func() {
err := clean.All()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -46,4 +46,4 @@ var _ = BeforeSuite(func() {
var _ = AfterSuite(func() {
err := clean.All()
Expect(err).NotTo(HaveOccurred())
})
})
15 changes: 3 additions & 12 deletions test/conformance/tests/test_policy_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ var _ = Describe("[sriov] operator", Ordered, func() {
firstPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func() corev1.PodPhase {
firstPod, _ = clients.Pods(namespaces.Test).Get(context.Background(), firstPod.Name, metav1.GetOptions{})
return firstPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
firstPod = waitForPodRunning(firstPod)

By("Checking MTU in pod network status annotation")
networkStatusJSON, exist := firstPod.Annotations["k8s.v1.cni.cncf.io/network-status"]
Expand Down Expand Up @@ -629,10 +626,7 @@ var _ = Describe("[sriov] operator", Ordered, func() {
firstPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func() corev1.PodPhase {
firstPod, _ = clients.Pods(namespaces.Test).Get(context.Background(), firstPod.Name, metav1.GetOptions{})
return firstPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
firstPod = waitForPodRunning(firstPod)

By("Checking MTU in pod network status annotation")
networkStatusJSON, exist := firstPod.Annotations["k8s.v1.cni.cncf.io/network-status"]
Expand Down Expand Up @@ -661,10 +655,7 @@ var _ = Describe("[sriov] operator", Ordered, func() {
secondPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func() corev1.PodPhase {
secondPod, _ = clients.Pods(namespaces.Test).Get(context.Background(), secondPod.Name, metav1.GetOptions{})
return secondPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
secondPod = waitForPodRunning(secondPod)

stdout, stderr, err = pod.ExecCommand(clients, secondPod,
"ping", firstPodIPs[0], "-s", "8972", "-M", "do", "-c", "2")
Expand Down
70 changes: 22 additions & 48 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,7 @@ var _ = Describe("[sriov] operator", func() {
created, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

var runningPod *corev1.Pod
Eventually(func() corev1.PodPhase {
runningPod, err = clients.Pods(namespaces.Test).Get(context.Background(), created.Name, metav1.GetOptions{})
if k8serrors.IsNotFound(err) {
return corev1.PodUnknown
}
Expect(err).ToNot(HaveOccurred())

return runningPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
runningPod := waitForPodRunning(created)

var downwardVolume *corev1.Volume
for _, v := range runningPod.Spec.Volumes {
Expand Down Expand Up @@ -438,16 +429,7 @@ var _ = Describe("[sriov] operator", func() {
created, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

var runningPod *corev1.Pod
Eventually(func() corev1.PodPhase {
runningPod, err = clients.Pods(namespaces.Test).Get(context.Background(), created.Name, metav1.GetOptions{})
if k8serrors.IsNotFound(err) {
return corev1.PodUnknown
}
Expect(err).ToNot(HaveOccurred())

return runningPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
runningPod := waitForPodRunning(created)

var downwardVolume *corev1.Volume
for _, v := range runningPod.Spec.Volumes {
Expand Down Expand Up @@ -484,11 +466,8 @@ var _ = Describe("[sriov] operator", func() {
podObj := pod.RedefineWithNodeSelector(pod.DefineWithNetworks(networks), node)
err := clients.Create(context.Background(), podObj)
Expect(err).ToNot(HaveOccurred())
Eventually(func() corev1.PodPhase {
podObj, err = clients.Pods(namespaces.Test).Get(context.Background(), podObj.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return podObj.Status.Phase
}, 5*time.Minute, time.Second).Should(Equal(corev1.PodRunning))

podObj = waitForPodRunning(podObj)

vfIndex, err := podVFIndexInHost(hostNetPod, podObj, "net1")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -543,11 +522,8 @@ var _ = Describe("[sriov] operator", func() {
hostNetPod = pod.DefineWithHostNetwork(node)
err := clients.Create(context.Background(), hostNetPod)
Expect(err).ToNot(HaveOccurred())
Eventually(func() corev1.PodPhase {
hostNetPod, err = clients.Pods(namespaces.Test).Get(context.Background(), hostNetPod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return hostNetPod.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))

hostNetPod = waitForPodRunning(hostNetPod)
})

// 25959
Expand Down Expand Up @@ -976,11 +952,8 @@ var _ = Describe("[sriov] operator", func() {
runningPodA, err := clients.Pods(testPodA.Namespace).Create(context.Background(), testPodA, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error to create pod %s", testPodA.Name))
By("Checking that first Pod is in Running state")
Eventually(func() corev1.PodPhase {
runningPodA, err = clients.Pods(namespaces.Test).Get(context.Background(), runningPodA.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return runningPodA.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
runningPodA = waitForPodRunning(runningPodA)

By("Create second Pod which consumes one more VF")

testPodB := pod.RedefineWithNodeSelector(
Expand Down Expand Up @@ -1014,11 +987,7 @@ var _ = Describe("[sriov] operator", func() {
})
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error to delete pod %s", runningPodA.Name))
By("Checking that second pod is able to use released VF")
Eventually(func() corev1.PodPhase {
runningPodB, err = clients.Pods(namespaces.Test).Get(context.Background(), runningPodB.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return runningPodB.Status.Phase
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
waitForPodRunning(runningPodB)
})

It("should reconcile managed VF if status is changed", func() {
Expand Down Expand Up @@ -1920,14 +1889,7 @@ func createCustomTestPod(node string, networks []string, hostNetwork bool, podCa
createdPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

Eventually(func() corev1.PodPhase {
runningPod, err := clients.Pods(namespaces.Test).Get(context.Background(), createdPod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return runningPod.Status.Phase
}, 5*time.Minute, 1*time.Second).Should(Equal(corev1.PodRunning))
podObj, err := clients.Pods(namespaces.Test).Get(context.Background(), createdPod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return podObj
return waitForPodRunning(createdPod)
}

func pingPod(ip string, nodeSelector string, sriovNetworkAttachment string) {
Expand Down Expand Up @@ -2247,6 +2209,18 @@ func waitForNetAttachDef(name, namespace string) {
}, (10+snoTimeoutMultiplier*110)*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
}

func waitForPodRunning(p *corev1.Pod) *corev1.Pod {
var ret *corev1.Pod
Eventually(func(g Gomega) corev1.PodPhase {
var err error
ret, err = clients.Pods(p.Namespace).Get(context.Background(), p.Name, metav1.GetOptions{})
g.Expect(err).ToNot(HaveOccurred())
return ret.Status.Phase
}, 3*time.Minute, 1*time.Second).Should(Equal(corev1.PodRunning), "Pod [%s/%s] should be running", p.Namespace, p.Name)

return ret
}

// assertNodeStateHasVFMatching asserts that the given node state has at least one VF matching the given fields
func assertNodeStateHasVFMatching(nodeName string, fields Fields) {
EventuallyWithOffset(1, func(g Gomega) sriovv1.InterfaceExts {
Expand Down

0 comments on commit 32123e1

Please sign in to comment.