From e699a3e9f25dbe98bbd0456fbe0091b3cba010ca Mon Sep 17 00:00:00 2001 From: danfengl Date: Wed, 28 Sep 2022 02:29:38 +0000 Subject: [PATCH] Fix issues of E2E test for API group, migration and pv opt-out backup 1. One of API group test failed due to other PR with fix for treat PartiallyFailed as failure to collect debugbundle without wrap the origin error; 2. Fix migration test issue of wrong velero cli for backup commmand; 3. Fix wrong pararmeter name issue for pv opt-out backup test. Signed-off-by: danfengl --- test/e2e/basic/enable_api_group_versions.go | 6 ++---- test/e2e/e2e_suite_test.go | 2 +- test/e2e/migration/migration.go | 24 ++++++++++++++------- test/e2e/pv-backup/pv-backup-filter.go | 9 ++++---- test/e2e/util/common/common.go | 16 -------------- test/e2e/util/velero/velero_utils.go | 2 +- 6 files changed, 25 insertions(+), 34 deletions(-) diff --git a/test/e2e/basic/enable_api_group_versions.go b/test/e2e/basic/enable_api_group_versions.go index fea32ae9c..862854a02 100644 --- a/test/e2e/basic/enable_api_group_versions.go +++ b/test/e2e/basic/enable_api_group_versions.go @@ -36,7 +36,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/builder" veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec" . "github.com/vmware-tanzu/velero/test/e2e" - . "github.com/vmware-tanzu/velero/test/e2e/util/common" . "github.com/vmware-tanzu/velero/test/e2e/util/k8s" . "github.com/vmware-tanzu/velero/test/e2e/util/velero" ) @@ -450,8 +449,7 @@ func runEnableAPIGroupVersionsTests(ctx context.Context, client TestClient, reso // No custom resource should have been restored. Expect "no resource found" // error during restore. err := VeleroRestore(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, restore, backup, "") - - if err.Error() != "Unexpected restore phase got PartiallyFailed, expecting Completed" { + if !strings.Contains(err.Error(), "Unexpected restore phase got PartiallyFailed, expecting Completed") { return errors.New("expected error but not none") } } @@ -467,7 +465,7 @@ func runEnableAPIGroupVersionsTests(ctx context.Context, client TestClient, reso func installCRD(ctx context.Context, yaml string) error { fmt.Printf("Install CRD with %s.\n", yaml) - err := KubectlApplyFile(ctx, yaml) + err := KubectlApplyByFile(ctx, yaml) return err } diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 4b733a81f..1025d0216 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -81,7 +81,7 @@ func init() { flag.StringVar(&VeleroCfg.UploaderType, "uploader-type", "", "Identify persistent volume backup uploader.") } -var _ = Describe("[APIGroup] Velero tests with various CRD API group versions", APIGropuVersionsTest) +var _ = Describe("[APIGroup][Common] Velero tests with various CRD API group versions", APIGropuVersionsTest) var _ = Describe("[APIGroup][APIExtensions] CRD of apiextentions v1beta1 should be B/R successfully from cluster(k8s version < 1.22) to cluster(k8s version >= 1.22)", APIExtensionsVersionsTest) // Test backup and restore of Kibishi using restic diff --git a/test/e2e/migration/migration.go b/test/e2e/migration/migration.go index 667acef60..3e81d8dd1 100644 --- a/test/e2e/migration/migration.go +++ b/test/e2e/migration/migration.go @@ -113,11 +113,9 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version) } }) } - + OriginVeleroCfg := VeleroCfg By(fmt.Sprintf("Install Velero in cluster-A (%s) to backup workload", VeleroCfg.DefaultCluster), func() { Expect(KubectlConfigUseContext(context.Background(), VeleroCfg.DefaultCluster)).To(Succeed()) - - OriginVeleroCfg := VeleroCfg OriginVeleroCfg.MigrateFromVeleroVersion = veleroCLI2Version.VeleroVersion OriginVeleroCfg.VeleroCLI = veleroCLI2Version.VeleroCLI OriginVeleroCfg.ClientToInstallVelero = OriginVeleroCfg.DefaultClient @@ -158,9 +156,14 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version) BackupStorageClassCfg.BackupName = backupScName BackupStorageClassCfg.IncludeResources = "StorageClass" BackupStorageClassCfg.IncludeClusterResources = true + //TODO Remove UseRestic parameter once minor version is 1.10 or upper + BackupStorageClassCfg.UseRestic = true + if veleroCLI2Version.VeleroVersion == "self" { + BackupStorageClassCfg.UseRestic = false + } - Expect(VeleroBackupNamespace(context.Background(), VeleroCfg.VeleroCLI, - VeleroCfg.VeleroNamespace, BackupStorageClassCfg)).To(Succeed(), func() string { + Expect(VeleroBackupNamespace(context.Background(), OriginVeleroCfg.VeleroCLI, + OriginVeleroCfg.VeleroNamespace, BackupStorageClassCfg)).To(Succeed(), func() string { RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, BackupStorageClassCfg.BackupName, "") return "Fail to backup workload" }) @@ -171,9 +174,14 @@ func MigrationTest(useVolumeSnapshots bool, veleroCLI2Version VeleroCLI2Version) BackupCfg.UseVolumeSnapshots = useVolumeSnapshots BackupCfg.BackupLocation = "" BackupCfg.Selector = "" - Expect(VeleroBackupNamespace(context.Background(), VeleroCfg.VeleroCLI, - VeleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string { - RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, BackupCfg.BackupName, "") + //TODO Remove UseRestic parameter once minor version is 1.10 or upper + BackupCfg.UseRestic = true + if veleroCLI2Version.VeleroVersion == "self" { + BackupCfg.UseRestic = false + } + Expect(VeleroBackupNamespace(context.Background(), OriginVeleroCfg.VeleroCLI, + OriginVeleroCfg.VeleroNamespace, BackupCfg)).To(Succeed(), func() string { + RunDebug(context.Background(), OriginVeleroCfg.VeleroCLI, OriginVeleroCfg.VeleroNamespace, BackupCfg.BackupName, "") return "Fail to backup workload" }) }) diff --git a/test/e2e/pv-backup/pv-backup-filter.go b/test/e2e/pv-backup/pv-backup-filter.go index 6c5148c97..3de103894 100644 --- a/test/e2e/pv-backup/pv-backup-filter.go +++ b/test/e2e/pv-backup/pv-backup-filter.go @@ -12,7 +12,6 @@ import ( . "github.com/vmware-tanzu/velero/test/e2e" . "github.com/vmware-tanzu/velero/test/e2e/test" - . "github.com/vmware-tanzu/velero/test/e2e/util/common" . "github.com/vmware-tanzu/velero/test/e2e/util/k8s" ) @@ -46,7 +45,7 @@ func (p *PVBackupFiltering) Init() error { } func (p *PVBackupFiltering) StartRun() error { - err := installStorageClass(p.Ctx, fmt.Sprintf("testdata/storage-class/%s.yaml", VeleroCfg.CloudProvider)) + err := installStorageClass(context.Background(), fmt.Sprintf("testdata/storage-class/%s.yaml", VeleroCfg.CloudProvider)) if err != nil { return err } @@ -57,8 +56,10 @@ func (p *PVBackupFiltering) StartRun() error { "--include-namespaces", strings.Join(*p.NSIncluded, ","), "--snapshot-volumes=false", "--wait", } + // "--default-volumes-to-fs-backup" is an overall switch, if it's set, then opt-in + // annotation will be ignored, so it's only set for opt-out test if p.annotation == OPT_OUT_ANN { - p.BackupArgs = append(p.BackupArgs, "--default-volumes-to-restic") + p.BackupArgs = append(p.BackupArgs, "--default-volumes-to-fs-backup") } p.RestoreArgs = []string{ @@ -204,6 +205,6 @@ func fileNotExist(ctx context.Context, namespace, podName, volume string) error func installStorageClass(ctx context.Context, yaml string) error { fmt.Printf("Install storage class with %s.\n", yaml) - err := KubectlApplyFile(ctx, yaml) + err := KubectlApplyByFile(ctx, yaml) return err } diff --git a/test/e2e/util/common/common.go b/test/e2e/util/common/common.go index 9178eda14..f7a43fc71 100644 --- a/test/e2e/util/common/common.go +++ b/test/e2e/util/common/common.go @@ -6,10 +6,6 @@ import ( "context" "fmt" "os/exec" - - "github.com/pkg/errors" - - veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec" ) type OsCommandLine struct { @@ -56,15 +52,3 @@ func GetListBy2Pipes(ctx context.Context, cmdline1, cmdline2, cmdline3 OsCommand return ret, nil } - -func KubectlApplyFile(ctx context.Context, yaml string) error { - fmt.Printf("Kube apply file %s.\n", yaml) - cmd := exec.CommandContext(ctx, "kubectl", "apply", "-f", yaml) - - _, stderr, err := veleroexec.RunCommand(cmd) - if err != nil { - return errors.Wrap(err, stderr) - } - - return nil -} diff --git a/test/e2e/util/velero/velero_utils.go b/test/e2e/util/velero/velero_utils.go index c67598ad1..f8495865c 100644 --- a/test/e2e/util/velero/velero_utils.go +++ b/test/e2e/util/velero/velero_utils.go @@ -443,7 +443,7 @@ func VeleroCmdExec(ctx context.Context, veleroCLI string, args []string) error { err := cmd.Run() retAll := outBuf.String() + " " + errBuf.String() if strings.Contains(strings.ToLower(retAll), "failed") { - return errors.New(fmt.Sprintf("velero cmd =%v return with failure\n", cmd)) + return errors.Wrap(err, fmt.Sprintf("velero cmd =%v return with failure\n", cmd)) } if err != nil { return err