diff --git a/test/conformance/test_suite_test.go b/test/conformance/test_suite_test.go index 2c3fd7448..583a94a83 100644 --- a/test/conformance/test_suite_test.go +++ b/test/conformance/test_suite_test.go @@ -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") } - diff --git a/test/conformance/tests/fixtures.go b/test/conformance/tests/fixtures.go index bf305b667..33748b6e6 100644 --- a/test/conformance/tests/fixtures.go +++ b/test/conformance/tests/fixtures.go @@ -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()) @@ -46,4 +46,4 @@ var _ = BeforeSuite(func() { var _ = AfterSuite(func() { err := clean.All() Expect(err).NotTo(HaveOccurred()) -}) \ No newline at end of file +}) diff --git a/test/conformance/tests/test_policy_configuration.go b/test/conformance/tests/test_policy_configuration.go index 7b4f52d83..28a2c95cc 100644 --- a/test/conformance/tests/test_policy_configuration.go +++ b/test/conformance/tests/test_policy_configuration.go @@ -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"] @@ -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"] @@ -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") diff --git a/test/conformance/tests/test_sriov_operator.go b/test/conformance/tests/test_sriov_operator.go index 59b58a163..4c8826e22 100644 --- a/test/conformance/tests/test_sriov_operator.go +++ b/test/conformance/tests/test_sriov_operator.go @@ -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 { @@ -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 { @@ -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()) @@ -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 @@ -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( @@ -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() { @@ -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) { @@ -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 {