Skip to content

Commit

Permalink
Refactor the E2E framework. Add migration framework.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
  • Loading branch information
blackpiglet committed Dec 30, 2024
1 parent 78c97d9 commit 60b9d8d
Show file tree
Hide file tree
Showing 33 changed files with 296 additions and 190 deletions.
46 changes: 22 additions & 24 deletions test/e2e/basic/backup-volume-info/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,39 @@ import (
v1 "k8s.io/api/core/v1"

. "github.com/vmware-tanzu/velero/test"
. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/common"
. "github.com/vmware-tanzu/velero/test/util/k8s"
)

type BackupVolumeInfo struct {
TestCase
BRCase
SnapshotVolumes bool
DefaultVolumesToFSBackup bool
SnapshotMoveData bool
TimeoutDuration time.Duration
}

func (v *BackupVolumeInfo) Init() error {
v.TestCase.Init()
v.BRCase.Init()

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, FeatureCSI) {
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
Expand Down Expand Up @@ -76,26 +94,6 @@ func (v *BackupVolumeInfo) Init() error {
return nil
}

func (v *BackupVolumeInfo) Start() error {
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, FeatureCSI) {
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.TestCase.Start()
return nil
}
func (v *BackupVolumeInfo) CreateResources() error {
labels := map[string]string{
"volume-info": "true",
Expand Down Expand Up @@ -147,7 +145,7 @@ func (v *BackupVolumeInfo) CreateResources() error {
return nil
}

func (v *BackupVolumeInfo) Destroy() error {
func (v *BackupVolumeInfo) DeleteResources() error {
err := CleanupNamespaces(v.Ctx, v.Client, v.CaseBaseName)
if err != nil {
return errors.Wrap(err, "Could cleanup retrieve namespaces")
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/backup-volume-info/csi_data_mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)
Expand All @@ -30,7 +30,7 @@ var CSIDataMoverVolumeInfoTest func() = TestFunc(&CSIDataMoverVolumeInfo{
BackupVolumeInfo{
SnapshotMoveData: true,
SnapshotVolumes: true,
TestCase: TestCase{
BRCase: BRCase{
CaseBaseName: "csi-data-mover-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for CSI data mover case.",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/backup-volume-info/csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "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{
BRCase: BRCase{
CaseBaseName: "csi-snapshot-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for CSI snapshot case.",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/backup-volume-info/filesystem_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "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{
BRCase: BRCase{
CaseBaseName: "fs-upload-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for filesystem upload case.",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/backup-volume-info/native_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var NativeSnapshotVolumeInfoTest func() = TestFunc(&NativeSnapshotVolumeInfo{
BackupVolumeInfo{
SnapshotVolumes: true,
TestCase: TestCase{
BRCase: BRCase{
UseVolumeSnapshots: true,
CaseBaseName: "native-snapshot-volumeinfo",
TestMsg: &TestMSG{
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/basic/backup-volume-info/skipped_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var SkippedVolumeInfoTest func() = TestFunc(&SkippedVolumeInfo{
BackupVolumeInfo{
SnapshotVolumes: false,
TestCase: TestCase{
BRCase: BRCase{
CaseBaseName: "skipped-volumes-volumeinfo",
TestMsg: &TestMSG{
Desc: "Test backup's VolumeInfo metadata content for volume-skipped case.",
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/basic/namespace-mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
. "github.com/vmware-tanzu/velero/test/util/kibishii"
)

type NamespaceMapping struct {
TestCase
BRCase
MappedNamespaceList []string
kibishiiData *KibishiiData
}

const NamespaceBaseName string = "ns-mp-"

var OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: false}})
var MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: false}})
var OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 1, UseVolumeSnapshots: true}})
var MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NamespacesTotal: 2, UseVolumeSnapshots: true}})
var OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{BRCase: BRCase{NamespacesTotal: 1, UseVolumeSnapshots: false}})
var MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{BRCase: BRCase{NamespacesTotal: 2, UseVolumeSnapshots: false}})
var OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{BRCase: BRCase{NamespacesTotal: 1, UseVolumeSnapshots: true}})
var MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{BRCase: BRCase{NamespacesTotal: 2, UseVolumeSnapshots: true}})

func (n *NamespaceMapping) Init() error {
n.TestCase.Init()
n.BRCase.Init()
n.CaseBaseName = "ns-mp-" + n.UUIDgen
n.BackupName = "backup-" + n.CaseBaseName
n.RestoreName = "restore-" + n.CaseBaseName
Expand Down Expand Up @@ -128,7 +128,7 @@ func (n *NamespaceMapping) Clean() error {
}
}

return n.GetTestCase().Clean()
return n.BRCase.Clean()
}

return nil
Expand Down
14 changes: 10 additions & 4 deletions test/e2e/basic/nodeport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
. "github.com/vmware-tanzu/velero/test/e2e/test"
"github.com/vmware-tanzu/velero/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

type NodePort struct {
TestCase
BRCase
labels map[string]string
serviceName string
namespaceToCollision []string
Expand All @@ -29,7 +30,12 @@ const NodeportBaseName string = "nodeport-"
var NodePortTest func() = TestFunc(&NodePort{})

func (n *NodePort) Init() error {
n.TestCase.Init()
n.BRCase.Init()

if n.VeleroCfg.CloudProvider == test.Azure || n.VeleroCfg.CloudProvider == test.AWS {
Skip("Skip due to issue https://github.com/kubernetes/kubernetes/issues/114384 on AKS")
}

n.CaseBaseName = NodeportBaseName + n.UUIDgen
n.BackupName = "backup-" + n.CaseBaseName
n.RestoreName = "restore-" + n.CaseBaseName
Expand Down Expand Up @@ -77,7 +83,7 @@ func (n *NodePort) CreateResources() error {
return nil
}

func (n *NodePort) Destroy() error {
func (n *NodePort) DeleteResources() error {
for i, ns := range *n.NSIncluded {
By(fmt.Sprintf("Start to destroy namespace %s......", n.CaseBaseName), func() {
Expect(CleanupNamespacesWithPoll(n.Ctx, n.Client, NodeportBaseName)).To(Succeed(),
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
. "github.com/vmware-tanzu/velero/test"
. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

type PVCSelectedNodeChanging struct {
TestCase
BRCase
labels map[string]string
data map[string]string
configmaptName string
Expand All @@ -32,7 +32,7 @@ type PVCSelectedNodeChanging struct {
var PVCSelectedNodeChangingTest func() = TestFunc(&PVCSelectedNodeChanging{})

func (p *PVCSelectedNodeChanging) Init() error {
p.TestCase.Init()
p.BRCase.Init()
p.CaseBaseName = "psnc-" + p.UUIDgen
p.namespace = p.CaseBaseName
p.mappedNS = p.namespace + "-mapped"
Expand Down Expand Up @@ -104,7 +104,7 @@ func (p *PVCSelectedNodeChanging) CreateResources() error {
return nil
}

func (p *PVCSelectedNodeChanging) Destroy() error {
func (p *PVCSelectedNodeChanging) DeleteResources() error {
By(fmt.Sprintf("Start to destroy namespace %s......", p.CaseBaseName), func() {
Expect(CleanupNamespacesWithPoll(p.Ctx, p.Client, p.CaseBaseName)).To(Succeed(),
fmt.Sprintf("Failed to delete namespace %s", p.CaseBaseName))
Expand Down Expand Up @@ -144,7 +144,7 @@ func (p *PVCSelectedNodeChanging) Clean() error {
if CurrentSpecReport().Failed() && p.VeleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
p.TestCase.Clean()
p.BRCase.Clean()
By(fmt.Sprintf("Clean namespace with prefix %s after test", p.mappedNS), func() {
CleanupNamespaces(p.Ctx, p.Client, p.mappedNS)
})
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/basic/resources-check/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import (
"github.com/pkg/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
)

type MultiNSBackup struct {
TestCase
BRCase
IsScalTest bool
NSExcluded *[]string
TimeoutDuration time.Duration
}

func (m *MultiNSBackup) Init() error {
m.TestCase.Init()
m.BRCase.Init()
m.CaseBaseName = "nstest-" + m.UUIDgen
m.BackupName = "backup-" + m.CaseBaseName
m.RestoreName = "restore-" + m.CaseBaseName
Expand Down Expand Up @@ -111,7 +111,7 @@ func (m *MultiNSBackup) Verify() error {
return nil
}

func (m *MultiNSBackup) Destroy() error {
func (m *MultiNSBackup) DeleteResources() error {
err := CleanupNamespaces(m.Ctx, m.Client, m.CaseBaseName)
if err != nil {
return errors.Wrap(err, "Could cleanup retrieve namespaces")
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/basic/resources-check/namespaces_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import (

"github.com/pkg/errors"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
)

type NSAnnotationCase struct {
TestCase
BRCase
}

func (n *NSAnnotationCase) Init() error {
n.TestCase.Init()
n.BRCase.Init()
n.CaseBaseName = "namespace-annotations-" + n.UUIDgen
n.BackupName = "backup-" + n.CaseBaseName
n.RestoreName = "restore-" + n.CaseBaseName
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/basic/resources-check/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ import (
. "github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
. "github.com/vmware-tanzu/velero/test/util/k8s"
)

type RBACCase struct {
TestCase
BRCase
}

func (r *RBACCase) Init() error {
r.TestCase.Init()
r.BRCase.Init()
r.CaseBaseName = "rabc-" + r.UUIDgen
r.BackupName = "backup-" + r.CaseBaseName
r.RestoreName = "restore-" + r.CaseBaseName
Expand Down Expand Up @@ -155,7 +155,7 @@ func (r *RBACCase) Verify() error {
return nil
}

func (r *RBACCase) Destroy() error {
func (r *RBACCase) DeleteResources() error {
//cleanup clusterrole
err := CleanupClusterRole(r.Ctx, r.Client, r.CaseBaseName)
if err != nil {
Expand All @@ -180,7 +180,7 @@ func (r *RBACCase) Clean() error {
if CurrentSpecReport().Failed() && r.VeleroCfg.FailFast {
fmt.Println("Test case failed and fail fast is enabled. Skip resource clean up.")
} else {
return r.Destroy()
return r.DeleteResources()
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/basic/resources-check/resources_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ limitations under the License.
package basic

import (
. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/e2e/framework"
)

func GetResourcesCheckTestCases() []VeleroBackupRestoreTest {
return []VeleroBackupRestoreTest{
func GetResourcesCheckTestCases() []BackupRestoreTest {
return []BackupRestoreTest{
&NSAnnotationCase{},
&MultiNSBackup{IsScalTest: false},
&RBACCase{},
Expand Down
Loading

0 comments on commit 60b9d8d

Please sign in to comment.