From 47ccd15b1dc9d02d70e8447aa85adb24293ba3b0 Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Mon, 3 Oct 2016 16:39:55 -0700 Subject: [PATCH] add delete-namespace-on-failure flag --- docs/devel/e2e-tests.md | 3 +++ hack/verify-flags/known-flags.txt | 1 + test/e2e/framework/framework.go | 12 ++++++++++-- test/e2e/framework/test_context.go | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/devel/e2e-tests.md b/docs/devel/e2e-tests.md index 0200afb8623..372cc68329f 100644 --- a/docs/devel/e2e-tests.md +++ b/docs/devel/e2e-tests.md @@ -137,6 +137,9 @@ go run hack/e2e.go -v --test --test_args="--ginkgo.skip=Pods.*env" # Run tests in parallel, skip any that must be run serially GINKGO_PARALLEL=y go run hack/e2e.go --v --test --test_args="--ginkgo.skip=\[Serial\]" +# Run tests in parallel, skip any that must be run serially and keep the test namespace if test failed +GINKGO_PARALLEL=y go run hack/e2e.go --v --test --test_args="--ginkgo.skip=\[Serial\] --delete-namespace-on-falure=false" + # Flags can be combined, and their actions will take place in this order: # --build, --up, --test, --down # diff --git a/hack/verify-flags/known-flags.txt b/hack/verify-flags/known-flags.txt index 8de4227000b..e7e635e2572 100644 --- a/hack/verify-flags/known-flags.txt +++ b/hack/verify-flags/known-flags.txt @@ -118,6 +118,7 @@ delete-collection-workers delete-instances delete-local-data delete-namespace +delete-namespace-on-failure deleting-pods-burst deleting-pods-qps deployment-controller-sync-period diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 51e94950c30..c297bf9dcd7 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -311,7 +311,10 @@ func (f *Framework) AfterEach() { // expectation failures preventing deleting the namespace. defer func() { nsDeletionErrors := map[string]error{} - if TestContext.DeleteNamespace { + // Whether to delete namespace is determined by 3 factors: delete-namespace flag, delete-namespace-on-failure flag and the test result + // if delete-namespace set to false, namespace will always be preserved. + // if delete-namespace is true and delete-namespace-on-failure is false, namespace will be preserved if test failed. + if TestContext.DeleteNamespace && (TestContext.DeleteNamespaceOnFailure || !CurrentGinkgoTestDescription().Failed) { for _, ns := range f.namespacesToDelete { By(fmt.Sprintf("Destroying namespace %q for this suite.", ns.Name)) timeout := 5 * time.Minute @@ -332,7 +335,12 @@ func (f *Framework) AfterEach() { // Note: this will not cause any failure since we create a new namespace for each test in BeforeEach(). // f.deleteFederationNs() } else { - Logf("Found DeleteNamespace=false, skipping namespace deletion!") + if TestContext.DeleteNamespace { + Logf("Found DeleteNamespace=false, skipping namespace deletion!") + } else if TestContext.DeleteNamespaceOnFailure { + Logf("Found DeleteNamespaceOnFailure=false, skipping namespace deletion!") + } + } // Paranoia-- prevent reuse! diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 936d9d2ca13..ebdf02995f1 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -55,6 +55,7 @@ type TestContextType struct { NodeOSDistro string VerifyServiceAccount bool DeleteNamespace bool + DeleteNamespaceOnFailure bool AllowedNotReadyNodes int CleanStart bool // If set to 'true' or 'all' framework will start a goroutine monitoring resource usage of system add-ons. @@ -148,6 +149,7 @@ func RegisterCommonFlags() { flag.StringVar(&TestContext.OutputPrintType, "output-print-type", "hr", "Comma separated list: 'hr' for human readable summaries 'json' for JSON ones.") flag.BoolVar(&TestContext.DumpLogsOnFailure, "dump-logs-on-failure", true, "If set to true test will dump data about the namespace in which test was running.") flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.") + flag.BoolVar(&TestContext.DeleteNamespaceOnFailure, "delete-namespace-on-failure", true, "If true, framework will delete test namespace on failure. Used only during test debugging.") flag.IntVar(&TestContext.AllowedNotReadyNodes, "allowed-not-ready-nodes", 0, "If non-zero, framework will allow for that many non-ready nodes when checking for all ready nodes.") flag.StringVar(&TestContext.Host, "host", "http://127.0.0.1:8080", "The host, or apiserver, to connect to") flag.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.")