Skip to content

Commit

Permalink
Modify according to comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Feb 22, 2024
1 parent effbcba commit ef5c2ed
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 28 deletions.
16 changes: 8 additions & 8 deletions test/e2e/basic/backup-volume-info/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ func (v *BackupVolumeInfo) Init() error {
v.TestCase.Init()

BeforeEach(func() {
if v.VeleroCfg.CloudProvider == "vsphere" && (!strings.Contains(v.CaseBaseName, "fs-upload") && !strings.Contains(v.CaseBaseName, "skipped")) {
fmt.Printf("Skip snapshot case %s for vsphere environment.\n", v.CaseBaseName)
Skip("Skip snapshot case due to vsphere environment doesn't cover the CSI test, and it doesn't have a Velero native snapshot plugin.")
}

if strings.Contains(v.VeleroCfg.Features, "EnableCSI") {
if strings.Contains(v.CaseBaseName, "native-snapshot") {
fmt.Printf("Skip native snapshot case %s when the CSI feature is enabled.\n", v.CaseBaseName)
Skip("Skip due to vSphere CSI driver long time issue of Static provisioning")
Skip("Skip native snapshot case due to CSI feature is enabled.")
}
} else {
if strings.Contains(v.CaseBaseName, "csi") {
fmt.Printf("Skip CSI related case %s when the CSI feature is not enabled.\n", v.CaseBaseName)
Skip("Skip due to vSphere CSI driver long time issue of Static provisioning")
Skip("Skip CSI cases due to CSI feature is not enabled.")
}
}
})
Expand Down Expand Up @@ -103,11 +108,9 @@ func (v *BackupVolumeInfo) CreateResources() error {
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
}

// Install StorageClass
Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s-csi.yaml", v.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install StorageClass")

// Install VolumeSnapshotClass
Expect(KubectlApplyByFile(v.Ctx, fmt.Sprintf("../testdata/volume-snapshot-class/%s.yaml", v.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install VolumeSnapshotClass")

pvc, err := CreatePVC(v.Client, createNSName, "volume-info", CSIStorageClassName, nil)
Expect(err).To(Succeed())
vols := CreateVolumes(pvc.Name, []string{"volume-info"})
Expand Down Expand Up @@ -141,8 +144,5 @@ func (v *BackupVolumeInfo) cleanResource() error {
return errors.Wrap(err, "fail to delete the StorageClass")
}

if err := KubectlDeleteByFile(v.Ctx, fmt.Sprintf("../testdata/volume-snapshot-class/%s.yaml", v.VeleroCfg.CloudProvider)); err != nil {
return errors.Wrap(err, "fail to delete the VolumeSnapshotClass")
}
return nil
}
8 changes: 7 additions & 1 deletion test/e2e/basic/backup-volume-info/csi_data_mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var CSIDataMoverVolumeInfoTest func() = TestFunc(&CSIDataMoverVolumeInfo{
SnapshotVolumes: true,
TestCase: TestCase{
CaseBaseName: "csi-data-mover-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for CSI data mover case.",
Text: "The VolumeInfo should be generated, and the SnapshotDataMovementInfo structure should not be nil.",
},
},
},
})
Expand All @@ -42,7 +46,7 @@ type CSIDataMoverVolumeInfo struct {

func (c *CSIDataMoverVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
c.VeleroCfg.CloudProvider,
c.VeleroCfg.ObjectStoreProvider,
c.VeleroCfg.CloudCredentialsFile,
c.VeleroCfg.BSLBucket,
c.VeleroCfg.BSLPrefix,
Expand All @@ -52,6 +56,8 @@ func (c *CSIDataMoverVolumeInfo) Verify() error {
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))

fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].SnapshotDataMovementInfo).NotTo(BeNil())

Expand Down
8 changes: 7 additions & 1 deletion test/e2e/basic/backup-volume-info/csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var CSISnapshotVolumeInfoTest func() = TestFunc(&CSISnapshotVolumeInfo{
SnapshotVolumes: true,
TestCase: TestCase{
CaseBaseName: "csi-snapshot-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for CSI snapshot case.",
Text: "The VolumeInfo should be generated, and the CSISnapshotInfo structure should not be nil.",
},
},
},
})
Expand All @@ -41,7 +45,7 @@ type CSISnapshotVolumeInfo struct {

func (c *CSISnapshotVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
c.VeleroCfg.CloudProvider,
c.VeleroCfg.ObjectStoreProvider,
c.VeleroCfg.CloudCredentialsFile,
c.VeleroCfg.BSLBucket,
c.VeleroCfg.BSLPrefix,
Expand All @@ -51,6 +55,8 @@ func (c *CSISnapshotVolumeInfo) Verify() error {
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))

fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].CSISnapshotInfo).NotTo(BeNil())

Expand Down
8 changes: 7 additions & 1 deletion test/e2e/basic/backup-volume-info/filesystem_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var FilesystemUploadVolumeInfoTest func() = TestFunc(&FilesystemUploadVolumeInfo
DefaultVolumesToFSBackup: true,
TestCase: TestCase{
CaseBaseName: "fs-upload-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for filesystem upload case.",
Text: "The VolumeInfo should be generated, and the PVBInfo structure should not be nil.",
},
},
},
})
Expand All @@ -41,7 +45,7 @@ type FilesystemUploadVolumeInfo struct {

func (f *FilesystemUploadVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
f.VeleroCfg.CloudProvider,
f.VeleroCfg.ObjectStoreProvider,
f.VeleroCfg.CloudCredentialsFile,
f.VeleroCfg.BSLBucket,
f.VeleroCfg.BSLPrefix,
Expand All @@ -51,6 +55,8 @@ func (f *FilesystemUploadVolumeInfo) Verify() error {
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))

fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].PVBInfo).NotTo(BeNil())

