Skip to content

Commit

Permalink
Update functional tests to skip incompatible default storage classes
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Romero <alromero@redhat.com>
  • Loading branch information
alromeros committed May 31, 2023
1 parent 41ba02d commit 9eba18e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
34 changes: 26 additions & 8 deletions tests/cloner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ var _ = Describe("all clone tests", func() {
})

It("[posneg:negative][test_id:6612]Clone with CSI as PVC source with target name that already exists", func() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI driver found")
}
if cloneType == "copy" {
Skip("Cannot simulate target pvc name conflict for host-assisted clone ")
}
Expand Down Expand Up @@ -1596,7 +1599,7 @@ var _ = Describe("all clone tests", func() {
}

By("Create the clone before the source PVC")
cloneDV := utils.NewDataVolumeForImageCloningAndStorageSpec("clone-dv", "1Mi", f.Namespace.Name, dataVolumeName, nil, &blockVM)
cloneDV := utils.NewDataVolumeForImageCloningAndStorageSpec("clone-dv", "1Mi", f.Namespace.Name, dataVolumeName, &f.BlockSCName, &blockVM)
_, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, cloneDV)
Expect(err).ToNot(HaveOccurred())
// Check if the NoSourceClone annotation exists in target PVC
Expand Down Expand Up @@ -2680,6 +2683,9 @@ var _ = Describe("all clone tests", func() {
if crossNamespace && f.IsBindingModeWaitForFirstConsumer(&defaultSc) {
Skip("only host assisted is applicable with WFFC cross namespace")
}
if !f.IsSnapshotStorageClassAvailable() {
Skip("Clone from volumesnapshot does not work without snapshot capable storage")
}

targetNs := f.Namespace
if crossNamespace {
Expand All @@ -2688,10 +2694,10 @@ var _ = Describe("all clone tests", func() {
targetNs = targetNamespace
}
size := "1Gi"
createSnapshot(size, nil, volumeMode)
createSnapshot(size, &f.SnapshotSCName, volumeMode)

for i = 0; i < repeat; i++ {
dataVolume := utils.NewDataVolumeForSnapshotCloningAndStorageSpec(fmt.Sprintf("clone-from-snap-%d", i), size, snapshot.Namespace, snapshot.Name, nil, &volumeMode)
dataVolume := utils.NewDataVolumeForSnapshotCloningAndStorageSpec(fmt.Sprintf("clone-from-snap-%d", i), size, snapshot.Namespace, snapshot.Name, &f.SnapshotSCName, &volumeMode)
dataVolume.Labels = map[string]string{"test-label-1": "test-label-value-1"}
dataVolume.Annotations = map[string]string{"test-annotation-1": "test-annotation-value-1"}
By(fmt.Sprintf("Create new datavolume %s which will clone from volumesnapshot", dataVolume.Name))
Expand Down Expand Up @@ -2855,18 +2861,21 @@ var _ = Describe("all clone tests", func() {

Context("Clone without a source snapshot", func() {
It("[test_id:9718] Should finish the clone after creating the source snapshot", func() {
if !f.IsSnapshotStorageClassAvailable() {
Skip("Clone from volumesnapshot does not work without snapshot capable storage")
}
size := "1Gi"
volumeMode := v1.PersistentVolumeMode(v1.PersistentVolumeFilesystem)
By("Create the clone before the source snapshot")
cloneDV := utils.NewDataVolumeForSnapshotCloningAndStorageSpec("clone-from-snap", size, f.Namespace.Name, "snap-"+dataVolumeName, nil, &volumeMode)
cloneDV := utils.NewDataVolumeForSnapshotCloningAndStorageSpec("clone-from-snap", size, f.Namespace.Name, "snap-"+dataVolumeName, &f.SnapshotSCName, &volumeMode)
cloneDV, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, cloneDV)
Expect(err).ToNot(HaveOccurred())
// Check if the NoSourceClone annotation exists in target PVC
// By("Check the expected event")
// f.ExpectEvent(f.Namespace.Name).Should(ContainSubstring(dvc.CloneWithoutSource))

By("Create source snapshot")
createSnapshot(size, nil, volumeMode)
createSnapshot(size, &f.SnapshotSCName, volumeMode)

clonePvc, err := utils.WaitForPVC(f.K8sClient, cloneDV.Namespace, cloneDV.Name)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -2889,13 +2898,17 @@ var _ = Describe("all clone tests", func() {

Context("Validate source snapshot", func() {
It("[test_id:9719] Should reject when input size is lower than recommended restore size", func() {
if !f.IsSnapshotStorageClassAvailable() {
Skip("Clone from volumesnapshot does not work without snapshot capable storage")
}

recommendedSnapSize := "2Gi"
volumeMode := v1.PersistentVolumeMode(v1.PersistentVolumeFilesystem)

By("Create source snapshot")
createSnapshot(recommendedSnapSize, nil, volumeMode)
createSnapshot(recommendedSnapSize, &f.SnapshotSCName, volumeMode)

cloneDV := utils.NewDataVolumeForSnapshotCloningAndStorageSpec("clone-from-snap", "500Mi", f.Namespace.Name, "snap-"+dataVolumeName, nil, &volumeMode)
cloneDV := utils.NewDataVolumeForSnapshotCloningAndStorageSpec("clone-from-snap", "500Mi", f.Namespace.Name, "snap-"+dataVolumeName, &f.SnapshotSCName, &volumeMode)
_, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, cloneDV)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("target resources requests storage size is smaller than the source"))
Expand All @@ -2904,16 +2917,21 @@ var _ = Describe("all clone tests", func() {

Context("sourceRef support", func() {
It("[test_id:9758] Should clone data from SourceRef snapshot DataSource", func() {
if !f.IsSnapshotStorageClassAvailable() {
Skip("Clone from volumesnapshot does not work without snapshot capable storage")
}

size := "1Gi"
volumeMode := v1.PersistentVolumeMode(v1.PersistentVolumeFilesystem)
createSnapshot(size, nil, volumeMode)
createSnapshot(size, &f.SnapshotSCName, volumeMode)

targetDS := utils.NewSnapshotDataSource("test-datasource", snapshot.Namespace, snapshot.Name, snapshot.Namespace)
By(fmt.Sprintf("Create new datasource %s", targetDS.Name))
targetDataSource, err := f.CdiClient.CdiV1beta1().DataSources(snapshot.Namespace).Create(context.TODO(), targetDS, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

targetDV := utils.NewDataVolumeWithSourceRef("target-dv", size, targetDataSource.Namespace, targetDataSource.Name)
targetDV.Spec.PVC.StorageClassName = &f.SnapshotSCName
By(fmt.Sprintf("Create new target datavolume %s", targetDV.Name))
targetDataVolume, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, targetDV)
Expect(err).ToNot(HaveOccurred())
Expand Down
16 changes: 16 additions & 0 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,12 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
storageProfile := &cdiv1.StorageProfile{}
err := client.Get(context.TODO(), types.NamespacedName{Name: name}, storageProfile)
Expect(err).ToNot(HaveOccurred())
// TODO: Adding a second Get here fixes a "the object has been modified; please apply
// your changes to the latest version and try again" error in "test_id:5912" when using a
// default storage class without accessMode.
// The real cause should bee somewhere else but this fixes it for the moment.
storageProfile, err = f.CdiClient.CdiV1beta1().StorageProfiles().Get(context.TODO(), name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
storageProfile.Spec = spec
err = client.Update(context.TODO(), storageProfile)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -2378,6 +2384,10 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
})

table.DescribeTable("import DV using StorageSpec without AccessModes, PVC is created only when", func(scName string, scFunc func(string)) {
if utils.IsDefaultSCNoProvisioner() {
Skip("Default storage class is no provisioner. The new storage class won't work")
}

By(fmt.Sprintf("verifying no storage class %s", testScName))
_, err := f.K8sClient.StorageV1().StorageClasses().Get(context.TODO(), scName, metav1.GetOptions{})
Expect(err).To(HaveOccurred())
Expand Down Expand Up @@ -2444,6 +2454,10 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
}

table.DescribeTable("import DV with AccessModes, PVC is pending until", func(scName string, scFunc func(string), dvFunc func(string) *cdiv1.DataVolume) {
if utils.IsDefaultSCNoProvisioner() {
Skip("Default storage class is no provisioner. The new storage class won't work")
}

By(fmt.Sprintf("verifying no storage class %s", testScName))
_, err := f.K8sClient.StorageV1().StorageClasses().Get(context.TODO(), scName, metav1.GetOptions{})
Expect(err).To(HaveOccurred())
Expand Down Expand Up @@ -2998,6 +3012,8 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",

sourceDv := utils.NewDataVolumeWithHTTPImport("source-dv", "1Gi", tinyCoreQcow2URL())
Expect(sourceDv).ToNot(BeNil())
sourceDv.Spec.PVC.StorageClassName = &f.SnapshotSCName
sourceDv.Annotations[controller.AnnPodRetainAfterCompletion] = "true"
By(fmt.Sprintf("creating new source dv %s with priority class", sourceDv.Name))
sourceDv, err = utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, sourceDv)
Expect(err).ToNot(HaveOccurred())
Expand Down
7 changes: 4 additions & 3 deletions tests/external_population_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _ = Describe("Population tests", func() {
})

It("Should provision storage with any volume data source", func() {
if !f.IsCSIVolumeCloneStorageClassAvailable() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI drivers available - Population not supported")
}
if !isAnyVolumeDataSourceEnabled() {
Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("Population tests", func() {
})

It("Should not populate PVC when AnyVolumeDataSource is disabled", func() {
if !f.IsCSIVolumeCloneStorageClassAvailable() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI drivers available - Population not supported")
}
if isAnyVolumeDataSourceEnabled() {
Expand Down Expand Up @@ -242,7 +242,7 @@ var _ = Describe("Population tests", func() {

Context("Legacy population", func() {
It("Should perform a CSI PVC clone by manually populating the DataSource field", func() {
if !f.IsCSIVolumeCloneStorageClassAvailable() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI drivers available - Population not supported")
}

Expand Down Expand Up @@ -299,6 +299,7 @@ var _ = Describe("Population tests", func() {
By("Creating source PVC")
pvcDef := utils.NewPVCDefinition(sourcePVCName, "80Mi", nil, nil)
pvcDef.Namespace = f.Namespace.Name
pvcDef.Spec.StorageClassName = &f.SnapshotSCName
sourcePvc := f.CreateAndPopulateSourcePVC(pvcDef, sourcePodFillerName, fillCommand+testFile+"; chmod 660 "+testBaseDir+testFile)

By("Creating Snapshot")
Expand Down
3 changes: 3 additions & 0 deletions tests/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,9 @@ var _ = Describe("Import populator", func() {
}

BeforeEach(func() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI driver found")
}
verifyCleanup(pvc)
})

Expand Down
3 changes: 3 additions & 0 deletions tests/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:cnv-qe@redhat.com][level:compon
}

BeforeEach(func() {
if utils.DefaultStorageClassCsiDriver == nil {
Skip("No CSI driver found")
}
verifyCleanup(pvc)
})

Expand Down
7 changes: 6 additions & 1 deletion tests/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ func IsNfs() bool {
return strings.Contains(DefaultStorageClass.GetName(), "nfs")
}

// IsDefaultSCNoProvisioner return true if the default storage class has no provisioner
func IsDefaultSCNoProvisioner() bool {
return DefaultStorageClass.Provisioner == "kubernetes.io/no-provisioner"
}

// IsStaticNfs returns true if the default storage class is the static nfs storage class with no provisioner
func IsStaticNfs() bool {
return IsNfs() && DefaultStorageClass.Provisioner == "kubernetes.io/no-provisioner"
return IsNfs() && IsDefaultSCNoProvisioner()
}

// IsStaticNfsWithInternalClusterServer returns true if the default storage class is the static nfs storage class with no provisioner
Expand Down

0 comments on commit 9eba18e

Please sign in to comment.