From 34742e3bc8b3306fb1cb1ed082f391563e835721 Mon Sep 17 00:00:00 2001 From: hj-johannes-lee Date: Wed, 2 Aug 2023 14:15:45 +0300 Subject: [PATCH 1/2] e2e,fpga: divide single It() to have multiple layers Structure is as follows: Describe("FPGA plugin") Context("af mode") BeforeEach("run device plugin") It("runs a pod requesting resources") Context("region mode") BeforeEach("run device plugin") It("runs a pod requesting resources") Signed-off-by: hj-johannes-lee --- test/e2e/fpga/fpga.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/e2e/fpga/fpga.go b/test/e2e/fpga/fpga.go index c02aee4d6..5a33b2eb4 100644 --- a/test/e2e/fpga/fpga.go +++ b/test/e2e/fpga/fpga.go @@ -47,7 +47,7 @@ const ( ) func init() { - ginkgo.Describe("FPGA Plugin E2E tests", describe) + ginkgo.Describe("FPGA Plugin", describe) } func describe() { @@ -64,16 +64,27 @@ func describe() { fmw := framework.NewDefaultFramework("fpgaplugin-e2e") fmw.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged - ginkgo.It("Run FPGA plugin tests", func(ctx context.Context) { - // Run region test case twice to ensure that device is reprogrammed at least once - runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "region", arria10NodeResource, nlb3PodResource, "nlb3", "nlb0") - runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "region", arria10NodeResource, nlb0PodResource, "nlb0", "nlb3") - // Run af test case - runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "af", nlb0NodeResource, nlb0PodResourceAF, "nlb0", "nlb3") + ginkgo.Context("When FPGA plugin is running in region mode", func() { + ginkgo.BeforeEach(func(ctx context.Context) { + runDevicePlugin(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, arria10NodeResource, "region") + }) + ginkgo.It("runs an opae-nlb-demo pod two times", func(ctx context.Context) { + runTestCase(ctx, fmw, "region", nlb3PodResource, "nlb3", "nlb0") + runTestCase(ctx, fmw, "region", nlb0PodResource, "nlb0", "nlb3") + }) + }) + + ginkgo.Context("When FPGA plugin is running in af mode", func() { + ginkgo.BeforeEach(func(ctx context.Context) { + runDevicePlugin(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, nlb0NodeResource, "af") + }) + ginkgo.It("runs an opae-nlb-demo pod", func(ctx context.Context) { + runTestCase(ctx, fmw, "af", nlb0PodResourceAF, "nlb0", "nlb3") + }) }) } -func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizationPath, mappingsCollectionPath, pluginMode, nodeResource, podResource, cmd1, cmd2 string) { +func runDevicePlugin(ctx context.Context, fmw *framework.Framework, pluginKustomizationPath, mappingsCollectionPath, nodeResource, pluginMode string) { tmpDir, err := os.MkdirTemp("", "fpgaplugine2etest-"+fmw.Namespace.Name) if err != nil { framework.Failf("unable to create temp directory: %v", err) @@ -101,8 +112,10 @@ func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizat if err = utils.WaitForNodesWithResource(ctx, fmw.ClientSet, resource, 30*time.Second); err != nil { framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) } +} - resource = v1.ResourceName(podResource) +func runTestCase(ctx context.Context, fmw *framework.Framework, pluginMode, podResource, cmd1, cmd2 string) { + resource := v1.ResourceName(podResource) image := "intel/opae-nlb-demo:devel" ginkgo.By("submitting a pod requesting correct FPGA resources") @@ -111,7 +124,7 @@ func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizat ginkgo.By("waiting the pod to finish successfully") - err = e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, fmw.ClientSet, pod.ObjectMeta.Name, fmw.Namespace.Name, 60*time.Second) + err := e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, fmw.ClientSet, pod.ObjectMeta.Name, fmw.Namespace.Name, 60*time.Second) gomega.Expect(err).To(gomega.BeNil(), utils.GetPodLogs(ctx, fmw, pod.ObjectMeta.Name, "testcontainer")) ginkgo.By("submitting a pod requesting incorrect FPGA resources") From 51c003243779640f94982655655bead14b0c2554 Mon Sep 17 00:00:00 2001 From: hj-johannes-lee Date: Wed, 2 Aug 2023 16:09:00 +0300 Subject: [PATCH 2/2] e2e,gpu: divide single It() to have multiple layers Structure is as follows: Describe("GPU plugin") BeforeEach("deploys plugin") Context("When device resources are available") BeforeEach("checks if resources are available") It("runs a pod requesting resources") Signed-off-by: hj-johannes-lee --- test/e2e/gpu/gpu.go | 77 ++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/test/e2e/gpu/gpu.go b/test/e2e/gpu/gpu.go index 6225f7230..c6bbab78c 100644 --- a/test/e2e/gpu/gpu.go +++ b/test/e2e/gpu/gpu.go @@ -52,7 +52,7 @@ func describe() { framework.Failf("unable to locate %q: %v", kustomizationYaml, errFailedToLocateRepoFile) } - ginkgo.It("checks availability of GPU resources", func(ctx context.Context) { + ginkgo.BeforeEach(func(ctx context.Context) { ginkgo.By("deploying GPU plugin") e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-k", filepath.Dir(kustomizationPath)) @@ -69,49 +69,54 @@ func describe() { if err = utils.TestPodsFileSystemInfo(podList.Items); err != nil { framework.Failf("container filesystem info checks failed: %v", err) } + }) - ginkgo.By("checking if the resource is allocatable") - if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second); err != nil { - framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) - } - - ginkgo.By("submitting a pod requesting GPU resources") - podSpec := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{Name: "gpuplugin-tester"}, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Args: []string{"-c", "ls /dev/dri"}, - Name: containerName, - Image: imageutils.GetE2EImage(imageutils.BusyBox), - Command: []string{"/bin/sh"}, - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")}, - Limits: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")}, + ginkgo.Context("When GPU resources are available", func() { + ginkgo.BeforeEach(func(ctx context.Context) { + ginkgo.By("checking if the resource is allocatable") + if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second); err != nil { + framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err) + } + }) + ginkgo.It("checks availability of GPU resources", func(ctx context.Context) { + ginkgo.By("submitting a pod requesting GPU resources") + podSpec := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "gpuplugin-tester"}, + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Args: []string{"-c", "ls /dev/dri"}, + Name: containerName, + Image: imageutils.GetE2EImage(imageutils.BusyBox), + Command: []string{"/bin/sh"}, + Resources: v1.ResourceRequirements{ + Requests: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")}, + Limits: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")}, + }, }, }, + RestartPolicy: v1.RestartPolicyNever, }, - RestartPolicy: v1.RestartPolicyNever, - }, - } - pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{}) - framework.ExpectNoError(err, "pod Create API error") + } + pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{}) + framework.ExpectNoError(err, "pod Create API error") - ginkgo.By("waiting the pod to finish successfully") - e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second) + ginkgo.By("waiting the pod to finish successfully") + e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second) - ginkgo.By("checking log output") - log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, pod.Name, containerName) + ginkgo.By("checking log output") + log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, pod.Name, containerName) - if err != nil { - framework.Failf("unable to get log from pod: %v", err) - } + if err != nil { + framework.Failf("unable to get log from pod: %v", err) + } - if !strings.Contains(log, "card") || !strings.Contains(log, "renderD") { - framework.Logf("log output: %s", log) - framework.Failf("device mounts not found from log") - } + if !strings.Contains(log, "card") || !strings.Contains(log, "renderD") { + framework.Logf("log output: %s", log) + framework.Failf("device mounts not found from log") + } - framework.Logf("found card and renderD from the log") + framework.Logf("found card and renderD from the log") + }) }) }