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 21, 2024
1 parent 95592a2 commit c6f6901
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
24 changes: 19 additions & 5 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,10 +108,14 @@ func (v *BackupVolumeInfo) CreateResources() error {
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
}

Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s-csi.yaml", v.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install StorageClass")
// No need to install the SC and VSC for vsphere environment.
if v.VeleroCfg.CloudProvider != "vsphere" {
// 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")
// 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())
Expand Down Expand Up @@ -137,6 +146,11 @@ func (v *BackupVolumeInfo) Destroy() error {
}

func (v *BackupVolumeInfo) cleanResource() error {
// Skip delete SC and VSC in vSphere environment, because they are not installed.
if v.VeleroCfg.CloudProvider == "vsphere" {
return nil
}

if err := DeleteStorageClass(v.Ctx, v.Client, CSIStorageClassName); err != nil {
return errors.Wrap(err, "fail to delete the StorageClass")
}
Expand Down
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)
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)
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)
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)
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)
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].Skipped == true).To(BeIdenticalTo(true))

Expand Down
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

0 comments on commit c6f6901

Please sign in to comment.