Skip to content

Commit

Permalink
Merge pull request #87 from openebs/testsuite-logs-support
Browse files Browse the repository at this point in the history
chore: add support for logs generation on testsuite failure
  • Loading branch information
blaisedias authored Oct 25, 2024
2 parents 2c9eac2 + bd57ef5 commit 51852f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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")
}
}

0 comments on commit 51852f4

Please sign in to comment.