Skip to content

Commit 2fac3f2

Browse files
committed
test/e2e: Reduce need to use local kubectl
Use POST method instead of running local kubectl. Use ExecCommandInContainerWithFullOutput() instead of RunKubectl(). PodExec() takes additional framework arg, passed down in call chain. VerifyExecInPodFail uses different error code cast as original one causes test code Panic if used with new call method.
1 parent 5dc87d2 commit 2fac3f2

File tree

11 files changed

+99
-97
lines changed

11 files changed

+99
-97
lines changed

test/e2e/common/volumes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var _ = ginkgo.Describe("[sig-storage] GCP Volumes", func() {
9191
}
9292

9393
// Must match content of test/images/volumes-tester/nfs/index.html
94-
volume.TestVolumeClient(c, config, nil, "" /* fsType */, tests)
94+
volume.TestVolumeClient(f, c, config, nil, "" /* fsType */, tests)
9595
})
9696
})
9797

@@ -114,7 +114,7 @@ var _ = ginkgo.Describe("[sig-storage] GCP Volumes", func() {
114114
},
115115
}
116116
// Must match content of test/images/volume-tester/nfs/index.html
117-
volume.TestVolumeClient(c, config, nil, "" /* fsType */, tests)
117+
volume.TestVolumeClient(f, c, config, nil, "" /* fsType */, tests)
118118
})
119119
})
120120

@@ -147,7 +147,7 @@ var _ = ginkgo.Describe("[sig-storage] GCP Volumes", func() {
147147
ExpectedContent: "Hello from GlusterFS!",
148148
},
149149
}
150-
volume.TestVolumeClient(c, config, nil, "" /* fsType */, tests)
150+
volume.TestVolumeClient(f, c, config, nil, "" /* fsType */, tests)
151151
})
152152
})
153153
})

test/e2e/framework/volume/fixtures.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ func runVolumeTesterPod(client clientset.Interface, config TestConfig, podSuffix
528528
return clientPod, nil
529529
}
530530

