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 <[email protected]>
  • Loading branch information
zeeke committed Jul 12, 2024
1 parent 8fce829 commit 789af14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 72 deletions.
3 changes: 1 addition & 2 deletions test/conformance/tests/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

var sriovInfos *cluster.EnabledNodes


var _ = BeforeSuite(func() {
err := clean.All()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -46,4 +45,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 @@ -97,10 +97,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))
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 @@ -606,10 +603,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))
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 @@ -638,10 +632,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))
waitForPodRunning(secondPod)

stdout, stderr, err = pod.ExecCommand(clients, secondPod,
"ping", firstPodIPs[0], "-s", "8972", "-M", "do", "-c", "2")
Expand Down
82 changes: 24 additions & 58 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 @@ -1638,11 +1607,7 @@ func changeNodeInterfaceState(testNode string, ifcName string, enable bool) {
)
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
}, 3*time.Minute, 1*time.Second).Should(Equal(corev1.PodSucceeded))
waitForPodRunning(createdPod)
}

func discoverResourceForMainSriov(nodes *cluster.EnabledNodes) (*sriovv1.InterfaceExt, string, string, bool) {
Expand Down Expand Up @@ -1906,14 +1871,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 All @@ -1938,11 +1896,7 @@ func pingPod(ip string, nodeSelector string, sriovNetworkAttachment string) {
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
}, 3*time.Minute, 1*time.Second).Should(Equal(corev1.PodSucceeded))
waitForPodRunning(createdPod)
}

func WaitForSRIOVStable() {
Expand Down Expand Up @@ -2233,6 +2187,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.PodSucceeded), "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 789af14

Please sign in to comment.