Skip to content

Commit

Permalink
chore: add support for logs generation on testsuite failure
Browse files Browse the repository at this point in the history
Add support functions that can be invoked in BeforeSuite
functions to generate logs on failure.

Signed-off-by: Blaise Dias <[email protected]>
  • Loading branch information
blaisedias committed Oct 24, 2024
1 parent 2c9eac2 commit bd57ef5
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 bd57ef5

Please sign in to comment.