Skip to content

Commit

Permalink
Merge pull request #4810 from danfengliu/fix-after-each-issue
Browse files Browse the repository at this point in the history
Add debug switcher for E2E test
  • Loading branch information
qiuming-best authored Apr 6, 2022
2 parents bb3c5f8 + 7b35f94 commit 20c2073
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 28 deletions.
4 changes: 3 additions & 1 deletion test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ADDITIONAL_BSL_PREFIX ?=
ADDITIONAL_BSL_CONFIG ?=

FEATURES ?=
DEBUG_E2E_TEST ?= false

.PHONY:ginkgo
ginkgo: # Make sure ginkgo is in $GOPATH/bin
Expand Down Expand Up @@ -121,7 +122,8 @@ run: ginkgo
-features=$(FEATURES) \
-install-velero=$(INSTALL_VELERO) \
-registry-credential-file=$(REGISTRY_CREDENTIAL_FILE) \
-kibishii-directory=$(KIBISHII_DIRECTORY)
-kibishii-directory=$(KIBISHII_DIRECTORY) \
-debug-e2e-test=$(DEBUG_E2E_TEST)

build: ginkgo
mkdir -p $(OUTPUT_DIR)
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ func BackupRestoreTest(useVolumeSnapshots bool) {
})

AfterEach(func() {
DeleteNamespace(context.Background(), client, kibishiiNamespace, true)
Expect(err).To(Succeed(), fmt.Sprintf("failed to delete the namespace %q", kibishiiNamespace))

if VeleroCfg.InstallVelero {
err = VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).To(Succeed())
if !VeleroCfg.Debug {
err = VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).To(Succeed())
}
}
})

Expand Down
6 changes: 4 additions & 2 deletions test/e2e/backups/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func backup_deletion_test(useVolumeSnapshots bool) {

AfterEach(func() {
if VeleroCfg.InstallVelero {
err = VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).To(Succeed())
if !VeleroCfg.Debug {
err = VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).To(Succeed())
}
}
})

Expand Down
4 changes: 3 additions & 1 deletion test/e2e/backups/sync_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func BackupsSyncTest() {

AfterEach(func() {
if VeleroCfg.InstallVelero {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
if !VeleroCfg.Debug {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
}
}
})

Expand Down
6 changes: 4 additions & 2 deletions test/e2e/basic/enable_api_group_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ func APIGropuVersionsTest() {
Expect(err).NotTo(HaveOccurred())

if VeleroCfg.InstallVelero {
err = VeleroUninstall(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).NotTo(HaveOccurred())
if !VeleroCfg.Debug {
err = VeleroUninstall(ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)
Expect(err).NotTo(HaveOccurred())
}
}

})
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/bsl-mgmt/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func BslDeletionTest(useVolumeSnapshots bool) {

AfterEach(func() {
if VeleroCfg.InstallVelero {
Expect(DeleteNamespace(context.Background(), client, bslDeletionTestNs,
true)).To(Succeed(), fmt.Sprintf("failed to delete the namespace %q",
bslDeletionTestNs))
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI,
VeleroCfg.VeleroNamespace)).To(Succeed())
if !VeleroCfg.Debug {
Expect(DeleteNamespace(context.Background(), client, bslDeletionTestNs,
true)).To(Succeed(), fmt.Sprintf("failed to delete the namespace %q",
bslDeletionTestNs))
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI,
VeleroCfg.VeleroNamespace)).To(Succeed())
}
}
})

Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func init() {
flag.StringVar(&VeleroCfg.AdditionalBSLConfig, "additional-bsl-config", "", "configuration to use for the additional backup storage location. Format is key1=value1,key2=value2")
flag.StringVar(&VeleroCfg.AdditionalBSLCredentials, "additional-bsl-credentials-file", "", "file containing credentials for additional backup storage location provider. Required if testing multiple credentials support.")
flag.StringVar(&VeleroCfg.Features, "features", "", "Comma-separated list of features to enable for this Velero process.")
flag.BoolVar(&VeleroCfg.Debug, "debug-e2e-test", false, "Switch to control namespace cleaning.")
}

var _ = Describe("[APIGroup] Velero tests with various CRD API group versions", APIGropuVersionsTest)
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/privilegesmgmt/ssr.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func SSRTest() {

AfterEach(func() {
if VeleroCfg.InstallVelero {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
if !VeleroCfg.Debug {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To(Succeed())
}
}
})

Expand Down
6 changes: 4 additions & 2 deletions test/e2e/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func TestFunc(test VeleroBackupRestoreTest) func() {
})
AfterEach(func() {
if VeleroCfg.InstallVelero {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To((Succeed()))
if !VeleroCfg.Debug {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To((Succeed()))
}
}
})
It(test.GetTestMsg().Text, func() {
Expand Down Expand Up @@ -115,7 +117,7 @@ func TestFuncWithMultiIt(tests []VeleroBackupRestoreTest) func() {

AfterEach(func() {
if VeleroCfg.InstallVelero {
if countIt == len(tests) {
if countIt == len(tests) && !VeleroCfg.Debug {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace)).To((Succeed()))
}
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type VerleroConfig struct {
InstallVelero bool
KibishiiDirectory string
Features string
Debug bool
}

type SnapshotCheckPoint struct {
Expand Down
16 changes: 9 additions & 7 deletions test/e2e/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, upgradeFromVelero Upgrade
})
AfterEach(func() {
if VeleroCfg.InstallVelero {
By(fmt.Sprintf("Delete sample workload namespace %s", upgradeNamespace), func() {
DeleteNamespace(context.Background(), client, upgradeNamespace, true)
})
By("Uninstall Velero", func() {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI,
VeleroCfg.VeleroNamespace)).To(Succeed())
})
if !VeleroCfg.Debug {
By(fmt.Sprintf("Delete sample workload namespace %s", upgradeNamespace), func() {
DeleteNamespace(context.Background(), client, upgradeNamespace, true)
})
By("Uninstall Velero", func() {
Expect(VeleroUninstall(context.Background(), VeleroCfg.VeleroCLI,
VeleroCfg.VeleroNamespace)).To(Succeed())
})
}
}
})
When("kibishii is the sample workload", func() {
Expand Down
15 changes: 13 additions & 2 deletions test/e2e/util/kibishii/kibishii_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,22 @@ func RunKibishiiTests(client TestClient, veleroCfg VerleroConfig, backupName, re
registryCredentialFile := VeleroCfg.RegistryCredentialFile
veleroFeatures := VeleroCfg.Features
kibishiiDirectory := VeleroCfg.KibishiiDirectory

if _, err := GetNamespace(context.Background(), client, kibishiiNamespace); err == nil {
fmt.Printf("Workload namespace %s exists, delete it first.", kibishiiNamespace)
if err = DeleteNamespace(context.Background(), client, kibishiiNamespace, true); err != nil {
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", kibishiiNamespace))
}
}
if err := CreateNamespace(oneHourTimeout, client, kibishiiNamespace); err != nil {
return errors.Wrapf(err, "Failed to create namespace %s to install Kibishii workload", kibishiiNamespace)
}

defer func() {
if !veleroCfg.Debug {
if err := DeleteNamespace(context.Background(), client, kibishiiNamespace, true); err != nil {
fmt.Println(errors.Wrapf(err, "failed to delete the namespace %q", kibishiiNamespace))
}
}
}()
if err := KibishiiPrepareBeforeBackup(oneHourTimeout, client, providerName,
kibishiiNamespace, registryCredentialFile, veleroFeatures,
kibishiiDirectory, useVolumeSnapshots); err != nil {
Expand Down

0 comments on commit 20c2073

Please sign in to comment.