Revert "Use native Ginkgo test runner instead of cmd/e2e"

This commit is contained in:
Quinton Hoole
2015-04-30 13:45:46 -07:00
parent 8d24f73bab
commit bfaf976df7
9 changed files with 257 additions and 176 deletions

98
test/e2e/driver.go Normal file
View File

@@ -0,0 +1,98 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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"
"path"
"regexp"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"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"
)
type testResult bool
type CloudConfig struct {
ProjectID string
Zone string
MasterName string
Provider cloudprovider.Interface
}
func init() {
// Turn on verbose by default to get spec names
config.DefaultReporterConfig.Verbose = true
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
config.GinkgoConfig.EmitSpecProgress = true
// Randomize specs as well as suites
config.GinkgoConfig.RandomizeAllSpecs = true
}
func (t *testResult) Fail() { *t = false }
// Run each Go end-to-end-test. This function assumes the
// creation of a test cluster.
func RunE2ETests(context *TestContextType, orderseed int64, times int, reportDir string, testList []string) {
testContext = *context
util.ReallyCrash = true
util.InitLogs()
defer util.FlushLogs()
if len(testList) != 0 {
if config.GinkgoConfig.FocusString != "" || config.GinkgoConfig.SkipString != "" {
glog.Fatal("Either specify --test/-t or --ginkgo.focus/--ginkgo.skip but not both.")
}
var testRegexps []string
for _, t := range testList {
testRegexps = append(testRegexps, regexp.QuoteMeta(t))
}
config.GinkgoConfig.FocusString = `\b(` + strings.Join(testRegexps, "|") + `)\b`
}
// Disable density test unless it's explicitly requested.
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
config.GinkgoConfig.SkipString = "Skipped"
}
// TODO: Make orderseed work again.
var passed testResult = true
gomega.RegisterFailHandler(ginkgo.Fail)
// Run the existing tests with output to console + JUnit for Jenkins
for i := 0; i < times && passed; i++ {
var r []ginkgo.Reporter
if reportDir != "" {
r = append(r, reporters.NewJUnitReporter(path.Join(reportDir, fmt.Sprintf("junit_%d.xml", i+1))))
}
ginkgo.RunSpecsWithDefaultAndCustomReporters(&passed, fmt.Sprintf("Kubernetes e2e Suite run %d of %d", i+1, times), r)
}
if !passed {
glog.Fatalf("At least one test failed")
} else {
glog.Infof("All tests pass")
}
}

View File

@@ -1,118 +0,0 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 (
"flag"
"fmt"
"os"
"path"
goruntime "runtime"
"strings"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"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"
)
type testResult bool
var (
cloudConfig = &testContext.CloudConfig
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.")
)
func init() {
// Turn on verbose by default to get spec names
config.DefaultReporterConfig.Verbose = true
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
config.GinkgoConfig.EmitSpecProgress = true
// Randomize specs as well as suites
config.GinkgoConfig.RandomizeAllSpecs = true
flag.StringVar(&testContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, "", "Path to kubeconfig containing embeded authinfo.")
flag.StringVar(&testContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
flag.StringVar(&testContext.AuthConfig, "auth-config", "", "Path to the auth info file.")
flag.StringVar(&testContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
flag.StringVar(&testContext.Host, "host", "", "The host, or apiserver, to connect to")
flag.StringVar(&testContext.RepoRoot, "repo-root", "../../", "Root directory of kubernetes repository, for finding test files.")
flag.StringVar(&testContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, vagrant, etc.)")
// TODO: Flags per provider? Rename gce-project/gce-zone?
flag.StringVar(&cloudConfig.MasterName, "kube-master", "", "Name of the kubernetes master. Only required if provider is gce or gke")
flag.StringVar(&cloudConfig.ProjectID, "gce-project", "", "The GCE project being used, if applicable")
flag.StringVar(&cloudConfig.Zone, "gce-zone", "", "GCE zone being used, if applicable")
}
func (t *testResult) Fail() { *t = false }
func TestE2E(t *testing.T) {
defer util.FlushLogs()
// Disable density test unless it's explicitly requested.
if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" {
config.GinkgoConfig.SkipString = "Skipped"
}
gomega.RegisterFailHandler(ginkgo.Fail)
// Run tests through the Ginkgo runner with output to console + JUnit for Jenkins
var r []ginkgo.Reporter
if *reportDir != "" {
r = append(r, reporters.NewJUnitReporter(path.Join(*reportDir, fmt.Sprintf("junit_%02d.xml", config.GinkgoConfig.ParallelNode))))
}
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r)
}
func TestMain(m *testing.M) {
flag.Parse()
util.ReallyCrash = true
util.InitLogs()
goruntime.GOMAXPROCS(goruntime.NumCPU())
// TODO: possibly clean up or refactor this functionality.
if testContext.Provider == "" {
glog.Info("The --provider flag is not set. Treating as a conformance test. Some tests may not be run.")
os.Exit(1)
}
if testContext.Provider == "aws" {
awsConfig := "[Global]\n"
if cloudConfig.Zone == "" {
glog.Error("gce-zone must be specified for AWS")
os.Exit(1)
}
awsConfig += fmt.Sprintf("Zone=%s\n", cloudConfig.Zone)
var err error
cloudConfig.Provider, err = cloudprovider.GetCloudProvider(testContext.Provider, strings.NewReader(awsConfig))
if err != nil {
glog.Error("Error building AWS provider: ", err)
os.Exit(1)
}
}
os.Exit(m.Run())
}