531-
func testVolumeContent(client clientset.Interface, pod *v1.Pod, fsGroup *int64, fsType string, tests []Test) {
531+
func testVolumeContent(f *framework.Framework, client clientset.Interface, pod *v1.Pod, fsGroup *int64, fsType string, tests []Test) {
532532
ginkgo.By("Checking that text file contents are perfect.")
533533
for i, test := range tests {
534534
if test.Mode == v1.PersistentVolumeBlock {
@@ -539,7 +539,7 @@ func testVolumeContent(client clientset.Interface, pod *v1.Pod, fsGroup *int64,
539539
framework.ExpectNoError(err, "failed: finding the contents of the block device %s.", deviceName)
540540

541541
// Check that it's a real block device
542-
utils.CheckVolumeModeOfPath(pod, test.Mode, deviceName)
542+
utils.CheckVolumeModeOfPath(f, pod, test.Mode, deviceName)
543543
} else {
544544
// Filesystem: check content
545545
fileName := fmt.Sprintf("/opt/%d/%s", i, test.File)
@@ -549,7 +549,7 @@ func testVolumeContent(client clientset.Interface, pod *v1.Pod, fsGroup *int64,
549549

550550
// Check that a directory has been mounted
551551
dirName := filepath.Dir(fileName)
552-
utils.CheckVolumeModeOfPath(pod, test.Mode, dirName)
552+
utils.CheckVolumeModeOfPath(f, pod, test.Mode, dirName)
553553

554554
if !framework.NodeOSDistroIs("windows") {
555555
// Filesystem: check fsgroup
@@ -574,20 +574,20 @@ func testVolumeContent(client clientset.Interface, pod *v1.Pod, fsGroup *int64,
574574
// and check that the pod sees expected data, e.g. from the server pod.
575575
// Multiple Tests can be specified to mount multiple volumes to a single
576576
// pod.
577-
func TestVolumeClient(client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
577+
func TestVolumeClient(f *framework.Framework, client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
578578
clientPod, err := runVolumeTesterPod(client, config, "client", false, fsGroup, tests)
579579
if err != nil {
580580
framework.Failf("Failed to create client pod: %v", err)
581581

582582
}
583583
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespace(client, clientPod))
584-
testVolumeContent(client, clientPod, fsGroup, fsType, tests)
584+
testVolumeContent(f, client, clientPod, fsGroup, fsType, tests)
585585
}
586586

587587
// InjectContent inserts index.html with given content into given volume. It does so by
588588
// starting and auxiliary pod which writes the file there.
589589
// The volume must be writable.
590-
func InjectContent(client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
590+
func InjectContent(f *framework.Framework, client clientset.Interface, config TestConfig, fsGroup *int64, fsType string, tests []Test) {
591591
privileged := true
592592
if framework.NodeOSDistroIs("windows") {
593593
privileged = false
@@ -621,7 +621,7 @@ func InjectContent(client clientset.Interface, config TestConfig, fsGroup *int64
621621

622622
// Check that the data have been really written in this pod.
623623
// This tests non-persistent volume types
624-
testVolumeContent(client, injectorPod, fsGroup, fsType, tests)
624+
testVolumeContent(f, client, injectorPod, fsGroup, fsType, tests)
625625
}
626626

627627
// CreateGCEVolume creates PersistentVolumeSource for GCEVolume.

test/e2e/storage/flexvolume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func testFlexVolume(driver string, cs clientset.Interface, config volume.TestCon
6262
ExpectedContent: "Hello from flexvolume!",
6363
},
6464
}
65-
volume.TestVolumeClient(cs, config, nil, "" /* fsType */, tests)
65+
volume.TestVolumeClient(f, cs, config, nil, "" /* fsType */, tests)
6666

6767
volume.TestCleanup(f, config)
6868
}

test/e2e/storage/persistent_volumes-local.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ var _ = utils.SIGDescribe("PersistentVolumes-local ", func() {
215215
writeCmd := createWriteCmd(volumeDir, testFile, testFileContent, testVol.localVolumeType)
216216

217217
ginkgo.By("Writing in pod1")
218-
podRWCmdExec(pod1, writeCmd)
218+
podRWCmdExec(f, pod1, writeCmd)
219219
})
220220

221221
ginkgo.AfterEach(func() {
@@ -226,28 +226,28 @@ var _ = utils.SIGDescribe("PersistentVolumes-local ", func() {
226226
ginkgo.It("should be able to mount volume and read from pod1", func() {
227227
ginkgo.By("Reading in pod1")
228228
// testFileContent was written in BeforeEach
229-
testReadFileContent(volumeDir, testFile, testFileContent, pod1, testVolType)
229+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod1, testVolType)
230230
})
231231

232232
ginkgo.It("should be able to mount volume and write from pod1", func() {
233233
// testFileContent was written in BeforeEach
234-
testReadFileContent(volumeDir, testFile, testFileContent, pod1, testVolType)
234+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod1, testVolType)
235235

236236
ginkgo.By("Writing in pod1")
237237
writeCmd := createWriteCmd(volumeDir, testFile, testVol.ltr.Path /*writeTestFileContent*/, testVolType)
238-
podRWCmdExec(pod1, writeCmd)
238+
podRWCmdExec(f, pod1, writeCmd)
239239
})
240240
})
241241

242242
ginkgo.Context("Two pods mounting a local volume at the same time", func() {
243243
ginkgo.It("should be able to write from pod1 and read from pod2", func() {
244-
twoPodsReadWriteTest(config, testVol)
244+
twoPodsReadWriteTest(f, config, testVol)
245245
})
246246
})
247247

248248
ginkgo.Context("Two pods mounting a local volume one after the other", func() {
249249
ginkgo.It("should be able to write from pod1 and read from pod2", func() {
250-
twoPodsReadWriteSerialTest(config, testVol)
250+
twoPodsReadWriteSerialTest(f, config, testVol)
251251
})
252252
})
253253

@@ -703,7 +703,7 @@ func testPodWithNodeConflict(config *localTestConfig, testVolType localVolumeTyp
703703
// The tests below are run against multiple mount point types
704704

705705
// Test two pods at the same time, write from pod1, and read from pod2
706-
func twoPodsReadWriteTest(config *localTestConfig, testVol *localTestVolume) {
706+
func twoPodsReadWriteTest(f *framework.Framework, config *localTestConfig, testVol *localTestVolume) {
707707
ginkgo.By("Creating pod1 to write to the PV")
708708
pod1, pod1Err := createLocalPod(config, testVol, nil)
709709
framework.ExpectNoError(pod1Err)
@@ -712,26 +712,26 @@ func twoPodsReadWriteTest(config *localTestConfig, testVol *localTestVolume) {
712712
writeCmd := createWriteCmd(volumeDir, testFile, testFileContent, testVol.localVolumeType)
713713

714714
ginkgo.By("Writing in pod1")
715-
podRWCmdExec(pod1, writeCmd)
715+
podRWCmdExec(f, pod1, writeCmd)
716716

717717
// testFileContent was written after creating pod1
718-
testReadFileContent(volumeDir, testFile, testFileContent, pod1, testVol.localVolumeType)
718+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod1, testVol.localVolumeType)
719719

720720
ginkgo.By("Creating pod2 to read from the PV")
721721
pod2, pod2Err := createLocalPod(config, testVol, nil)
722722
framework.ExpectNoError(pod2Err)
723723
verifyLocalPod(config, testVol, pod2, config.node0.Name)
724724

725725
// testFileContent was written after creating pod1
726-
testReadFileContent(volumeDir, testFile, testFileContent, pod2, testVol.localVolumeType)
726+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod2, testVol.localVolumeType)
727727

728728
writeCmd = createWriteCmd(volumeDir, testFile, testVol.ltr.Path /*writeTestFileContent*/, testVol.localVolumeType)
729729

730730
ginkgo.By("Writing in pod2")
731-
podRWCmdExec(pod2, writeCmd)
731+
podRWCmdExec(f, pod2, writeCmd)
732732

733733
ginkgo.By("Reading in pod1")
734-
testReadFileContent(volumeDir, testFile, testVol.ltr.Path, pod1, testVol.localVolumeType)
734+
testReadFileContent(f, volumeDir, testFile, testVol.ltr.Path, pod1, testVol.localVolumeType)
735735

736736
ginkgo.By("Deleting pod1")
737737
e2epod.DeletePodOrFail(config.client, config.ns, pod1.Name)
@@ -740,7 +740,7 @@ func twoPodsReadWriteTest(config *localTestConfig, testVol *localTestVolume) {
740740
}
741741

742742
// Test two pods one after other, write from pod1, and read from pod2
743-
func twoPodsReadWriteSerialTest(config *localTestConfig, testVol *localTestVolume) {
743+
func twoPodsReadWriteSerialTest(f *framework.Framework, config *localTestConfig, testVol *localTestVolume) {
744744
ginkgo.By("Creating pod1")
745745
pod1, pod1Err := createLocalPod(config, testVol, nil)
746746
framework.ExpectNoError(pod1Err)
@@ -749,10 +749,10 @@ func twoPodsReadWriteSerialTest(config *localTestConfig, testVol *localTestVolum
749749
writeCmd := createWriteCmd(volumeDir, testFile, testFileContent, testVol.localVolumeType)
750750

751751
ginkgo.By("Writing in pod1")
752-
podRWCmdExec(pod1, writeCmd)
752+
podRWCmdExec(f, pod1, writeCmd)
753753

754754
// testFileContent was written after creating pod1
755-
testReadFileContent(volumeDir, testFile, testFileContent, pod1, testVol.localVolumeType)
755+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod1, testVol.localVolumeType)
756756

757757
ginkgo.By("Deleting pod1")
758758
e2epod.DeletePodOrFail(config.client, config.ns, pod1.Name)
@@ -763,7 +763,7 @@ func twoPodsReadWriteSerialTest(config *localTestConfig, testVol *localTestVolum
763763
verifyLocalPod(config, testVol, pod2, config.node0.Name)
764764

765765
ginkgo.By("Reading in pod2")
766-
testReadFileContent(volumeDir, testFile, testFileContent, pod2, testVol.localVolumeType)
766+
testReadFileContent(f, volumeDir, testFile, testFileContent, pod2, testVol.localVolumeType)
767767

768768
ginkgo.By("Deleting pod2")
769769
e2epod.DeletePodOrFail(config.client, config.ns, pod2.Name)
@@ -1015,16 +1015,16 @@ func createReadCmd(testFileDir string, testFile string, volumeType localVolumeTy
10151015
}
10161016

10171017
// Read testFile and evaluate whether it contains the testFileContent
1018-
func testReadFileContent(testFileDir string, testFile string, testFileContent string, pod *v1.Pod, volumeType localVolumeType) {
1018+
func testReadFileContent(f *framework.Framework, testFileDir string, testFile string, testFileContent string, pod *v1.Pod, volumeType localVolumeType) {
10191019
readCmd := createReadCmd(testFileDir, testFile, volumeType)
1020-
readOut := podRWCmdExec(pod, readCmd)
1020+
readOut := podRWCmdExec(f, pod, readCmd)
10211021
gomega.Expect(readOut).To(gomega.ContainSubstring(testFileContent))
10221022
}
10231023

10241024
// Execute a read or write command in a pod.
10251025
// Fail on error
1026-
func podRWCmdExec(pod *v1.Pod, cmd string) string {
1027-
out, err := utils.PodExec(pod, cmd)
1026+
func podRWCmdExec(f *framework.Framework, pod *v1.Pod, cmd string) string {
1027+
out, err := utils.PodExec(f, pod, cmd)
10281028
framework.Logf("podRWCmdExec out: %q err: %v", out, err)
10291029
framework.ExpectNoError(err)
10301030
return out

test/e2e/storage/testsuites/ephemeral.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (p *ephemeralTestSuite) defineTests(driver TestDriver, pattern testpatterns
118118

119119
l.testCase.ReadOnly = true
120120
l.testCase.RunningPodCheck = func(pod *v1.Pod) interface{} {
121-
storageutils.VerifyExecInPodSucceed(pod, "mount | grep /mnt/test | grep ro,")
121+
storageutils.VerifyExecInPodSucceed(f, pod, "mount | grep /mnt/test | grep ro,")
122122
return nil
123123
}
124124
l.testCase.TestEphemeral()
@@ -130,7 +130,7 @@ func (p *ephemeralTestSuite) defineTests(driver TestDriver, pattern testpatterns
130130

131131
l.testCase.ReadOnly = false
132132
l.testCase.RunningPodCheck = func(pod *v1.Pod) interface{} {
133-
storageutils.VerifyExecInPodSucceed(pod, "mount | grep /mnt/test | grep rw,")
133+
storageutils.VerifyExecInPodSucceed(f, pod, "mount | grep /mnt/test | grep rw,")
134134
return nil
135135
}
136136
l.testCase.TestEphemeral()
@@ -159,8 +159,8 @@ func (p *ephemeralTestSuite) defineTests(driver TestDriver, pattern testpatterns
159159
// visible in the other.
160160
if !readOnly && !shared {
161161
ginkgo.By("writing data in one pod and checking for it in the second")
162-
storageutils.VerifyExecInPodSucceed(pod, "touch /mnt/test-0/hello-world")
163-
storageutils.VerifyExecInPodSucceed(pod2, "[ ! -f /mnt/test-0/hello-world ]")
162+
storageutils.VerifyExecInPodSucceed(f, pod, "touch /mnt/test-0/hello-world")
163+
storageutils.VerifyExecInPodSucceed(f, pod2, "[ ! -f /mnt/test-0/hello-world ]")
164164
}
165165

166166
defer StopPod(f.ClientSet, pod2)

test/e2e/storage/testsuites/multivolume.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,18 @@ func testAccessMultipleVolumes(f *framework.Framework, cs clientset.Interface, n
365365
index := i + 1
366366
path := fmt.Sprintf("/mnt/volume%d", index)
367367
ginkgo.By(fmt.Sprintf("Checking if the volume%d exists as expected volume mode (%s)", index, *pvc.Spec.VolumeMode))
368-
utils.CheckVolumeModeOfPath(pod, *pvc.Spec.VolumeMode, path)
368+
utils.CheckVolumeModeOfPath(f, pod, *pvc.Spec.VolumeMode, path)
369369

370370
if readSeedBase > 0 {
371371
ginkgo.By(fmt.Sprintf("Checking if read from the volume%d works properly", index))
372-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, readSeedBase+int64(i))
372+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, readSeedBase+int64(i))
373373
}
374374

375375
ginkgo.By(fmt.Sprintf("Checking if write to the volume%d works properly", index))
376-
utils.CheckWriteToPath(pod, *pvc.Spec.VolumeMode, path, byteLen, writeSeedBase+int64(i))
376+
utils.CheckWriteToPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, writeSeedBase+int64(i))
377377

378378
ginkgo.By(fmt.Sprintf("Checking if read from the volume%d works properly", index))
379-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, writeSeedBase+int64(i))
379+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, writeSeedBase+int64(i))
380380
}
381381

382382
pod, err = cs.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
@@ -452,22 +452,22 @@ func TestConcurrentAccessToSingleVolume(f *framework.Framework, cs clientset.Int
452452
for i, pod := range pods {
453453
index := i + 1
454454
ginkgo.By(fmt.Sprintf("Checking if the volume in pod%d exists as expected volume mode (%s)", index, *pvc.Spec.VolumeMode))
455-
utils.CheckVolumeModeOfPath(pod, *pvc.Spec.VolumeMode, path)
455+
utils.CheckVolumeModeOfPath(f, pod, *pvc.Spec.VolumeMode, path)
456456

457457
if i != 0 {
458458
ginkgo.By(fmt.Sprintf("From pod%d, checking if reading the data that pod%d write works properly", index, index-1))
459459
// For 1st pod, no one has written data yet, so pass the read check
460-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
460+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
461461
}
462462

463463
// Update the seed and check if write/read works properly
464464
seed = time.Now().UTC().UnixNano()
465465

466466
ginkgo.By(fmt.Sprintf("Checking if write to the volume in pod%d works properly", index))
467-
utils.CheckWriteToPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
467+
utils.CheckWriteToPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
468468

469469
ginkgo.By(fmt.Sprintf("Checking if read from the volume in pod%d works properly", index))
470-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
470+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
471471
}
472472

473473
// Delete the last pod and remove from slice of pods
@@ -483,23 +483,23 @@ func TestConcurrentAccessToSingleVolume(f *framework.Framework, cs clientset.Int
483483
index := i + 1
484484
// index of pod and index of pvc match, because pods are created above way
485485
ginkgo.By(fmt.Sprintf("Rechecking if the volume in pod%d exists as expected volume mode (%s)", index, *pvc.Spec.VolumeMode))
486-
utils.CheckVolumeModeOfPath(pod, *pvc.Spec.VolumeMode, "/mnt/volume1")
486+
utils.CheckVolumeModeOfPath(f, pod, *pvc.Spec.VolumeMode, "/mnt/volume1")
487487

488488
if i == 0 {
489489
// This time there should be data that last pod wrote, for 1st pod
490490
ginkgo.By(fmt.Sprintf("From pod%d, rechecking if reading the data that last pod write works properly", index))
491491
} else {
492492
ginkgo.By(fmt.Sprintf("From pod%d, rechecking if reading the data that pod%d write works properly", index, index-1))
493493
}
494-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
494+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
495495

496496
// Update the seed and check if write/read works properly
497497
seed = time.Now().UTC().UnixNano()
498498

499499
ginkgo.By(fmt.Sprintf("Rechecking if write to the volume in pod%d works properly", index))
500-
utils.CheckWriteToPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
500+
utils.CheckWriteToPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
501501

502502
ginkgo.By(fmt.Sprintf("Rechecking if read from the volume in pod%d works properly", index))
503-
utils.CheckReadFromPath(pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
503+
utils.CheckReadFromPath(f, pod, *pvc.Spec.VolumeMode, path, byteLen, seed)
504504
}
505505
}

0 commit comments

Comments
 (0)