diff --git a/common/e2e_ginkgo/e2e_ginkgo.go b/common/e2e_ginkgo/e2e_ginkgo.go index 65788e0..2f0f179 100644 --- a/common/e2e_ginkgo/e2e_ginkgo.go +++ b/common/e2e_ginkgo/e2e_ginkgo.go @@ -3,6 +3,7 @@ package e2e_ginkgo import ( "fmt" "os" + "strings" "testing" "github.com/openebs/openebs-e2e/common" @@ -243,3 +244,17 @@ func AfterEachCheck() error { func AfterEachK8sCheck() error { return k8stest.ResourceK8sCheck() } + +func BeforeSuiteFailed() { + testSpec := ginkgo.CurrentSpecReport() + leaf := testSpec.LeafNodeLocation.FileName + leaflets := strings.Split(leaf, "/") + if len(leaflets) > 1 { + logsPath, err := common.GetTestSuiteLogsPath(leaflets[len(leaflets)-2]) + if err == nil { + k8stest.GenerateSupportBundle(logsPath) + } else { + log.Log.Info("test suite logs path was not set", "location", leaf) + } + } +} diff --git a/common/vars.go b/common/vars.go index 7a97e4b..b8b22dc 100644 --- a/common/vars.go +++ b/common/vars.go @@ -100,3 +100,19 @@ func ResetTestCaseLogsPath() { currentTestCase = "" testcaseLogsPath = "" } + +// GetTestSuiteLogsPath get the path to the logs directory for the current test suite +func GetTestSuiteLogsPath(testsuite string) (string, error) { + if len(testsuite) > 1 { + logRoot, ok := os.LookupEnv("e2etestlogdir") + if !ok { + logRoot = "/tmp/e2e/logs" + } + t0 := time.Now().UTC() + ts := fmt.Sprintf("%v%02d%02d%v%v%v", t0.Year(), t0.Month(), t0.Day(), t0.Hour(), t0.Minute(), t0.Second()) + tsLogsPath := fmt.Sprintf("%s/%s/%s", logRoot, strings.Map(SanitizePathname, testsuite), ts) + return tsLogsPath, nil + } else { + return "", fmt.Errorf("zero length testsuite name") + } +}