Skip to content
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

Refactor the E2E framework. Add migration framework. #8564

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test/e2e/basic/api-group/enable_api_group_extentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func APIExtensionsVersionsTest() {
label := "for=backup"
srcCrdYaml := "testdata/enable_api_group_versions/case-a-source-v1beta1.yaml"
BeforeEach(func() {
if veleroCfg.DefaultClusterContext == "" && veleroCfg.StandbyClusterContext == "" {
if veleroCfg.ActiveClusterContext == "" && veleroCfg.StandbyClusterContext == "" {
Skip("CRD with apiextension versions migration test needs 2 clusters")
}
veleroCfg = VeleroCfg
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
srcVersions, err := GetAPIVersions(veleroCfg.DefaultClient, resourceName)
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.ActiveClusterContext)).To(Succeed())
srcVersions, err := GetAPIVersions(veleroCfg.ActiveClient, resourceName)
Expect(err).ShouldNot(HaveOccurred())
dstVersions, err := GetAPIVersions(veleroCfg.StandbyClient, resourceName)
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -67,9 +67,9 @@ func APIExtensionsVersionsTest() {
})
})
AfterEach(func() {
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.DefaultClient
By(fmt.Sprintf("Switch to default kubeconfig context %s", veleroCfg.ActiveClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.ActiveClusterContext)).To(Succeed())
veleroCfg.ClientToInstallVelero = veleroCfg.ActiveClient
})

if CurrentSpecReport().Failed() && veleroCfg.FailFast {
Expand All @@ -82,7 +82,7 @@ func APIExtensionsVersionsTest() {
By("Uninstall Velero and delete CRD ", func() {
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute*5)
defer ctxCancel()
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.ActiveClusterContext)).To(Succeed())
Expect(VeleroUninstall(ctx, veleroCfg)).To(Succeed())
Expect(DeleteCRDByName(context.Background(), crdName)).To(Succeed())

Expand All @@ -98,14 +98,14 @@ func APIExtensionsVersionsTest() {
backupName = "backup-" + UUIDgen.String()
restoreName = "restore-" + UUIDgen.String()

By(fmt.Sprintf("Install Velero in cluster-A (%s) to backup workload", veleroCfg.DefaultClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.DefaultClusterContext)).To(Succeed())
By(fmt.Sprintf("Install Velero in cluster-A (%s) to backup workload", veleroCfg.ActiveClusterContext), func() {
Expect(KubectlConfigUseContext(context.Background(), veleroCfg.ActiveClusterContext)).To(Succeed())
veleroCfg.Features = "EnableAPIGroupVersions"
veleroCfg.UseVolumeSnapshots = false
Expect(VeleroInstall(context.Background(), &veleroCfg, false)).To(Succeed())
})

By(fmt.Sprintf("Install CRD of apiextenstions v1beta1 in cluster-A (%s)", veleroCfg.DefaultClusterContext), func() {
By(fmt.Sprintf("Install CRD of apiextenstions v1beta1 in cluster-A (%s)", veleroCfg.ActiveClusterContext), func() {
Expect(InstallCRD(context.Background(), srcCrdYaml)).To(Succeed())
Expect(CRDShouldExist(context.Background(), crdName)).To(Succeed())
Expect(WaitForCRDEstablished(crdName)).To(Succeed())
Expand Down
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
Loading
Loading