diff --git a/test/e2e/storage/testsuites/base.go b/test/e2e/storage/testsuites/base.go index 626bd9c4240..7dfa5b5270c 100644 --- a/test/e2e/storage/testsuites/base.go +++ b/test/e2e/storage/testsuites/base.go @@ -60,6 +60,17 @@ func init() { type opCounts map[string]int64 +// migrationOpCheck validates migrated metrics. +type migrationOpCheck struct { + cs clientset.Interface + pluginName string + skipCheck bool + + // The old ops are not set if skipCheck is true. + oldInTreeOps opCounts + oldMigratedOps opCounts +} + // BaseSuites is a list of storage test suites that work for in-tree and CSI drivers var BaseSuites = []func() TestSuite{ InitVolumesTestSuite, @@ -687,24 +698,18 @@ func getMigrationVolumeOpCounts(cs clientset.Interface, pluginName string) (opCo return opCounts{}, opCounts{} } -func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string, oldInTreeOps, oldMigratedOps opCounts) { +func newMigrationOpCheck(cs clientset.Interface, pluginName string) *migrationOpCheck { + moc := migrationOpCheck{ + cs: cs, + pluginName: pluginName, + } if len(pluginName) == 0 { // This is a native CSI Driver and we don't check ops - return + moc.skipCheck = true + return &moc } - if sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) { - // If this plugin is migrated based on the test flag storage.migratedPlugins - newInTreeOps, _ := getMigrationVolumeOpCounts(cs, pluginName) - - for op, count := range newInTreeOps { - if count != oldInTreeOps[op] { - framework.Failf("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin", pluginName, count-oldInTreeOps[op], op) - } - } - // We don't check for migrated metrics because some negative test cases - // may not do any volume operations and therefore not emit any metrics - } else { + if !sets.NewString(strings.Split(*migratedPlugins, ",")...).Has(pluginName) { // In-tree plugin is not migrated framework.Logf("In-tree plugin %v is not migrated, not validating any metrics", pluginName) @@ -721,7 +726,27 @@ func validateMigrationVolumeOpCounts(cs clientset.Interface, pluginName string, // and native CSI Driver metrics. This way we can check the counts for // migrated version of the driver for stronger negative test case // guarantees (as well as more informative metrics). + moc.skipCheck = true + return &moc } + moc.oldInTreeOps, moc.oldMigratedOps = getMigrationVolumeOpCounts(cs, pluginName) + return &moc +} + +func (moc *migrationOpCheck) validateMigrationVolumeOpCounts() { + if moc.skipCheck { + return + } + + newInTreeOps, _ := getMigrationVolumeOpCounts(moc.cs, moc.pluginName) + + for op, count := range newInTreeOps { + if count != moc.oldInTreeOps[op] { + framework.Failf("In-tree plugin %v migrated to CSI Driver, however found %v %v metrics for in-tree plugin", moc.pluginName, count-moc.oldInTreeOps[op], op) + } + } + // We don't check for migrated metrics because some negative test cases + // may not do any volume operations and therefore not emit any metrics } // Skip skipVolTypes patterns if the driver supports dynamic provisioning diff --git a/test/e2e/storage/testsuites/multivolume.go b/test/e2e/storage/testsuites/multivolume.go index a7c31ecc68e..a605f296396 100644 --- a/test/e2e/storage/testsuites/multivolume.go +++ b/test/e2e/storage/testsuites/multivolume.go @@ -79,8 +79,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter driver TestDriver resources []*VolumeResource - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var ( dInfo = driver.GetDriverInfo() @@ -108,7 +107,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) } cleanup := func() { @@ -120,7 +119,7 @@ func (t *multiVolumeTestSuite) DefineTests(driver TestDriver, pattern testpatter errs = append(errs, tryFunc(l.driverCleanup)) l.driverCleanup = nil framework.ExpectNoError(errors.NewAggregate(errs), "while cleanup resource") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } // This tests below configuration: diff --git a/test/e2e/storage/testsuites/provisioning.go b/test/e2e/storage/testsuites/provisioning.go index 9e1223c8bc7..63070544b7a 100644 --- a/test/e2e/storage/testsuites/provisioning.go +++ b/test/e2e/storage/testsuites/provisioning.go @@ -103,8 +103,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte sourcePVC *v1.PersistentVolumeClaim sc *storagev1.StorageClass - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var ( dInfo = driver.GetDriverInfo() @@ -139,7 +138,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) l.cs = l.config.Framework.ClientSet testVolumeSizeRange := p.GetTestSuiteInfo().SupportedSizeRange driverVolumeSizeRange := dDriver.GetDriverInfo().SupportedSizeRange @@ -177,7 +176,7 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte l.driverCleanup = nil framework.ExpectNoError(err, "while cleaning up driver") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } ginkgo.It("should provision storage with mount options", func() { diff --git a/test/e2e/storage/testsuites/stress.go b/test/e2e/storage/testsuites/stress.go index bcbbc997d5e..39437f983da 100644 --- a/test/e2e/storage/testsuites/stress.go +++ b/test/e2e/storage/testsuites/stress.go @@ -43,8 +43,7 @@ type stressTest struct { config *PerTestConfig driverCleanup func() - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck resources []*VolumeResource pods []*v1.Pod @@ -110,7 +109,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) l.resources = []*VolumeResource{} l.pods = []*v1.Pod{} l.stopChs = []chan struct{}{} @@ -140,7 +139,7 @@ func (t *stressTestSuite) DefineTests(driver TestDriver, pattern testpatterns.Te errs = append(errs, tryFunc(l.driverCleanup)) framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } ginkgo.It("multiple pods should access different volumes repeatedly [Slow] [Serial]", func() { diff --git a/test/e2e/storage/testsuites/subpath.go b/test/e2e/storage/testsuites/subpath.go index 9fc756f660e..2764c8de114 100644 --- a/test/e2e/storage/testsuites/subpath.go +++ b/test/e2e/storage/testsuites/subpath.go @@ -101,8 +101,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T filePathInSubpath string filePathInVolume string - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var l local @@ -119,7 +118,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName) testVolumeSizeRange := s.GetTestSuiteInfo().SupportedSizeRange l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange) l.hostExec = utils.NewHostExec(f) @@ -183,7 +182,7 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T l.hostExec.Cleanup() } - validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } driverName := driver.GetDriverInfo().Name diff --git a/test/e2e/storage/testsuites/topology.go b/test/e2e/storage/testsuites/topology.go index 7195876dc5a..e394aa40e69 100644 --- a/test/e2e/storage/testsuites/topology.go +++ b/test/e2e/storage/testsuites/topology.go @@ -45,8 +45,7 @@ type topologyTest struct { config *PerTestConfig driverCleanup func() - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck resource VolumeResource pod *v1.Pod @@ -148,7 +147,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns. StorageClassName: &(l.resource.Sc.Name), }, l.config.Framework.Namespace.Name) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) return l } @@ -158,7 +157,7 @@ func (t *topologyTestSuite) DefineTests(driver TestDriver, pattern testpatterns. l.driverCleanup = nil framework.ExpectNoError(err, "while cleaning up driver") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } ginkgo.It("should provision a volume and schedule a pod with AllowedTopologies", func() { diff --git a/test/e2e/storage/testsuites/volume_expand.go b/test/e2e/storage/testsuites/volume_expand.go index e2656790f18..42e5253aa75 100644 --- a/test/e2e/storage/testsuites/volume_expand.go +++ b/test/e2e/storage/testsuites/volume_expand.go @@ -86,8 +86,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte pod *v1.Pod pod2 *v1.Pod - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var l local @@ -112,7 +111,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, driver.GetDriverInfo().InTreePluginName) testVolumeSizeRange := v.GetTestSuiteInfo().SupportedSizeRange l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange) } @@ -141,7 +140,7 @@ func (v *volumeExpandTestSuite) DefineTests(driver TestDriver, pattern testpatte errs = append(errs, tryFunc(l.driverCleanup)) l.driverCleanup = nil framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource") - validateMigrationVolumeOpCounts(f.ClientSet, driver.GetDriverInfo().InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } if !pattern.AllowExpansion { diff --git a/test/e2e/storage/testsuites/volume_io.go b/test/e2e/storage/testsuites/volume_io.go index ce916cbdbdc..d3df462cca2 100644 --- a/test/e2e/storage/testsuites/volume_io.go +++ b/test/e2e/storage/testsuites/volume_io.go @@ -95,8 +95,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns. resource *VolumeResource - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var ( dInfo = driver.GetDriverInfo() @@ -116,7 +115,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns. // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange) @@ -139,7 +138,7 @@ func (t *volumeIOTestSuite) DefineTests(driver TestDriver, pattern testpatterns. } framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } ginkgo.It("should write files of various sizes, verify size, validate content [Slow]", func() { diff --git a/test/e2e/storage/testsuites/volumemode.go b/test/e2e/storage/testsuites/volumemode.go index 5925327094e..3e82ad7b613 100644 --- a/test/e2e/storage/testsuites/volumemode.go +++ b/test/e2e/storage/testsuites/volumemode.go @@ -89,8 +89,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern // VolumeResource contains pv, pvc, sc, etc., owns cleaning that up VolumeResource - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var ( dInfo = driver.GetDriverInfo() @@ -112,7 +111,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) } // manualInit initializes l.VolumeResource without creating the PV & PVC objects. @@ -183,7 +182,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern errs = append(errs, tryFunc(l.driverCleanup)) l.driverCleanup = nil framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } // We register different tests depending on the drive diff --git a/test/e2e/storage/testsuites/volumes.go b/test/e2e/storage/testsuites/volumes.go index 3178da169e4..cb8cccbd0d3 100644 --- a/test/e2e/storage/testsuites/volumes.go +++ b/test/e2e/storage/testsuites/volumes.go @@ -109,8 +109,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T resource *VolumeResource - intreeOps opCounts - migratedOps opCounts + migrationCheck *migrationOpCheck } var dInfo = driver.GetDriverInfo() var l local @@ -128,7 +127,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T // Now do the more expensive test initialization. l.config, l.driverCleanup = driver.PrepareTest(f) - l.intreeOps, l.migratedOps = getMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName) + l.migrationCheck = newMigrationOpCheck(f.ClientSet, dInfo.InTreePluginName) testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange l.resource = CreateVolumeResource(driver, l.config, pattern, testVolumeSizeRange) if l.resource.VolSource == nil { @@ -146,7 +145,7 @@ func (t *volumesTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T errs = append(errs, tryFunc(l.driverCleanup)) l.driverCleanup = nil framework.ExpectNoError(errors.NewAggregate(errs), "while cleaning up resource") - validateMigrationVolumeOpCounts(f.ClientSet, dInfo.InTreePluginName, l.intreeOps, l.migratedOps) + l.migrationCheck.validateMigrationVolumeOpCounts() } ginkgo.It("should store data", func() {