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

chore: add support for logs generation on testsuite failure #87

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
15 changes: 15 additions & 0 deletions common/e2e_ginkgo/e2e_ginkgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e_ginkgo
import (
"fmt"
"os"
"strings"
"testing"

"github.com/openebs/openebs-e2e/common"
Expand Down Expand Up @@ -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)
}
}
}
16 changes: 16 additions & 0 deletions common/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}