Skip to content

Run snapshot class tests separately from other tests #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/k8s-integration/driver-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (

// generateDriverConfigFile loads a testdriver config template and creates a file
// with the test-specific configuration
func generateDriverConfigFile(testParams *testParameters, storageClassFile string) (string, error) {
func generateDriverConfigFile(testParams *testParameters) (string, error) {
// Load template
t, err := template.ParseFiles(filepath.Join(testParams.pkgDir, testConfigDir, configTemplateFile))
if err != nil {
Expand Down Expand Up @@ -130,16 +130,18 @@ func generateDriverConfigFile(testParams *testParameters, storageClassFile strin
caps = append(caps, "pvcDataSource")
minimumVolumeSize := "5Gi"
numAllowedTopologies := 1
if storageClassFile == regionalPDStorageClass {
if testParams.storageClassFile == regionalPDStorageClass {
minimumVolumeSize = "200Gi"
numAllowedTopologies = 2
}
timeouts := map[string]string{
dataSourceProvisionTimeoutKey: dataSourceProvisionTimeout,
}
extLoc := strings.LastIndex(testParams.storageClassFile, ".")
scName := testParams.storageClassFile[:extLoc]
params := driverConfig{
StorageClassFile: filepath.Join(testParams.pkgDir, testConfigDir, storageClassFile),
StorageClass: storageClassFile[:strings.LastIndex(storageClassFile, ".")],
StorageClassFile: filepath.Join(testParams.pkgDir, testConfigDir, testParams.storageClassFile),
StorageClass: scName,
SnapshotClassFile: absSnapshotClassFilePath,
SnapshotClass: snapshotClassName,
SupportedFsType: fsTypes,
Expand Down
48 changes: 34 additions & 14 deletions test/k8s-integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type testParameters struct {
k8sSourceDir string
testFocus string
testSkip string
storageClassFile string
snapshotClassFile string
cloudProviderArgs []string
deploymentStrategy string
Expand Down Expand Up @@ -501,21 +502,27 @@ func handle() error {
applicableSnapshotClassFiles = append(applicableSnapshotClassFiles, snapshotClassFile)
}
}
if len(applicableSnapshotClassFiles) == 0 {
// when no snapshot class specified, we run the tests without snapshot capability
applicableSnapshotClassFiles = append(applicableSnapshotClassFiles, "")
}
var ginkgoErrors []string
var testOutputDirs []string

// Run non-snapshot tests.
testParams.snapshotClassFile = ""
for _, scFile := range applicableStorageClassFiles {
outputDir := strings.TrimSuffix(scFile, ".yaml")
testOutputDirs = append(testOutputDirs, outputDir)
testParams.storageClassFile = scFile
if err = runCSITests(testParams, outputDir); err != nil {
ginkgoErrors = append(ginkgoErrors, err.Error())
}
}
// Run snapshot tests, if there are applicable files, using the first storage class.
if len(applicableStorageClassFiles) > 0 {
testParams.storageClassFile = applicableStorageClassFiles[0]
for _, snapshotClassFile := range applicableSnapshotClassFiles {
if len(snapshotClassFile) != 0 {
outputDir = fmt.Sprintf("%s--%s", outputDir, strings.TrimSuffix(snapshotClassFile, ".yaml"))
}
testOutputDirs = append(testOutputDirs, outputDir)
testParams.snapshotClassFile = snapshotClassFile
if err = runCSITests(testParams, scFile, outputDir); err != nil {
outputDir := strings.TrimSuffix(snapshotClassFile, ".yaml")
testOutputDirs = append(testOutputDirs, outputDir)
if err = runCSITests(testParams, outputDir); err != nil {
ginkgoErrors = append(ginkgoErrors, err.Error())
}
}
Expand Down Expand Up @@ -633,8 +640,8 @@ func runMigrationTests(testParams *testParameters) error {
return runTestsWithConfig(testParams, "--storage.migratedPlugins=kubernetes.io/gce-pd", "")
}

func runCSITests(testParams *testParameters, storageClassFile string, reportPrefix string) error {
testDriverConfigFile, err := generateDriverConfigFile(testParams, storageClassFile)
func runCSITests(testParams *testParameters, reportPrefix string) error {
testDriverConfigFile, err := generateDriverConfigFile(testParams)
if err != nil {
return fmt.Errorf("failed to generated driver config: %w", err)
}
Expand Down Expand Up @@ -668,7 +675,20 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
kubetestDumpDir = artifactsDir
}
}
ginkgoArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s", testParams.testFocus, testParams.testSkip)

focus := testParams.testFocus
skip := testParams.testSkip
// If testParams.snapshotClassFile is empty, then snapshot tests will be automatically skipped. Otherwise confirm
// the right tests are run.
if testParams.snapshotClassFile != "" && strings.Contains(skip, "VolumeSnapshotDataSource") {
return fmt.Errorf("Snapshot class file %s specified, but snapshot tests are skipped: %s", testParams.snapshotClassFile, skip)
}
if testParams.snapshotClassFile != "" {
// Run exactly the snapshot tests, if there is a snapshot class file.
focus = "Driver:\\s*csi-gcepd.*Feature:VolumeSnapshotDataSource"
}

ginkgoArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s", focus, skip)

windowsArgs := ""
if testParams.platform == "windows" {
Expand Down Expand Up @@ -728,8 +748,8 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--test-package-marker=latest-%s.txt", *testVersion))
}
}
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--focus-regex=%s", testParams.testFocus))
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--skip-regex=%s", testParams.testSkip))
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--focus-regex=%s", focus))
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--skip-regex=%s", skip))
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--parallel=%d", testParams.parallel))
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--test-args=%s %s", testConfigArg, windowsArgs))

Expand Down
2 changes: 1 addition & 1 deletion test/run-k8s-integration-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ readonly run_intree_plugin_tests=${RUN_INTREE_PLUGIN_TESTS:-false}
readonly use_kubetest2=${USE_KUBETEST2:-true}
readonly test_pd_labels=${TEST_PD_LABELS:-true}
readonly migration_test=${MIGRATION_TEST:-false}
readonly test_disk_image_snapshot=${TEST_DISK_IMAGE_SNAPSHOT:-false}
readonly test_disk_image_snapshot=${TEST_DISK_IMAGE_SNAPSHOT:-true}

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

Expand Down