From 11627ae134b86a6845e393b0773d7d685f1f519b Mon Sep 17 00:00:00 2001 From: Michelle Au Date: Mon, 19 Nov 2018 15:09:27 -0800 Subject: [PATCH] Fix io test to use unique file names and cleanup all files --- test/e2e/storage/testsuites/volume_io.go | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/e2e/storage/testsuites/volume_io.go b/test/e2e/storage/testsuites/volume_io.go index 82cb0eaf4b0..8a09722510b 100644 --- a/test/e2e/storage/testsuites/volume_io.go +++ b/test/e2e/storage/testsuites/volume_io.go @@ -24,7 +24,7 @@ package testsuites import ( "fmt" "math" - "path" + "path/filepath" "strconv" "strings" "time" @@ -49,6 +49,8 @@ var md5hashes = map[int64]string{ testpatterns.FileSizeLarge: "8d763edc71bd16217664793b5a15e403", } +const mountPath = "/opt" + type volumeIOTestSuite struct { tsInfo TestSuiteInfo } @@ -176,10 +178,9 @@ func createFileSizes(maxFileSize int64) []int64 { } // Return the plugin's client pod spec. Use an InitContainer to setup the file i/o test env. -func makePodSpec(config framework.VolumeTestConfig, dir, initCmd string, volsrc v1.VolumeSource, podSecContext *v1.PodSecurityContext) *v1.Pod { - volName := fmt.Sprintf("%s-%s", config.Prefix, "io-volume") - +func makePodSpec(config framework.VolumeTestConfig, initCmd string, volsrc v1.VolumeSource, podSecContext *v1.PodSecurityContext) *v1.Pod { var gracePeriod int64 = 1 + volName := fmt.Sprintf("io-volume-%s", config.Namespace) return &v1.Pod{ TypeMeta: metav1.TypeMeta{ Kind: "Pod", @@ -204,7 +205,7 @@ func makePodSpec(config framework.VolumeTestConfig, dir, initCmd string, volsrc VolumeMounts: []v1.VolumeMount{ { Name: volName, - MountPath: dir, + MountPath: mountPath, }, }, }, @@ -221,7 +222,7 @@ func makePodSpec(config framework.VolumeTestConfig, dir, initCmd string, volsrc VolumeMounts: []v1.VolumeMount{ { Name: volName, - MountPath: dir, + MountPath: mountPath, }, }, }, @@ -302,8 +303,7 @@ func deleteFile(pod *v1.Pod, fpath string) { // Note: `fsizes` values are enforced to each be at least `MinFileSize` and a multiple of `MinFileSize` // bytes. func testVolumeIO(f *framework.Framework, cs clientset.Interface, config framework.VolumeTestConfig, volsrc v1.VolumeSource, podSecContext *v1.PodSecurityContext, file string, fsizes []int64) (err error) { - dir := path.Join("/opt", config.Prefix, config.Namespace) - ddInput := path.Join(dir, "dd_if") + ddInput := filepath.Join(mountPath, fmt.Sprintf("%s-%s-dd_if", config.Prefix, config.Namespace)) writeBlk := strings.Repeat("abcdefghijklmnopqrstuvwxyz123456", 32) // 1KiB value loopCnt := testpatterns.MinFileSize / int64(len(writeBlk)) // initContainer cmd to create and fill dd's input file. The initContainer is used to create @@ -311,7 +311,7 @@ func testVolumeIO(f *framework.Framework, cs clientset.Interface, config framewo // used to create a 1MiB file in the target directory. initCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do echo -n %s >>%s; let i+=1; done", loopCnt, writeBlk, ddInput) - clientPod := makePodSpec(config, dir, initCmd, volsrc, podSecContext) + clientPod := makePodSpec(config, initCmd, volsrc, podSecContext) By(fmt.Sprintf("starting %s", clientPod.Name)) podsNamespacer := cs.CoreV1().Pods(config.Namespace) @@ -320,7 +320,7 @@ func testVolumeIO(f *framework.Framework, cs clientset.Interface, config framewo return fmt.Errorf("failed to create client pod %q: %v", clientPod.Name, err) } defer func() { - // note the test dir will be removed when the kubelet unmounts it + deleteFile(clientPod, ddInput) By(fmt.Sprintf("deleting client pod %q...", clientPod.Name)) e := framework.DeletePodWithWait(f, cs, clientPod) if e != nil { @@ -345,14 +345,16 @@ func testVolumeIO(f *framework.Framework, cs clientset.Interface, config framewo if math.Mod(float64(fsize), float64(testpatterns.MinFileSize)) != 0 { fsize = fsize/testpatterns.MinFileSize + testpatterns.MinFileSize } - fpath := path.Join(dir, fmt.Sprintf("%s-%d", file, fsize)) + fpath := filepath.Join(mountPath, fmt.Sprintf("%s-%d", file, fsize)) + defer func() { + deleteFile(clientPod, fpath) + }() if err = writeToFile(clientPod, fpath, ddInput, fsize); err != nil { return err } if err = verifyFile(clientPod, fpath, fsize, ddInput); err != nil { return err } - deleteFile(clientPod, fpath) } return