From 330fcdf05591f9cf5719538c33d59479c89d99bb Mon Sep 17 00:00:00 2001 From: Drew Sirenko <68304519+AndrewSirenko@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:35:45 -0800 Subject: [PATCH] Refactor E2E: Generalize format_options CreateVolumeDetails helper fcn. --- tests/e2e/format_options.go | 77 ++++++++++--------- tests/e2e/testsuites/e2e_utils.go | 17 ++++ tests/e2e/testsuites/format_options_tester.go | 31 +------- 3 files changed, 61 insertions(+), 64 deletions(-) diff --git a/tests/e2e/format_options.go b/tests/e2e/format_options.go index f42f088c2..4ae170d96 100644 --- a/tests/e2e/format_options.go +++ b/tests/e2e/format_options.go @@ -28,40 +28,6 @@ import ( var ( testedFsTypes = []string{ebscsidriver.FSTypeExt4} - - formatOptionTests = map[string]testsuites.FormatOptionTest{ - ebscsidriver.BlockSizeKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.BlockSizeKey: "1024", - }, - }, - ebscsidriver.InodeSizeKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.InodeSizeKey: "512", - }, - }, - ebscsidriver.BytesPerInodeKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.BytesPerInodeKey: "8192", - }, - }, - ebscsidriver.NumberOfInodesKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.NumberOfInodesKey: "200192", - }, - }, - ebscsidriver.Ext4BigAllocKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.Ext4BigAllocKey: "true", - }, - }, - ebscsidriver.Ext4ClusterSizeKey: { - CreateVolumeParameters: map[string]string{ - ebscsidriver.Ext4BigAllocKey: "true", - ebscsidriver.Ext4ClusterSizeKey: "16384", - }, - }, - } ) var _ = Describe("[ebs-csi-e2e] [single-az] [format-options] Formatting a volume", func() { @@ -81,6 +47,47 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [format-options] Formatting a volume }) for _, fsType := range testedFsTypes { + + formatOptionTests := map[string]testsuites.FormatOptionTest{ + ebscsidriver.BlockSizeKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.BlockSizeKey: "1024", + ebscsidriver.FSTypeKey: fsType, + }, + }, + ebscsidriver.InodeSizeKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.InodeSizeKey: "512", + ebscsidriver.FSTypeKey: fsType, + }, + }, + ebscsidriver.BytesPerInodeKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.BytesPerInodeKey: "8192", + ebscsidriver.FSTypeKey: fsType, + }, + }, + ebscsidriver.NumberOfInodesKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.NumberOfInodesKey: "200192", + ebscsidriver.FSTypeKey: fsType, + }, + }, + ebscsidriver.Ext4BigAllocKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.Ext4BigAllocKey: "true", + ebscsidriver.FSTypeKey: fsType, + }, + }, + ebscsidriver.Ext4ClusterSizeKey: { + CreateVolumeParameters: map[string]string{ + ebscsidriver.Ext4BigAllocKey: "true", + ebscsidriver.Ext4ClusterSizeKey: "16384", + ebscsidriver.FSTypeKey: fsType, + }, + }, + } + Context(fmt.Sprintf("using an %s filesystem", fsType), func() { for testedParameter, formatOptionTestCase := range formatOptionTests { formatOptionTestCase := formatOptionTestCase @@ -90,7 +97,7 @@ var _ = Describe("[ebs-csi-e2e] [single-az] [format-options] Formatting a volume Context(fmt.Sprintf("with a custom %s parameter", testedParameter), func() { It("successfully mounts and is resizable", func() { - formatOptionTestCase.Run(cs, ns, ebsDriver, fsType) + formatOptionTestCase.Run(cs, ns, ebsDriver) }) }) } diff --git a/tests/e2e/testsuites/e2e_utils.go b/tests/e2e/testsuites/e2e_utils.go index 921916ea3..b780185b8 100644 --- a/tests/e2e/testsuites/e2e_utils.go +++ b/tests/e2e/testsuites/e2e_utils.go @@ -26,3 +26,20 @@ const ( func PodCmdWriteToVolume(volumeMountPath string) string { return fmt.Sprintf("echo 'hello world' >> %s/data && grep 'hello world' %s/data && sync", volumeMountPath, volumeMountPath) } + +func CreateVolumeDetails(createVolumeParameters map[string]string, volumeSize string) *VolumeDetails { + allowVolumeExpansion := true + + volume := VolumeDetails{ + MountOptions: []string{"rw"}, + ClaimSize: volumeSize, + VolumeMount: VolumeMountDetails{ + NameGenerate: DefaultVolumeName, + MountPathGenerate: DefaultMountPath, + }, + AllowVolumeExpansion: &allowVolumeExpansion, + CreateVolumeParameters: createVolumeParameters, + } + + return &volume +} diff --git a/tests/e2e/testsuites/format_options_tester.go b/tests/e2e/testsuites/format_options_tester.go index 5f86d7af8..80a4eb28a 100644 --- a/tests/e2e/testsuites/format_options_tester.go +++ b/tests/e2e/testsuites/format_options_tester.go @@ -15,7 +15,6 @@ limitations under the License. package testsuites import ( - awscloud "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" ebscsidriver "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver" "github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver" . "github.com/onsi/ginkgo/v2" @@ -33,9 +32,9 @@ const ( volumeSizeIncreaseAmtGi = 1 ) -func (t *FormatOptionTest) Run(client clientset.Interface, namespace *v1.Namespace, ebsDriver driver.PVTestDriver, fsType string) { +func (t *FormatOptionTest) Run(client clientset.Interface, namespace *v1.Namespace, ebsDriver driver.PVTestDriver) { By("setting up pvc with custom format option") - volumeDetails := createFormatOptionVolumeDetails(fsType, t) + volumeDetails := CreateVolumeDetails(t.CreateVolumeParameters, driver.MinimumSizeForVolumeType(t.CreateVolumeParameters[ebscsidriver.VolumeTypeKey])) testPvc, _ := volumeDetails.SetupDynamicPersistentVolumeClaim(client, namespace, ebsDriver) defer testPvc.Cleanup() @@ -55,32 +54,6 @@ func (t *FormatOptionTest) Run(client clientset.Interface, namespace *v1.Namespa resizeTestPod.WaitForSuccess() } -func createFormatOptionVolumeDetails(fsType string, t *FormatOptionTest) *VolumeDetails { - allowVolumeExpansion := true - - parameters := map[string]string{ - ebscsidriver.VolumeTypeKey: awscloud.VolumeTypeGP2, - ebscsidriver.FSTypeKey: fsType, - } - - for k, v := range t.CreateVolumeParameters { - parameters[k] = v - } - - volume := VolumeDetails{ - MountOptions: []string{"rw"}, - ClaimSize: driver.MinimumSizeForVolumeType(awscloud.VolumeTypeGP2), - VolumeMount: VolumeMountDetails{ - NameGenerate: DefaultVolumeName, - MountPathGenerate: DefaultMountPath, - }, - AllowVolumeExpansion: &allowVolumeExpansion, - CreateVolumeParameters: parameters, - } - - return &volume -} - func createPodWithVolume(client clientset.Interface, namespace *v1.Namespace, cmd string, testPvc *TestPersistentVolumeClaim, volumeDetails *VolumeDetails) *TestPod { testPod := NewTestPod(client, namespace, cmd) testPod.SetupVolume(testPvc.persistentVolumeClaim, volumeDetails.VolumeMount.NameGenerate, volumeDetails.VolumeMount.MountPathGenerate, volumeDetails.VolumeMount.ReadOnly)