From bd79d00e228b4162339be69f659e8fdb74e167d1 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Tue, 27 Jan 2015 16:44:49 -0800 Subject: [PATCH] Generate JUnit XML for Jenkins from the Go e2e tests Use ginkgo's native support for JUnit in order to generate the XML file. This is a first step in better integration of our e2e tests with Jenkins. In order to improve the logged information, we will probably need to have more native ginkgo tests but this step allows us to see what Jenkins can already do with this information and what we need to tweak to improve it. Tested by running the full e2e tests and inspecting the contents of junit.xml on the top of the tree. Textual output is still generated on the console to keep the current goe2e.sh logs available until the full conversion of our Jenkins instance to use the JUnit XML is completed. --- .gitignore | 3 +++ cmd/e2e/e2e.go | 3 ++- test/e2e/driver.go | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3e8fe105e48..78ef71d8fce 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,9 @@ Session.vim *.test /hack/.test-cmd-auth +# JUnit test output from ginkgo e2e tests +/junit*.xml + # Mercurial files **/.hg **/.hg* diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index becbf9abd90..1cada546ab6 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -29,6 +29,7 @@ import ( var ( authConfig = flag.String("auth_config", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file.") certDir = flag.String("cert_dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.") + reportDir = flag.String("report_dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.") host = flag.String("host", "", "The host to connect to") repoRoot = flag.String("repo_root", "./", "Root directory of kubernetes repository, for finding test files. Default assumes working directory is repository root") provider = flag.String("provider", "", "The name of the Kubernetes provider") @@ -52,5 +53,5 @@ func main() { glog.Error("Invalid --times (negative or no testing requested)!") os.Exit(1) } - e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot, *provider, *orderseed, *times, testList) + e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot, *provider, *orderseed, *times, *reportDir, testList) } diff --git a/test/e2e/driver.go b/test/e2e/driver.go index 58882516295..95ca1643b5c 100644 --- a/test/e2e/driver.go +++ b/test/e2e/driver.go @@ -17,12 +17,14 @@ limitations under the License. package e2e import ( + "path" "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/config" + "github.com/onsi/ginkgo/reporters" "github.com/onsi/gomega" ) @@ -32,7 +34,7 @@ func (t *testResult) Fail() { *t = false } // Run each Go end-to-end-test. This function assumes the // creation of a test cluster. -func RunE2ETests(authConfig, certDir, host, repoRoot, provider string, orderseed int64, times int, testList []string) { +func RunE2ETests(authConfig, certDir, host, repoRoot, provider string, orderseed int64, times int, reportDir string, testList []string) { testContext = testContextType{authConfig, certDir, host, repoRoot, provider} util.ReallyCrash = true util.InitLogs() @@ -57,7 +59,14 @@ func RunE2ETests(authConfig, certDir, host, repoRoot, provider string, orderseed gomega.RegisterFailHandler(ginkgo.Fail) // Turn of colors for now to make it easier to collect console output in Jenkins config.DefaultReporterConfig.NoColor = true - ginkgo.RunSpecs(&passed, "Kubernetes e2e Suite") + var r []ginkgo.Reporter + if reportDir != "" { + // TODO: When we start using parallel tests we need to change this to "junit_%d.xml", + // see ginkgo docs for more details. + r = append(r, reporters.NewJUnitReporter(path.Join(reportDir, "junit.xml"))) + } + // Run the existing tests with output to console + JUnit for Jenkins + ginkgo.RunSpecsWithDefaultAndCustomReporters(&passed, "Kubernetes e2e Suite", r) if !passed { glog.Fatalf("At least one test failed")