Skip to content

Commit

Permalink
Refactor E2E: Generalize format_options CreateVolumeDetails helper fcn.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSirenko committed Nov 24, 2023
1 parent cc7cbe6 commit 330fcdf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 64 deletions.
77 changes: 42 additions & 35 deletions tests/e2e/format_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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)
})
})
}
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/testsuites/e2e_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
31 changes: 2 additions & 29 deletions tests/e2e/testsuites/format_options_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand All @@ -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)
Expand Down

0 comments on commit 330fcdf

Please sign in to comment.