Skip to content

Commit 4a68302

Browse files
committed
test: add context in e2e tests
fix fix
1 parent 9c413c0 commit 4a68302

12 files changed

+193
-182
lines changed

test/e2e/dynamic_provisioning_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
admissionapi "k8s.io/pod-security-admission/api"
3131
)
3232

33-
var _ = ginkgo.Describe("Dynamic Provisioning", func() {
33+
var _ = ginkgo.Describe("Dynamic Provisioning", func(ctx ginkgo.SpecContext) {
3434
f := framework.NewDefaultFramework("smb")
3535
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
3636

@@ -40,7 +40,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
4040
testDriver driver.PVTestDriver
4141
)
4242

43-
ginkgo.BeforeEach(func() {
43+
ginkgo.BeforeEach(func(ctx ginkgo.SpecContext) {
4444
checkPodsRestart := testCmd{
4545
command: "sh",
4646
args: []string{"test/utils/check_driver_pods_restart.sh"},
@@ -54,7 +54,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
5454
})
5555

5656
testDriver = driver.InitSMBDriver()
57-
ginkgo.It("should create a volume after driver restart [smb.csi.k8s.io]", func() {
57+
ginkgo.It("should create a volume after driver restart [smb.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
5858
ginkgo.Skip("test case is disabled since node logs would be lost after driver restart")
5959
pod := testsuites.PodDetails{
6060
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done"),
@@ -94,10 +94,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
9494
execTestCmd([]testCmd{restartDriver})
9595
},
9696
}
97-
test.Run(cs, ns)
97+
test.Run(ctx, cs, ns)
9898
})
9999

100-
ginkgo.It("should create a volume on demand with mount options [smb.csi.k8s.io] [Windows]", func() {
100+
ginkgo.It("should create a volume on demand with mount options [smb.csi.k8s.io] [Windows]", func(ctx ginkgo.SpecContext) {
101101
pods := []testsuites.PodDetails{
102102
{
103103
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
@@ -128,10 +128,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
128128
StorageClassParameters: defaultStorageClassParameters,
129129
}
130130

131-
test.Run(cs, ns)
131+
test.Run(ctx, cs, ns)
132132
})
133133

134-
ginkgo.It("should create multiple PV objects, bind to PVCs and attach all to different pods on the same node [smb.csi.k8s.io] [Windows]", func() {
134+
ginkgo.It("should create multiple PV objects, bind to PVCs and attach all to different pods on the same node [smb.csi.k8s.io] [Windows]", func(ctx ginkgo.SpecContext) {
135135
pods := []testsuites.PodDetails{
136136
{
137137
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 100; done"),
@@ -166,11 +166,11 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
166166
ColocatePods: true,
167167
StorageClassParameters: defaultStorageClassParameters,
168168
}
169-
test.Run(cs, ns)
169+
test.Run(ctx, cs, ns)
170170
})
171171

172172
// Track issue https://github.com/kubernetes/kubernetes/issues/70505
173-
ginkgo.It("should create a volume on demand and mount it as readOnly in a pod [smb.csi.k8s.io]", func() {
173+
ginkgo.It("should create a volume on demand and mount it as readOnly in a pod [smb.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
174174
// Windows volume does not support readOnly
175175
skipIfTestingInWindowsCluster()
176176
pods := []testsuites.PodDetails{
@@ -194,10 +194,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
194194
Pods: pods,
195195
StorageClassParameters: defaultStorageClassParameters,
196196
}
197-
test.Run(cs, ns)
197+
test.Run(ctx, cs, ns)
198198
})
199199

200-
ginkgo.It("should create a deployment object, write and read to it, delete the pod and write and read to it again [smb.csi.k8s.io] [Windows]", func() {
200+
ginkgo.It("should create a deployment object, write and read to it, delete the pod and write and read to it again [smb.csi.k8s.io] [Windows]", func(ctx ginkgo.SpecContext) {
201201
pod := testsuites.PodDetails{
202202
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' >> /mnt/test-1/data && while true; do sleep 100; done"),
203203
Volumes: []testsuites.VolumeDetails{
@@ -227,10 +227,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
227227
},
228228
StorageClassParameters: defaultStorageClassParameters,
229229
}
230-
test.Run(cs, ns)
230+
test.Run(ctx, cs, ns)
231231
})
232232

233-
ginkgo.It(fmt.Sprintf("should delete PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimDelete), func() {
233+
ginkgo.It(fmt.Sprintf("should delete PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimDelete), func(ctx ginkgo.SpecContext) {
234234
reclaimPolicy := v1.PersistentVolumeReclaimDelete
235235
volumes := []testsuites.VolumeDetails{
236236
{
@@ -243,10 +243,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
243243
Volumes: volumes,
244244
StorageClassParameters: defaultStorageClassParameters,
245245
}
246-
test.Run(cs, ns)
246+
test.Run(ctx, cs, ns)
247247
})
248248

249-
ginkgo.It(fmt.Sprintf("should retain PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimRetain), func() {
249+
ginkgo.It(fmt.Sprintf("should retain PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimRetain), func(ctx ginkgo.SpecContext) {
250250
reclaimPolicy := v1.PersistentVolumeReclaimRetain
251251
volumes := []testsuites.VolumeDetails{
252252
{
@@ -260,10 +260,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
260260
Driver: smbDriver,
261261
StorageClassParameters: defaultStorageClassParameters,
262262
}
263-
test.Run(cs, ns)
263+
test.Run(ctx, cs, ns)
264264
})
265265

266-
ginkgo.It("should create a pod with multiple volumes [smb.csi.k8s.io] [Windows]", func() {
266+
ginkgo.It("should create a pod with multiple volumes [smb.csi.k8s.io] [Windows]", func(ctx ginkgo.SpecContext) {
267267
volumes := []testsuites.VolumeDetails{}
268268
for i := 1; i <= 6; i++ {
269269
volume := testsuites.VolumeDetails{
@@ -288,10 +288,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
288288
Pods: pods,
289289
StorageClassParameters: subDirStorageClassParameters,
290290
}
291-
test.Run(cs, ns)
291+
test.Run(ctx, cs, ns)
292292
})
293293

294-
ginkgo.It("should create a pod with volume mount subpath [smb.csi.k8s.io] [Windows]", func() {
294+
ginkgo.It("should create a pod with volume mount subpath [smb.csi.k8s.io] [Windows]", func(ctx ginkgo.SpecContext) {
295295
pods := []testsuites.PodDetails{
296296
{
297297
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
@@ -312,10 +312,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
312312
Pods: pods,
313313
StorageClassParameters: noProvisionerSecretStorageClassParameters,
314314
}
315-
test.Run(cs, ns)
315+
test.Run(ctx, cs, ns)
316316
})
317317

318-
ginkgo.It("should clone a volume from an existing volume [smb.csi.k8s.io]", func() {
318+
ginkgo.It("should clone a volume from an existing volume [smb.csi.k8s.io]", func(ctx ginkgo.SpecContext) {
319319
skipIfTestingInWindowsCluster()
320320

321321
pod := testsuites.PodDetails{
@@ -348,6 +348,6 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
348348
PodWithClonedVolume: podWithClonedVolume,
349349
StorageClassParameters: defaultStorageClassParameters,
350350
}
351-
test.Run(cs, ns)
351+
test.Run(ctx, cs, ns)
352352
})
353353
})

test/e2e/testsuites/dynamically_provisioned_cmd_volume_tester.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
2122

2223
"github.com/onsi/ginkgo/v2"
@@ -33,18 +34,18 @@ type DynamicallyProvisionedCmdVolumeTest struct {
3334
StorageClassParameters map[string]string
3435
}
3536

36-
func (t *DynamicallyProvisionedCmdVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
37+
func (t *DynamicallyProvisionedCmdVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
3738
for _, pod := range t.Pods {
38-
tpod, cleanup := pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
39+
tpod, cleanup := pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
3940
// defer must be called here for resources not get removed before using them
4041
for i := range cleanup {
41-
defer cleanup[i]()
42+
defer cleanup[i](ctx)
4243
}
4344

4445
ginkgo.By("deploying the pod")
45-
tpod.Create()
46-
defer tpod.Cleanup()
46+
tpod.Create(ctx)
47+
defer tpod.Cleanup(ctx)
4748
ginkgo.By("checking that the pods command exits with no error")
48-
tpod.WaitForSuccess()
49+
tpod.WaitForSuccess(ctx)
4950
}
5051
}

test/e2e/testsuites/dynamically_provisioned_collocated_pod_tester.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
2122

2223
"github.com/onsi/ginkgo/v2"
@@ -34,24 +35,24 @@ type DynamicallyProvisionedCollocatedPodTest struct {
3435
StorageClassParameters map[string]string
3536
}
3637

37-
func (t *DynamicallyProvisionedCollocatedPodTest) Run(client clientset.Interface, namespace *v1.Namespace) {
38+
func (t *DynamicallyProvisionedCollocatedPodTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
3839
nodeName := ""
3940
for _, pod := range t.Pods {
40-
tpod, cleanup := pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
41+
tpod, cleanup := pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
4142
if t.ColocatePods && nodeName != "" {
4243
tpod.SetNodeSelector(map[string]string{"name": nodeName})
4344
}
4445
// defer must be called here for resources not get removed before using them
4546
for i := range cleanup {
46-
defer cleanup[i]()
47+
defer cleanup[i](ctx)
4748
}
4849

4950
ginkgo.By("deploying the pod")
50-
tpod.Create()
51-
defer tpod.Cleanup()
51+
tpod.Create(ctx)
52+
defer tpod.Cleanup(ctx)
5253

5354
ginkgo.By("checking that the pod is running")
54-
tpod.WaitForRunning()
55+
tpod.WaitForRunning(ctx)
5556
nodeName = tpod.pod.Spec.NodeName
5657
}
5758

test/e2e/testsuites/dynamically_provisioned_delete_pod_tester.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"time"
2122

2223
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
@@ -41,18 +42,18 @@ type PodExecCheck struct {
4142
ExpectedString string
4243
}
4344

44-
func (t *DynamicallyProvisionedDeletePodTest) Run(client clientset.Interface, namespace *v1.Namespace) {
45-
tDeployment, cleanup := t.Pod.SetupDeployment(client, namespace, t.CSIDriver, t.StorageClassParameters)
45+
func (t *DynamicallyProvisionedDeletePodTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
46+
tDeployment, cleanup := t.Pod.SetupDeployment(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
4647
// defer must be called here for resources not get removed before using them
4748
for i := range cleanup {
48-
defer cleanup[i]()
49+
defer cleanup[i](ctx)
4950
}
5051

5152
ginkgo.By("deploying the deployment")
52-
tDeployment.Create()
53+
tDeployment.Create(ctx)
5354

5455
ginkgo.By("checking that the pod is running")
55-
tDeployment.WaitForPodReady()
56+
tDeployment.WaitForPodReady(ctx)
5657

5758
if t.PodCheck != nil {
5859
ginkgo.By("sleep 5s and then check pod exec")
@@ -61,10 +62,10 @@ func (t *DynamicallyProvisionedDeletePodTest) Run(client clientset.Interface, na
6162
}
6263

6364
ginkgo.By("deleting the pod for deployment")
64-
tDeployment.DeletePodAndWait()
65+
tDeployment.DeletePodAndWait(ctx)
6566

6667
ginkgo.By("checking again that the pod is running")
67-
tDeployment.WaitForPodReady()
68+
tDeployment.WaitForPodReady(ctx)
6869

6970
if t.PodCheck != nil {
7071
ginkgo.By("sleep 5s and then check pod exec after pod restart again")

test/e2e/testsuites/dynamically_provisioned_pod_with_multiple_pv.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
2122

2223
"github.com/onsi/ginkgo/v2"
@@ -34,18 +35,18 @@ type DynamicallyProvisionedPodWithMultiplePVsTest struct {
3435
StorageClassParameters map[string]string
3536
}
3637

37-
func (t *DynamicallyProvisionedPodWithMultiplePVsTest) Run(client clientset.Interface, namespace *v1.Namespace) {
38+
func (t *DynamicallyProvisionedPodWithMultiplePVsTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
3839
for _, pod := range t.Pods {
39-
tpod, cleanup := pod.SetupWithDynamicMultipleVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
40+
tpod, cleanup := pod.SetupWithDynamicMultipleVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
4041
// defer must be called here for resources not get removed before using them
4142
for i := range cleanup {
42-
defer cleanup[i]()
43+
defer cleanup[i](ctx)
4344
}
4445

4546
ginkgo.By("deploying the pod")
46-
tpod.Create()
47-
defer tpod.Cleanup()
47+
tpod.Create(ctx)
48+
defer tpod.Cleanup(ctx)
4849
ginkgo.By("checking that the pods command exits with no error")
49-
tpod.WaitForSuccess()
50+
tpod.WaitForSuccess(ctx)
5051
}
5152
}

test/e2e/testsuites/dynamically_provisioned_read_only_volume_tester.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
@@ -37,26 +38,26 @@ type DynamicallyProvisionedReadOnlyVolumeTest struct {
3738
StorageClassParameters map[string]string
3839
}
3940

40-
func (t *DynamicallyProvisionedReadOnlyVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
41+
func (t *DynamicallyProvisionedReadOnlyVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
4142
for _, pod := range t.Pods {
4243
expectedReadOnlyLog := "Read-only file system"
4344
if pod.IsWindows {
4445
expectedReadOnlyLog = "FileOpenFailure"
4546
}
4647

47-
tpod, cleanup := pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
48+
tpod, cleanup := pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
4849
// defer must be called here for resources not get removed before using them
4950
for i := range cleanup {
50-
defer cleanup[i]()
51+
defer cleanup[i](ctx)
5152
}
5253

5354
ginkgo.By("deploying the pod")
54-
tpod.Create()
55-
defer tpod.Cleanup()
55+
tpod.Create(ctx)
56+
defer tpod.Cleanup(ctx)
5657
ginkgo.By("checking that the pods command exits with an error")
57-
tpod.WaitForFailure()
58+
tpod.WaitForFailure(ctx)
5859
ginkgo.By("checking that pod logs contain expected message")
59-
body, err := tpod.Logs()
60+
body, err := tpod.Logs(ctx)
6061
framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err))
6162
gomega.Expect(string(body)).To(gomega.ContainSubstring(expectedReadOnlyLog))
6263
}

test/e2e/testsuites/dynamically_provisioned_reclaim_policy_tester.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package testsuites
1818

1919
import (
20+
"context"
2021
"github.com/kubernetes-csi/csi-driver-smb/pkg/smb"
2122
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
2223

@@ -33,18 +34,18 @@ type DynamicallyProvisionedReclaimPolicyTest struct {
3334
StorageClassParameters map[string]string
3435
}
3536

36-
func (t *DynamicallyProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) {
37+
func (t *DynamicallyProvisionedReclaimPolicyTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
3738
for _, volume := range t.Volumes {
38-
tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver, t.StorageClassParameters)
39+
tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
3940

4041
// will delete the PVC
4142
// will also wait for PV to be deleted when reclaimPolicy=Delete
42-
tpvc.Cleanup()
43+
tpvc.Cleanup(ctx)
4344
// first check PV stills exists, then manually delete it
4445
if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain {
45-
tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased)
46-
tpvc.DeleteBoundPersistentVolume()
47-
tpvc.DeleteBackingVolume(t.Driver)
46+
tpvc.WaitForPersistentVolumePhase(ctx, v1.VolumeReleased)
47+
tpvc.DeleteBoundPersistentVolume(ctx)
48+
tpvc.DeleteBackingVolume(ctx, t.Driver)
4849
}
4950
}
5051
}

0 commit comments

Comments
 (0)