Expand Down
8 changes: 7 additions & 1 deletion test/e2e/basic/backup-volume-info/native_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var NativeSnapshotVolumeInfoTest func() = TestFunc(&NativeSnapshotVolumeInfo{
SnapshotVolumes: true,
TestCase: TestCase{
CaseBaseName: "native-snapshot-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for native snapshot case.",
Text: "The VolumeInfo should be generated, and the NativeSnapshotInfo structure should not be nil.",
},
},
},
})
Expand All @@ -41,7 +45,7 @@ type NativeSnapshotVolumeInfo struct {

func (n *NativeSnapshotVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
n.VeleroCfg.CloudProvider,
n.VeleroCfg.ObjectStoreProvider,
n.VeleroCfg.CloudCredentialsFile,
n.VeleroCfg.BSLBucket,
n.VeleroCfg.BSLPrefix,
Expand All @@ -51,6 +55,8 @@ func (n *NativeSnapshotVolumeInfo) Verify() error {
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))

fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].NativeSnapshotInfo).NotTo(BeNil())

Expand Down
8 changes: 7 additions & 1 deletion test/e2e/basic/backup-volume-info/skipped_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var SkippedVolumeInfoTest func() = TestFunc(&SkippedVolumeInfo{
SnapshotVolumes: false,
TestCase: TestCase{
CaseBaseName: "skipped-volumes-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for volume-skipped case.",
Text: "The VolumeInfo should be generated, and the Skipped parameter should be true.",
},
},
},
})
Expand All @@ -41,7 +45,7 @@ type SkippedVolumeInfo struct {

func (s *SkippedVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
s.VeleroCfg.CloudProvider,
s.VeleroCfg.ObjectStoreProvider,
s.VeleroCfg.CloudCredentialsFile,
s.VeleroCfg.BSLBucket,
s.VeleroCfg.BSLPrefix,
Expand All @@ -51,6 +55,8 @@ func (s *SkippedVolumeInfo) Verify() error {
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))

fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0])
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].Skipped == true).To(BeIdenticalTo(true))

Expand Down
11 changes: 11 additions & 0 deletions test/testdata/storage-class/vsphere-csi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: e2e-csi-storage-class
annotations:
storageclass.kubernetes.io/is-default-class: "false"
parameters:
StoragePolicyName: "vSAN Default Storage Policy"
provisioner: csi.vsphere.vmware.com
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
8 changes: 0 additions & 8 deletions test/util/csi/AzureVolumeSnapshotClass.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions test/util/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func IsSnapshotExisted(cloudProvider, cloudCredentialsFile, bslBucket, bslConfig
}

func GetVolumeInfoMetadataContent(
cloudProvider,
objectStoreProvider,
cloudCredentialsFile,
bslBucket,
bslPrefix,
Expand All @@ -207,24 +207,24 @@ func GetVolumeInfoMetadataContent(
bslPrefix = strings.Trim(getFullPrefix(bslPrefix, subPrefix), "/")
volumeFileName := backupName + "-volumeinfo.json.gz"
fmt.Printf("|| VERIFICATION || - Get backup %s volumeinfo file in storage %s\n", backupName, bslPrefix)
s, err := getProvider(cloudProvider)
s, err := getProvider(objectStoreProvider)
if err != nil {
return nil, errors.Wrapf(err, fmt.Sprintf("Cloud provider %s is not valid", cloudProvider))
return nil, errors.Wrapf(err, fmt.Sprintf("Cloud provider %s is not valid", objectStoreProvider))
}

return s.GetObject(cloudCredentialsFile, bslBucket, bslPrefix, bslConfig, volumeFileName)
}

func GetVolumeInfo(
cloudProvider,
objectStoreProvider,
cloudCredentialsFile,
bslBucket,
bslPrefix,
bslConfig,
backupName,
subPrefix string,
) ([]*volume.VolumeInfo, error) {
readCloser, err := GetVolumeInfoMetadataContent(cloudProvider,
readCloser, err := GetVolumeInfoMetadataContent(objectStoreProvider,
cloudCredentialsFile,
bslBucket,
bslPrefix,
Expand Down
6 changes: 4 additions & 2 deletions test/util/velero/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ func installVeleroServer(ctx context.Context, cli, cloudProvider string, options

if len(options.Features) > 0 {
args = append(args, "--features", options.Features)
if strings.EqualFold(cloudProvider, "azure") && strings.EqualFold(options.Features, FeatureCSI) && options.UseVolumeSnapshots {
if !strings.EqualFold(cloudProvider, "vsphere") && strings.EqualFold(options.Features, FeatureCSI) && options.UseVolumeSnapshots {
fmt.Println("Start to install Azure VolumeSnapshotClass ...")
if err := KubectlApplyByFile(ctx, "../util/csi/AzureVolumeSnapshotClass.yaml"); err != nil {
if err := KubectlApplyByFile(ctx, fmt.Sprintf("../testdata/volume-snapshot-class/%s.yaml", cloudProvider)); err != nil {
fmt.Println("Fail to install VolumeSnapshotClass when CSI feature is enabled: ", err)
return err
}
}
Expand Down Expand Up @@ -634,6 +635,7 @@ func VeleroUninstall(ctx context.Context, cli, namespace string) error {
return errors.Wrapf(err, "failed to uninstall velero, stdout=%s, stderr=%s", stdout, stderr)
}
fmt.Println("Velero uninstalled ⛵")

return nil
}

Expand Down

0 comments on commit ef5c2ed

Please sign in to comment.