Skip to content

Commit 445028f

Browse files
authored
Merge pull request #966 from mattcary/snap-tests
Run snapshot class tests separately from other tests
2 parents 075128b + 53c0f3b commit 445028f

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

test/k8s-integration/driver-config.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434

3535
// generateDriverConfigFile loads a testdriver config template and creates a file
3636
// with the test-specific configuration
37-
func generateDriverConfigFile(testParams *testParameters, storageClassFile string) (string, error) {
37+
func generateDriverConfigFile(testParams *testParameters) (string, error) {
3838
// Load template
3939
t, err := template.ParseFiles(filepath.Join(testParams.pkgDir, testConfigDir, configTemplateFile))
4040
if err != nil {
@@ -130,16 +130,18 @@ func generateDriverConfigFile(testParams *testParameters, storageClassFile strin
130130
caps = append(caps, "pvcDataSource")
131131
minimumVolumeSize := "5Gi"
132132
numAllowedTopologies := 1
133-
if storageClassFile == regionalPDStorageClass {
133+
if testParams.storageClassFile == regionalPDStorageClass {
134134
minimumVolumeSize = "200Gi"
135135
numAllowedTopologies = 2
136136
}
137137
timeouts := map[string]string{
138138
dataSourceProvisionTimeoutKey: dataSourceProvisionTimeout,
139139
}
140+
extLoc := strings.LastIndex(testParams.storageClassFile, ".")
141+
scName := testParams.storageClassFile[:extLoc]
140142
params := driverConfig{
141-
StorageClassFile: filepath.Join(testParams.pkgDir, testConfigDir, storageClassFile),
142-
StorageClass: storageClassFile[:strings.LastIndex(storageClassFile, ".")],
143+
StorageClassFile: filepath.Join(testParams.pkgDir, testConfigDir, testParams.storageClassFile),
144+
StorageClass: scName,
143145
SnapshotClassFile: absSnapshotClassFilePath,
144146
SnapshotClass: snapshotClassName,
145147
SupportedFsType: fsTypes,

test/k8s-integration/main.go

+34-14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type testParameters struct {
9393
k8sSourceDir string
9494
testFocus string
9595
testSkip string
96+
storageClassFile string
9697
snapshotClassFile string
9798
cloudProviderArgs []string
9899
deploymentStrategy string
@@ -501,21 +502,27 @@ func handle() error {
501502
applicableSnapshotClassFiles = append(applicableSnapshotClassFiles, snapshotClassFile)
502503
}
503504
}
504-
if len(applicableSnapshotClassFiles) == 0 {
505-
// when no snapshot class specified, we run the tests without snapshot capability
506-
applicableSnapshotClassFiles = append(applicableSnapshotClassFiles, "")
507-
}
508505
var ginkgoErrors []string
509506
var testOutputDirs []string
507+
508+
// Run non-snapshot tests.
509+
testParams.snapshotClassFile = ""
510510
for _, scFile := range applicableStorageClassFiles {
511511
outputDir := strings.TrimSuffix(scFile, ".yaml")
512+
testOutputDirs = append(testOutputDirs, outputDir)
513+
testParams.storageClassFile = scFile
514+
if err = runCSITests(testParams, outputDir); err != nil {
515+
ginkgoErrors = append(ginkgoErrors, err.Error())
516+
}
517+
}
518+
// Run snapshot tests, if there are applicable files, using the first storage class.
519+
if len(applicableStorageClassFiles) > 0 {
520+
testParams.storageClassFile = applicableStorageClassFiles[0]
512521
for _, snapshotClassFile := range applicableSnapshotClassFiles {
513-
if len(snapshotClassFile) != 0 {
514-
outputDir = fmt.Sprintf("%s--%s", outputDir, strings.TrimSuffix(snapshotClassFile, ".yaml"))
515-
}
516-
testOutputDirs = append(testOutputDirs, outputDir)
517522
testParams.snapshotClassFile = snapshotClassFile
518-
if err = runCSITests(testParams, scFile, outputDir); err != nil {
523+
outputDir := strings.TrimSuffix(snapshotClassFile, ".yaml")
524+
testOutputDirs = append(testOutputDirs, outputDir)
525+
if err = runCSITests(testParams, outputDir); err != nil {
519526
ginkgoErrors = append(ginkgoErrors, err.Error())
520527
}
521528
}
@@ -633,8 +640,8 @@ func runMigrationTests(testParams *testParameters) error {
633640
return runTestsWithConfig(testParams, "--storage.migratedPlugins=kubernetes.io/gce-pd", "")
634641
}
635642

636-
func runCSITests(testParams *testParameters, storageClassFile string, reportPrefix string) error {
637-
testDriverConfigFile, err := generateDriverConfigFile(testParams, storageClassFile)
643+
func runCSITests(testParams *testParameters, reportPrefix string) error {
644+
testDriverConfigFile, err := generateDriverConfigFile(testParams)
638645
if err != nil {
639646
return fmt.Errorf("failed to generated driver config: %w", err)
640647
}
@@ -668,7 +675,20 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
668675
kubetestDumpDir = artifactsDir
669676
}
670677
}
671-
ginkgoArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s", testParams.testFocus, testParams.testSkip)
678+
679+
focus := testParams.testFocus
680+
skip := testParams.testSkip
681+
// If testParams.snapshotClassFile is empty, then snapshot tests will be automatically skipped. Otherwise confirm
682+
// the right tests are run.
683+
if testParams.snapshotClassFile != "" && strings.Contains(skip, "VolumeSnapshotDataSource") {
684+
return fmt.Errorf("Snapshot class file %s specified, but snapshot tests are skipped: %s", testParams.snapshotClassFile, skip)
685+
}
686+
if testParams.snapshotClassFile != "" {
687+
// Run exactly the snapshot tests, if there is a snapshot class file.
688+
focus = "Driver:\\s*csi-gcepd.*Feature:VolumeSnapshotDataSource"
689+
}
690+
691+
ginkgoArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s", focus, skip)
672692

673693
windowsArgs := ""
674694
if testParams.platform == "windows" {
@@ -728,8 +748,8 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
728748
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--test-package-marker=latest-%s.txt", *testVersion))
729749
}
730750
}
731-
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--focus-regex=%s", testParams.testFocus))
732-
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--skip-regex=%s", testParams.testSkip))
751+
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--focus-regex=%s", focus))
752+
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--skip-regex=%s", skip))
733753
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--parallel=%d", testParams.parallel))
734754
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--test-args=%s %s", testConfigArg, windowsArgs))
735755

test/run-k8s-integration-ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ readonly run_intree_plugin_tests=${RUN_INTREE_PLUGIN_TESTS:-false}
2929
readonly use_kubetest2=${USE_KUBETEST2:-true}
3030
readonly test_pd_labels=${TEST_PD_LABELS:-true}
3131
readonly migration_test=${MIGRATION_TEST:-false}
32-
readonly test_disk_image_snapshot=${TEST_DISK_IMAGE_SNAPSHOT:-false}
32+
readonly test_disk_image_snapshot=${TEST_DISK_IMAGE_SNAPSHOT:-true}
3333

3434
readonly GCE_PD_TEST_FOCUS="PersistentVolumes\sGCEPD|[V|v]olume\sexpand|\[sig-storage\]\sIn-tree\sVolumes\s\[Driver:\sgcepd\]|allowedTopologies|Pod\sDisks|PersistentVolumes\sDefault"
3535

0 commit comments

Comments
 (0)