From 03065a1bded8a455d2d1c403fae58a8f70c951a1 Mon Sep 17 00:00:00 2001 From: Michelle Au Date: Wed, 7 Nov 2018 17:22:19 -0800 Subject: [PATCH] Refactor driverinfo feature support into capabilities map --- test/e2e/storage/drivers/base.go | 22 +++-- test/e2e/storage/drivers/csi.go | 28 +++--- test/e2e/storage/drivers/in_tree.go | 101 ++++++++++++-------- test/e2e/storage/testsuites/provisioning.go | 2 +- test/e2e/storage/testsuites/volume_io.go | 2 +- test/e2e/storage/testsuites/volumemode.go | 4 +- test/e2e/storage/testsuites/volumes.go | 18 +++- 7 files changed, 112 insertions(+), 65 deletions(-) diff --git a/test/e2e/storage/drivers/base.go b/test/e2e/storage/drivers/base.go index ae8f3ab834..95d6b263c3 100644 --- a/test/e2e/storage/drivers/base.go +++ b/test/e2e/storage/drivers/base.go @@ -76,18 +76,26 @@ type DynamicPVTestDriver interface { GetDynamicProvisionStorageClass(fsType string) *storagev1.StorageClass } +// Capability represents a feature that a volume plugin supports +type Capability string + +const ( + CapPersistence Capability = "persistence" // data is persisted across pod restarts + CapBlock Capability = "block" // raw block mode + CapFsGroup Capability = "fsGroup" // volume ownership via fsGroup + CapExec Capability = "exec" // exec a file in the volume +) + // DriverInfo represents a combination of parameters to be used in implementation of TestDriver type DriverInfo struct { Name string // Name of the driver FeatureTag string // FeatureTag for the driver - MaxFileSize int64 // Max file size to be tested for this driver - SupportedFsType sets.String // Map of string for supported fs type - SupportedMountOption sets.String // Map of string for supported mount option - RequiredMountOption sets.String // Map of string for required mount option (Optional) - IsPersistent bool // Flag to represent whether it provides persistency - IsFsGroupSupported bool // Flag to represent whether it supports fsGroup - IsBlockSupported bool // Flag to represent whether it supports Block Volume + MaxFileSize int64 // Max file size to be tested for this driver + SupportedFsType sets.String // Map of string for supported fs type + SupportedMountOption sets.String // Map of string for supported mount option + RequiredMountOption sets.String // Map of string for required mount option (Optional) + Capabilities map[Capability]bool // Map that represents plugin capabilities // Parameters below will be set inside test loop by using SetCommonDriverParameters. // Drivers that implement TestDriver is required to set all the above parameters diff --git a/test/e2e/storage/drivers/csi.go b/test/e2e/storage/drivers/csi.go index 9ede2863f3..4e44738915 100644 --- a/test/e2e/storage/drivers/csi.go +++ b/test/e2e/storage/drivers/csi.go @@ -67,9 +67,9 @@ func InitHostPathCSIDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + }, }, } } @@ -153,9 +153,9 @@ func InitHostV0PathCSIDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + }, }, } } @@ -243,9 +243,11 @@ func InitGcePDCSIDriver() TestDriver { "ext4", "xfs", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapExec: true, + }, }, } } @@ -334,9 +336,11 @@ func InitGcePDExternalCSIDriver() TestDriver { "ext4", "xfs", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapExec: true, + }, }, } } diff --git a/test/e2e/storage/drivers/in_tree.go b/test/e2e/storage/drivers/in_tree.go index c69ae3f42f..cc73bd81a4 100644 --- a/test/e2e/storage/drivers/in_tree.go +++ b/test/e2e/storage/drivers/in_tree.go @@ -90,9 +90,10 @@ func InitNFSDriver() TestDriver { ), SupportedMountOption: sets.NewString("proto=tcp", "relatime"), RequiredMountOption: sets.NewString("vers=4.1"), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapExec: true, + }, }, } } @@ -235,9 +236,10 @@ func InitGlusterFSDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapExec: true, + }, }, } } @@ -356,9 +358,12 @@ func InitISCSIDriver() TestDriver { //"ext3", "ext4", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: true, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapBlock: true, + CapExec: true, + }, }, } } @@ -465,9 +470,13 @@ func InitRbdDriver() TestDriver { //"ext3", "ext4", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: true}, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapBlock: true, + CapExec: true, + }, + }, } } @@ -585,9 +594,10 @@ func InitCephFSDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapExec: true, + }, }, } } @@ -684,9 +694,9 @@ func InitHostPathDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + }, }, } } @@ -756,9 +766,9 @@ func InitHostPathSymlinkDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: true, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + }, }, } } @@ -896,9 +906,9 @@ func InitEmptydirDriver() TestDriver { SupportedFsType: sets.NewString( "", // Default fsType ), - IsPersistent: false, - IsFsGroupSupported: false, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapExec: true, + }, }, } } @@ -963,9 +973,11 @@ func InitCinderDriver() TestDriver { "", // Default fsType "ext3", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapExec: true, + }, }, } } @@ -1121,9 +1133,12 @@ func InitGcePdDriver() TestDriver { "xfs", ), SupportedMountOption: sets.NewString("debug", "nouid32"), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: true, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapBlock: true, + CapExec: true, + }, }, } } @@ -1235,9 +1250,11 @@ func InitVSphereDriver() TestDriver { "", // Default fsType "ext4", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: false, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapExec: true, + }, }, } } @@ -1351,9 +1368,12 @@ func InitAzureDriver() TestDriver { "", // Default fsType "ext4", ), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: true, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapBlock: true, + CapExec: true, + }, }, } } @@ -1464,9 +1484,12 @@ func InitAwsDriver() TestDriver { "ext3", ), SupportedMountOption: sets.NewString("debug", "nouid32"), - IsPersistent: true, - IsFsGroupSupported: true, - IsBlockSupported: true, + Capabilities: map[Capability]bool{ + CapPersistence: true, + CapFsGroup: true, + CapBlock: true, + CapExec: true, + }, }, } } diff --git a/test/e2e/storage/testsuites/provisioning.go b/test/e2e/storage/testsuites/provisioning.go index 70c3ad0e3c..ba9f8d025b 100644 --- a/test/e2e/storage/testsuites/provisioning.go +++ b/test/e2e/storage/testsuites/provisioning.go @@ -187,7 +187,7 @@ func testProvisioning(input *provisioningTestInput) { }) It("should create and delete block persistent volumes", func() { - if !input.dInfo.IsBlockSupported { + if !input.dInfo.Capabilities[drivers.CapBlock] { framework.Skipf("Driver %q does not support BlockVolume - skipping", input.dInfo.Name) } block := v1.PersistentVolumeBlock diff --git a/test/e2e/storage/testsuites/volume_io.go b/test/e2e/storage/testsuites/volume_io.go index 8a09722510..3b29151777 100644 --- a/test/e2e/storage/testsuites/volume_io.go +++ b/test/e2e/storage/testsuites/volume_io.go @@ -90,7 +90,7 @@ func createVolumeIOTestInput(pattern testpatterns.TestPattern, resource genericV framework.Skipf("Driver %q does not define volumeSource - skipping", dInfo.Name) } - if dInfo.IsFsGroupSupported { + if dInfo.Capabilities[drivers.CapFsGroup] { fsGroupVal := int64(1234) fsGroup = &fsGroupVal } diff --git a/test/e2e/storage/testsuites/volumemode.go b/test/e2e/storage/testsuites/volumemode.go index 03468f9332..94bef7508d 100644 --- a/test/e2e/storage/testsuites/volumemode.go +++ b/test/e2e/storage/testsuites/volumemode.go @@ -78,13 +78,13 @@ func createVolumeModeTestInput(pattern testpatterns.TestPattern, resource volume testVolType: pattern.VolType, nodeName: dInfo.Config.ClientNodeName, volMode: pattern.VolMode, - isBlockSupported: dInfo.IsBlockSupported, + isBlockSupported: dInfo.Capabilities[drivers.CapBlock], } } func getVolumeModeTestFunc(pattern testpatterns.TestPattern, driver drivers.TestDriver) func(*volumeModeTestInput) { dInfo := driver.GetDriverInfo() - isBlockSupported := dInfo.IsBlockSupported + isBlockSupported := dInfo.Capabilities[drivers.CapBlock] volMode := pattern.VolMode volType := pattern.VolType diff --git a/test/e2e/storage/testsuites/volumes.go b/test/e2e/storage/testsuites/volumes.go index 0d5d3191cb..8189187fc6 100644 --- a/test/e2e/storage/testsuites/volumes.go +++ b/test/e2e/storage/testsuites/volumes.go @@ -74,12 +74,22 @@ func (t *volumesTestSuite) getTestSuiteInfo() TestSuiteInfo { } func (t *volumesTestSuite) skipUnsupportedTest(pattern testpatterns.TestPattern, driver drivers.TestDriver) { +} + +func skipPersistenceTest(driver drivers.TestDriver) { dInfo := driver.GetDriverInfo() - if !dInfo.IsPersistent { + if !dInfo.Capabilities[drivers.CapPersistence] { framework.Skipf("Driver %q does not provide persistency - skipping", dInfo.Name) } } +func skipExecTest(driver drivers.TestDriver) { + dInfo := driver.GetDriverInfo() + if !dInfo.Capabilities[drivers.CapExec] { + framework.Skipf("Driver %q does not support exec - skipping", dInfo.Name) + } +} + func createVolumesTestInput(pattern testpatterns.TestPattern, resource genericVolumeTestResource) volumesTestInput { var fsGroup *int64 driver := resource.driver @@ -91,7 +101,7 @@ func createVolumesTestInput(pattern testpatterns.TestPattern, resource genericVo framework.Skipf("Driver %q does not define volumeSource - skipping", dInfo.Name) } - if dInfo.IsFsGroupSupported { + if dInfo.Capabilities[drivers.CapFsGroup] { fsGroupVal := int64(1234) fsGroup = &fsGroupVal } @@ -161,13 +171,15 @@ func testVolumes(input *volumesTestInput) { cs := f.ClientSet defer framework.VolumeTestCleanup(f, input.config) + skipPersistenceTest(input.resource.driver) + volumeTest := input.tests framework.InjectHtml(cs, input.config, volumeTest[0].Volume, volumeTest[0].ExpectedContent) framework.TestVolumeClient(cs, input.config, input.fsGroup, input.tests) }) It("should allow exec of files on the volume", func() { f := input.f - defer framework.VolumeTestCleanup(f, input.config) + skipExecTest(input.resource.driver) testScriptInPod(f, input.resource.volType, input.resource.volSource) })