View File

@@ -45,7 +45,6 @@ const (
)
var _ = Describe("kubectl", func() {
defer GinkgoRecover()
var c *client.Client
var ns string
var testingNs *api.Namespace
@@ -66,12 +65,11 @@ var _ = Describe("kubectl", func() {
})
Describe("update-demo", func() {
var updateDemoRoot, nautilusPath, kittenPath string
BeforeEach(func() {
var (
updateDemoRoot = filepath.Join(testContext.RepoRoot, "examples/update-demo")
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
})
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
)
It("should create and stop a replication controller", func() {
defer cleanup(nautilusPath, updateDemoSelector)
@@ -109,10 +107,7 @@ var _ = Describe("kubectl", func() {
})
Describe("guestbook", func() {
var guestbookPath string
BeforeEach(func() {
guestbookPath = filepath.Join(testContext.RepoRoot, "examples/guestbook")
})
var guestbookPath = filepath.Join(testContext.RepoRoot, "examples/guestbook")
It("should create and stop a working application", func() {
if !providerIs("gce", "gke") {

View File

@@ -22,19 +22,20 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
. "github.com/onsi/ginkgo"
)
var (
root = kubeRootOrDie()
root = absOrDie(filepath.Clean(filepath.Join(path.Base(os.Args[0]), "..")))
)
var _ = Describe("Shell", func() {
defer GinkgoRecover()
// Slurp up all the tests in hack/e2e-suite
// This should be using testContext.RepoRoot, but this is evaluated before flags are evaluated, so we are stuck.
bashE2ERoot := filepath.Join(root, "hack/e2e-suite")
files, err := ioutil.ReadDir(bashE2ERoot)
if err != nil {
@@ -55,13 +56,8 @@ var _ = Describe("Shell", func() {
}
})
// Returns the root directory of the Kubernetes source tree, assuming the test lives inside test/e2e.
func kubeRootOrDie() string {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
out, err := filepath.Abs(filepath.Join(cwd, "..", ".."))
func absOrDie(path string) string {
out, err := filepath.Abs(path)
if err != nil {
panic(err)
}

View File

@@ -34,7 +34,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
@@ -51,14 +50,6 @@ const (
podStartTimeout = 5 * time.Minute
)
type CloudConfig struct {
ProjectID string
Zone string
MasterName string
Provider cloudprovider.Interface
}
type TestContextType struct {
KubeConfig string
KubeContext string
@@ -313,7 +304,8 @@ func validateController(c *client.Client, containerImage string, replicas int, c
Failf("Timed out after %v seconds waiting for %s pods to reach valid state", podStartTimeout.Seconds(), testname)
}
// kubectlCmd runs the kubectl executable through the helper script.
// kubectlCmd runs the kubectl executable.
// kubectlCmd runs the kubectl executable.
func kubectlCmd(args ...string) *exec.Cmd {
defaultArgs := []string{}
@@ -341,7 +333,7 @@ func kubectlCmd(args ...string) *exec.Cmd {
kubectlArgs := append(defaultArgs, args...)
//TODO: the "kubectl" path string might be worth externalizing into an (optional) ginko arg.
cmd := exec.Command(filepath.Join(testContext.RepoRoot, "cluster/kubectl.sh"), kubectlArgs...)
cmd := exec.Command("kubectl", kubectlArgs...)
Logf("Running '%s %s'", cmd.Path, strings.Join(cmd.Args, " "))
return cmd
}