Skip to content

Commit a70651f

Browse files
Merge pull request #1491 from hj-johannes-lee/PR-2023-025
e2e,gpu,fpga: divide single It() to have multiple layers
2 parents d43bab5 + 51c0032 commit a70651f

File tree

2 files changed

+64
-46
lines changed

2 files changed

+64
-46
lines changed

test/e2e/fpga/fpga.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
)
4848

4949
func init() {
50-
ginkgo.Describe("FPGA Plugin E2E tests", describe)
50+
ginkgo.Describe("FPGA Plugin", describe)
5151
}
5252

5353
func describe() {
@@ -64,16 +64,27 @@ func describe() {
6464
fmw := framework.NewDefaultFramework("fpgaplugin-e2e")
6565
fmw.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
6666

67-
ginkgo.It("Run FPGA plugin tests", func(ctx context.Context) {
68-
// Run region test case twice to ensure that device is reprogrammed at least once
69-
runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "region", arria10NodeResource, nlb3PodResource, "nlb3", "nlb0")
70-
runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "region", arria10NodeResource, nlb0PodResource, "nlb0", "nlb3")
71-
// Run af test case
72-
runTestCase(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, "af", nlb0NodeResource, nlb0PodResourceAF, "nlb0", "nlb3")
67+
ginkgo.Context("When FPGA plugin is running in region mode", func() {
68+
ginkgo.BeforeEach(func(ctx context.Context) {
69+
runDevicePlugin(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, arria10NodeResource, "region")
70+
})
71+
ginkgo.It("runs an opae-nlb-demo pod two times", func(ctx context.Context) {
72+
runTestCase(ctx, fmw, "region", nlb3PodResource, "nlb3", "nlb0")
73+
runTestCase(ctx, fmw, "region", nlb0PodResource, "nlb0", "nlb3")
74+
})
75+
})
76+
77+
ginkgo.Context("When FPGA plugin is running in af mode", func() {
78+
ginkgo.BeforeEach(func(ctx context.Context) {
79+
runDevicePlugin(ctx, fmw, pluginKustomizationPath, mappingsCollectionPath, nlb0NodeResource, "af")
80+
})
81+
ginkgo.It("runs an opae-nlb-demo pod", func(ctx context.Context) {
82+
runTestCase(ctx, fmw, "af", nlb0PodResourceAF, "nlb0", "nlb3")
83+
})
7384
})
7485
}
7586

76-
func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizationPath, mappingsCollectionPath, pluginMode, nodeResource, podResource, cmd1, cmd2 string) {
87+
func runDevicePlugin(ctx context.Context, fmw *framework.Framework, pluginKustomizationPath, mappingsCollectionPath, nodeResource, pluginMode string) {
7788
tmpDir, err := os.MkdirTemp("", "fpgaplugine2etest-"+fmw.Namespace.Name)
7889
if err != nil {
7990
framework.Failf("unable to create temp directory: %v", err)
@@ -101,8 +112,10 @@ func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizat
101112
if err = utils.WaitForNodesWithResource(ctx, fmw.ClientSet, resource, 30*time.Second); err != nil {
102113
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
103114
}
115+
}
104116

105-
resource = v1.ResourceName(podResource)
117+
func runTestCase(ctx context.Context, fmw *framework.Framework, pluginMode, podResource, cmd1, cmd2 string) {
118+
resource := v1.ResourceName(podResource)
106119
image := "intel/opae-nlb-demo:devel"
107120

108121
ginkgo.By("submitting a pod requesting correct FPGA resources")
@@ -111,7 +124,7 @@ func runTestCase(ctx context.Context, fmw *framework.Framework, pluginKustomizat
111124

112125
ginkgo.By("waiting the pod to finish successfully")
113126

114-
err = e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, fmw.ClientSet, pod.ObjectMeta.Name, fmw.Namespace.Name, 60*time.Second)
127+
err := e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, fmw.ClientSet, pod.ObjectMeta.Name, fmw.Namespace.Name, 60*time.Second)
115128
gomega.Expect(err).To(gomega.BeNil(), utils.GetPodLogs(ctx, fmw, pod.ObjectMeta.Name, "testcontainer"))
116129

117130
ginkgo.By("submitting a pod requesting incorrect FPGA resources")

test/e2e/gpu/gpu.go

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func describe() {
5252
framework.Failf("unable to locate %q: %v", kustomizationYaml, errFailedToLocateRepoFile)
5353
}
5454

55-
ginkgo.It("checks availability of GPU resources", func(ctx context.Context) {
55+
ginkgo.BeforeEach(func(ctx context.Context) {
5656
ginkgo.By("deploying GPU plugin")
5757
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "apply", "-k", filepath.Dir(kustomizationPath))
5858

@@ -69,49 +69,54 @@ func describe() {
6969
if err = utils.TestPodsFileSystemInfo(podList.Items); err != nil {
7070
framework.Failf("container filesystem info checks failed: %v", err)
7171
}
72+
})
7273

73-
ginkgo.By("checking if the resource is allocatable")
74-
if err = utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second); err != nil {
75-
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
76-
}
77-
78-
ginkgo.By("submitting a pod requesting GPU resources")
79-
podSpec := &v1.Pod{
80-
ObjectMeta: metav1.ObjectMeta{Name: "gpuplugin-tester"},
81-
Spec: v1.PodSpec{
82-
Containers: []v1.Container{
83-
{
84-
Args: []string{"-c", "ls /dev/dri"},
85-
Name: containerName,
86-
Image: imageutils.GetE2EImage(imageutils.BusyBox),
87-
Command: []string{"/bin/sh"},
88-
Resources: v1.ResourceRequirements{
89-
Requests: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")},
90-
Limits: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")},
74+
ginkgo.Context("When GPU resources are available", func() {
75+
ginkgo.BeforeEach(func(ctx context.Context) {
76+
ginkgo.By("checking if the resource is allocatable")
77+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second); err != nil {
78+
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
79+
}
80+
})
81+
ginkgo.It("checks availability of GPU resources", func(ctx context.Context) {
82+
ginkgo.By("submitting a pod requesting GPU resources")
83+
podSpec := &v1.Pod{
84+
ObjectMeta: metav1.ObjectMeta{Name: "gpuplugin-tester"},
85+
Spec: v1.PodSpec{
86+
Containers: []v1.Container{
87+
{
88+
Args: []string{"-c", "ls /dev/dri"},
89+
Name: containerName,
90+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
91+
Command: []string{"/bin/sh"},
92+
Resources: v1.ResourceRequirements{
93+
Requests: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")},
94+
Limits: v1.ResourceList{"gpu.intel.com/i915": resource.MustParse("1")},
95+
},
9196
},
9297
},
98+
RestartPolicy: v1.RestartPolicyNever,
9399
},
94-
RestartPolicy: v1.RestartPolicyNever,
95-
},
96-
}
97-
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
98-
framework.ExpectNoError(err, "pod Create API error")
100+
}
101+
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, podSpec, metav1.CreateOptions{})
102+
framework.ExpectNoError(err, "pod Create API error")
99103

100-
ginkgo.By("waiting the pod to finish successfully")
101-
e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second)
104+
ginkgo.By("waiting the pod to finish successfully")
105+
e2epod.NewPodClient(f).WaitForSuccess(ctx, pod.ObjectMeta.Name, 60*time.Second)
102106

103-
ginkgo.By("checking log output")
104-
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, pod.Name, containerName)
107+
ginkgo.By("checking log output")
108+
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, pod.Name, containerName)
105109

106-
if err != nil {
107-
framework.Failf("unable to get log from pod: %v", err)
108-
}
110+
if err != nil {
111+
framework.Failf("unable to get log from pod: %v", err)
112+
}
109113

110-
if !strings.Contains(log, "card") || !strings.Contains(log, "renderD") {
111-
framework.Logf("log output: %s", log)
112-
framework.Failf("device mounts not found from log")
113-
}
114+
if !strings.Contains(log, "card") || !strings.Contains(log, "renderD") {
115+
framework.Logf("log output: %s", log)
116+
framework.Failf("device mounts not found from log")
117+
}
114118

115-
framework.Logf("found card and renderD from the log")
119+
framework.Logf("found card and renderD from the log")
120+
})
116121
})
117122
}

0 commit comments

Comments
 (0)