All failures are worth logging immediately, not just unexpected errors. That helps understand tests that have long-running cleanup operations with their own logging, because the failure will be visible inside the test output. The logging in framework.ExpectNoError also was rather poor, because it only showed the error, but not the additional information about it. Tests suites now should use log.Fail as Gomega failure handler instead of ginkgowrapper.Fail. log.Fail will handle the logging for all failures before proceeding to record the failure in Ginkgo. Because logging is always done also after a test failure, additional failures during cleanup are now visible. Ginkgo itself just ignores them.
95 lines
3.2 KiB
Go
95 lines
3.2 KiB
Go
/*
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/onsi/ginkgo"
|
|
"github.com/onsi/ginkgo/config"
|
|
"github.com/onsi/ginkgo/reporters"
|
|
"github.com/onsi/gomega"
|
|
"k8s.io/klog"
|
|
|
|
runtimeutils "k8s.io/apimachinery/pkg/util/runtime"
|
|
"k8s.io/component-base/logs"
|
|
commontest "k8s.io/kubernetes/test/e2e/common"
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
|
|
|
// ensure auth plugins are loaded
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
|
|
|
// ensure that cloud providers are loaded
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/aws"
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/azure"
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/gce"
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/kubemark"
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/openstack"
|
|
_ "k8s.io/kubernetes/test/e2e/framework/providers/vsphere"
|
|
)
|
|
|
|
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
|
// Reference common test to make the import valid.
|
|
commontest.CurrentSuite = commontest.E2E
|
|
framework.SetupSuite()
|
|
return nil
|
|
}, func(data []byte) {
|
|
// Run on all Ginkgo nodes
|
|
})
|
|
|
|
var _ = ginkgo.SynchronizedAfterSuite(func() {
|
|
framework.CleanupSuite()
|
|
}, func() {
|
|
framework.AfterSuiteActions()
|
|
})
|
|
|
|
// RunE2ETests checks configuration parameters (specified through flags) and then runs
|
|
// E2E tests using the Ginkgo runner.
|
|
// If a "report directory" is specified, one or more JUnit test reports will be
|
|
// generated in this directory, and cluster logs will also be saved.
|
|
// This function is called on each Ginkgo node in parallel mode.
|
|
func RunE2ETests(t *testing.T) {
|
|
runtimeutils.ReallyCrash = true
|
|
logs.InitLogs()
|
|
defer logs.FlushLogs()
|
|
|
|
gomega.RegisterFailHandler(e2elog.Fail)
|
|
// Disable skipped tests unless they are explicitly requested.
|
|
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
|
|
config.GinkgoConfig.SkipString = `\[Flaky\]|\[Feature:.+\]`
|
|
}
|
|
|
|
// Run tests through the Ginkgo runner with output to console + JUnit for Jenkins
|
|
var r []ginkgo.Reporter
|
|
if framework.TestContext.ReportDir != "" {
|
|
// TODO: we should probably only be trying to create this directory once
|
|
// rather than once-per-Ginkgo-node.
|
|
if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil {
|
|
klog.Errorf("Failed creating report directory: %v", err)
|
|
} else {
|
|
r = append(r, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, fmt.Sprintf("junit_%v%02d.xml", framework.TestContext.ReportPrefix, config.GinkgoConfig.ParallelNode))))
|
|
}
|
|
}
|
|
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, config.GinkgoConfig.ParallelNode)
|
|
|
|
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
|
|
}
|