Skip to content

Commit

Permalink
[snapshot/restore tests]: Use supplied snapshot storage class, don't …
Browse files Browse the repository at this point in the history
…attempt discover

We have a mechanism to say which storage class we want to test snapshots with,
let's use that, and completely skip those tests if nobody tells us that we can snapshot.

Signed-off-by: Alex Kalenyuk <[email protected]>
  • Loading branch information
akalenyu committed Feb 6, 2024
1 parent 2dee26d commit e4c7dfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
40 changes: 18 additions & 22 deletions tests/libstorage/storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ func DeleteStorageClass(name string) {
}

func GetSnapshotStorageClass(client kubecli.KubevirtClient) (string, error) {
if Config != nil && Config.StorageSnapshot != "" {
return Config.StorageSnapshot, nil
var snapshotStorageClass string

if Config == nil || Config.StorageSnapshot == "" {
return "", nil
}
snapshotStorageClass = Config.StorageSnapshot

sc, err := client.StorageV1().StorageClasses().Get(context.Background(), snapshotStorageClass, metav1.GetOptions{})
if err != nil {
return "", err
}

crd, err := client.
Expand All @@ -87,7 +95,7 @@ func GetSnapshotStorageClass(client kubecli.KubevirtClient) (string, error) {
return "", err
}

hasV1 := false
var hasV1 bool
for _, v := range crd.Spec.Versions {
if v.Name == "v1" && v.Served {
hasV1 = true
Expand All @@ -105,32 +113,20 @@ func GetSnapshotStorageClass(client kubecli.KubevirtClient) (string, error) {
if len(volumeSnapshotClasses.Items) == 0 {
return "", nil
}
defaultSnapClass := volumeSnapshotClasses.Items[0]
for _, snapClass := range volumeSnapshotClasses.Items {
if snapClass.Annotations["snapshot.storage.kubernetes.io/is-default-class"] == "true" {
defaultSnapClass = snapClass
}
}

storageClasses, err := client.StorageV1().StorageClasses().List(context.Background(), metav1.ListOptions{})
if err != nil {
return "", err
}

var storageClass string

for _, sc := range storageClasses.Items {
if sc.Provisioner == defaultSnapClass.Driver {
storageClass = sc.Name
var hasMatchingSnapClass bool
for _, snapClass := range volumeSnapshotClasses.Items {
if sc.Provisioner == snapClass.Driver {
hasMatchingSnapClass = true
break
}
}

if Config != nil {
Config.StorageSnapshot = storageClass
if !hasMatchingSnapClass {
return "", nil
}

return storageClass, nil
return snapshotStorageClass, nil
}

func GetSnapshotClass(scName string, client kubecli.KubevirtClient) (string, error) {
Expand Down
6 changes: 4 additions & 2 deletions tests/storage/datavolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ var _ = SIGDescribe("DataVolume Integration", func() {

It("should accurately report DataVolume provisioning", func() {
sc, err := libstorage.GetSnapshotStorageClass(virtClient)
if err != nil {
Skip("no snapshot storage class configured")
Expect(err).ToNot(HaveOccurred())

if sc == "" {
Skip("Skiping test, no VolumeSnapshot support")
}

dataVolume := libdv.NewDataVolume(
Expand Down

0 comments on commit e4c7dfa

Please sign in to comment.