-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add E2E test cases for backup VolumeInfo feature. #7396
Merged
danfengliu
merged 2 commits into
vmware-tanzu:main
from
blackpiglet:backup_volumeinfo_e2e
Feb 23, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package basic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/pkg/errors" | ||
|
||
. "github.com/vmware-tanzu/velero/test" | ||
. "github.com/vmware-tanzu/velero/test/e2e/test" | ||
. "github.com/vmware-tanzu/velero/test/util/k8s" | ||
. "github.com/vmware-tanzu/velero/test/util/velero" | ||
) | ||
|
||
type BackupVolumeInfo struct { | ||
TestCase | ||
SnapshotVolumes bool | ||
DefaultVolumesToFSBackup bool | ||
SnapshotMoveData bool | ||
TimeoutDuration time.Duration | ||
} | ||
|
||
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 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 CSI cases due to CSI feature is not enabled.") | ||
} | ||
} | ||
}) | ||
|
||
v.CaseBaseName = v.CaseBaseName + v.UUIDgen | ||
v.BackupName = "backup-" + v.CaseBaseName | ||
v.RestoreName = "restore-" + v.CaseBaseName | ||
v.TimeoutDuration = 10 * time.Minute | ||
v.NamespacesTotal = 1 | ||
|
||
v.VeleroCfg = VeleroCfg | ||
v.Client = *v.VeleroCfg.ClientToInstallVelero | ||
v.NSIncluded = &[]string{v.CaseBaseName} | ||
|
||
v.TestMsg = &TestMSG{ | ||
Desc: "Test backup's VolumeInfo metadata content", | ||
Text: "The VolumeInfo should be generated based on the backup type", | ||
FailedMSG: "Failed to verify the backup VolumeInfo's content", | ||
} | ||
|
||
v.BackupArgs = []string{ | ||
"backup", "create", v.BackupName, | ||
"--namespace", v.VeleroCfg.VeleroNamespace, | ||
"--include-namespaces", v.CaseBaseName, | ||
"--snapshot-volumes" + "=" + strconv.FormatBool(v.SnapshotVolumes), | ||
"--default-volumes-to-fs-backup" + "=" + strconv.FormatBool(v.DefaultVolumesToFSBackup), | ||
"--snapshot-move-data" + "=" + strconv.FormatBool(v.SnapshotMoveData), | ||
"--wait", | ||
} | ||
|
||
v.RestoreArgs = []string{ | ||
"create", "--namespace", v.VeleroCfg.VeleroNamespace, "restore", v.RestoreName, | ||
"--from-backup", v.BackupName, "--wait", | ||
} | ||
return nil | ||
} | ||
|
||
func (v *BackupVolumeInfo) CreateResources() error { | ||
v.Ctx, v.CtxCancel = context.WithTimeout(context.Background(), v.TimeoutDuration) | ||
labels := map[string]string{ | ||
"volume-info": "true", | ||
} | ||
for nsNum := 0; nsNum < v.NamespacesTotal; nsNum++ { | ||
fmt.Printf("Creating namespaces ...\n") | ||
createNSName := v.CaseBaseName | ||
if err := CreateNamespaceWithLabel(v.Ctx, v.Client, createNSName, labels); err != nil { | ||
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") | ||
|
||
pvc, err := CreatePVC(v.Client, createNSName, "volume-info", CSIStorageClassName, nil) | ||
Expect(err).To(Succeed()) | ||
vols := CreateVolumes(pvc.Name, []string{"volume-info"}) | ||
|
||
//Create deployment | ||
fmt.Printf("Creating deployment in namespaces ...%s\n", createNSName) | ||
deployment := NewDeployment(v.CaseBaseName, createNSName, 1, labels, nil).WithVolume(vols).Result() | ||
deployment, err = CreateDeployment(v.Client.ClientGo, createNSName, deployment) | ||
if err != nil { | ||
return errors.Wrap(err, fmt.Sprintf("failed to delete the namespace %q", createNSName)) | ||
} | ||
err = WaitForReadyDeployment(v.Client.ClientGo, createNSName, deployment.Name) | ||
if err != nil { | ||
return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", createNSName)) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (v *BackupVolumeInfo) Destroy() error { | ||
err := CleanupNamespaces(v.Ctx, v.Client, v.CaseBaseName) | ||
if err != nil { | ||
return errors.Wrap(err, "Could cleanup retrieve namespaces") | ||
} | ||
|
||
return WaitAllSelectedNSDeleted(v.Ctx, v.Client, "ns-test=true") | ||
} | ||
|
||
func (v *BackupVolumeInfo) cleanResource() error { | ||
if err := DeleteStorageClass(v.Ctx, v.Client, CSIStorageClassName); err != nil { | ||
return errors.Wrap(err, "fail to delete the StorageClass") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package basic | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/vmware-tanzu/velero/test/e2e/test" | ||
. "github.com/vmware-tanzu/velero/test/util/providers" | ||
. "github.com/vmware-tanzu/velero/test/util/velero" | ||
) | ||
|
||
var CSIDataMoverVolumeInfoTest func() = TestFunc(&CSIDataMoverVolumeInfo{ | ||
BackupVolumeInfo{ | ||
SnapshotMoveData: true, | ||
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.", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
type CSIDataMoverVolumeInfo struct { | ||
BackupVolumeInfo | ||
} | ||
|
||
func (c *CSIDataMoverVolumeInfo) Verify() error { | ||
volumeInfo, err := GetVolumeInfo( | ||
c.VeleroCfg.ObjectStoreProvider, | ||
c.VeleroCfg.CloudCredentialsFile, | ||
c.VeleroCfg.BSLBucket, | ||
c.VeleroCfg.BSLPrefix, | ||
c.VeleroCfg.BSLConfig, | ||
c.BackupName, | ||
BackupObjectsPrefix+"/"+c.BackupName, | ||
) | ||
|
||
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()) | ||
|
||
// Clean SC and VSC | ||
return c.cleanResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package basic | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/vmware-tanzu/velero/test/e2e/test" | ||
. "github.com/vmware-tanzu/velero/test/util/providers" | ||
. "github.com/vmware-tanzu/velero/test/util/velero" | ||
) | ||
|
||
var CSISnapshotVolumeInfoTest func() = TestFunc(&CSISnapshotVolumeInfo{ | ||
BackupVolumeInfo{ | ||
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.", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
type CSISnapshotVolumeInfo struct { | ||
BackupVolumeInfo | ||
} | ||
|
||
func (c *CSISnapshotVolumeInfo) Verify() error { | ||
volumeInfo, err := GetVolumeInfo( | ||
c.VeleroCfg.ObjectStoreProvider, | ||
c.VeleroCfg.CloudCredentialsFile, | ||
c.VeleroCfg.BSLBucket, | ||
c.VeleroCfg.BSLPrefix, | ||
c.VeleroCfg.BSLConfig, | ||
c.BackupName, | ||
BackupObjectsPrefix+"/"+c.BackupName, | ||
) | ||
|
||
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()) | ||
|
||
// Clean SC and VSC | ||
return c.cleanResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package basic | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
. "github.com/vmware-tanzu/velero/test/e2e/test" | ||
. "github.com/vmware-tanzu/velero/test/util/providers" | ||
. "github.com/vmware-tanzu/velero/test/util/velero" | ||
) | ||
|
||
var FilesystemUploadVolumeInfoTest func() = TestFunc(&FilesystemUploadVolumeInfo{ | ||
BackupVolumeInfo{ | ||
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.", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
type FilesystemUploadVolumeInfo struct { | ||
BackupVolumeInfo | ||
} | ||
|
||
func (f *FilesystemUploadVolumeInfo) Verify() error { | ||
volumeInfo, err := GetVolumeInfo( | ||
f.VeleroCfg.ObjectStoreProvider, | ||
f.VeleroCfg.CloudCredentialsFile, | ||
f.VeleroCfg.BSLBucket, | ||
f.VeleroCfg.BSLPrefix, | ||
f.VeleroCfg.BSLConfig, | ||
f.BackupName, | ||
BackupObjectsPrefix+"/"+f.BackupName, | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to print volume info file content for case improvement in future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
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()) | ||
|
||
// Clean SC and VSC | ||
return f.cleanResource() | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case should be skipped on vSphere pipeline since we're not going test Velero CSI plugin on vSphere cluster in near future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the check in the base test case.