From feb7abcada36ce368f75f35dd6bdfc5c71137b4c Mon Sep 17 00:00:00 2001 From: Robert Bailey Date: Sat, 18 Apr 2015 15:30:10 -0700 Subject: [PATCH] Ensure that e2e tests run on gce|gke and are appropriately skipped for other cloud providers. --- test/e2e/certs.go | 2 +- test/e2e/es_cluster_logging.go | 3 +-- test/e2e/kubectl.go | 9 +++++---- test/e2e/monitoring.go | 2 +- test/e2e/pd.go | 2 +- test/e2e/rc.go | 7 +++---- test/e2e/service.go | 2 +- test/e2e/shell.go | 14 ++++++-------- test/e2e/util.go | 12 ++++++++++++ 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/test/e2e/certs.go b/test/e2e/certs.go index 0dd8d9de5d4..75278ce6c1c 100644 --- a/test/e2e/certs.go +++ b/test/e2e/certs.go @@ -32,7 +32,7 @@ var _ = Describe("MasterCerts", func() { }) It("should have all expected certs on the master", func() { - if testContext.Provider != "gce" && testContext.Provider != "gke" { + if !providerIs("gce", "gke") { By(fmt.Sprintf("Skipping MasterCerts test for cloud provider %s (only supported for gce and gke)", testContext.Provider)) return } diff --git a/test/e2e/es_cluster_logging.go b/test/e2e/es_cluster_logging.go index 12b212e7804..2c93c2c33d0 100644 --- a/test/e2e/es_cluster_logging.go +++ b/test/e2e/es_cluster_logging.go @@ -57,11 +57,10 @@ func bodyToJSON(body []byte) (map[string]interface{}, error) { // ClusterLevelLoggingWithElasticsearch is an end to end test for cluster level logging. func ClusterLevelLoggingWithElasticsearch(c *client.Client) { - // TODO: For now assume we are only testing cluster logging with Elasticsearch // on GCE. Once we are sure that Elasticsearch cluster level logging // works for other providers we should widen this scope of this test. - if testContext.Provider != "gce" { + if !providerIs("gce") { Logf("Skipping cluster level logging test for provider %s", testContext.Provider) return } diff --git a/test/e2e/kubectl.go b/test/e2e/kubectl.go index 9c0712ff52a..559c7b60b2b 100644 --- a/test/e2e/kubectl.go +++ b/test/e2e/kubectl.go @@ -97,11 +97,12 @@ var _ = Describe("kubectl", func() { Describe("guestbook", func() { var guestbookPath = filepath.Join(testContext.RepoRoot, "examples/guestbook") - if testContext.Provider != "gce" && testContext.Provider != "gke" { - By(fmt.Sprintf("Skipping guestbook, uses createExternalLoadBalancer, a (gce|gke) feature")) - } - It("should create and stop a working application", func() { + if !providerIs("gce", "gke") { + By(fmt.Sprintf("Skipping guestbook, uses createExternalLoadBalancer, a (gce|gke) feature")) + return + } + defer cleanup(guestbookPath, frontendSelector, redisMasterSelector, redisSlaveSelector) By("creating all guestbook components") diff --git a/test/e2e/monitoring.go b/test/e2e/monitoring.go index aa6d326f286..5c5aec5243c 100644 --- a/test/e2e/monitoring.go +++ b/test/e2e/monitoring.go @@ -42,7 +42,7 @@ var _ = Describe("Monitoring", func() { }) It("verify monitoring pods and all cluster nodes are available on influxdb using heapster.", func() { - if testContext.Provider != "gce" { + if !providerIs("gce") { By(fmt.Sprintf("Skipping Monitoring test, which is only supported for provider gce (not %s)", testContext.Provider)) return diff --git a/test/e2e/pd.go b/test/e2e/pd.go index a2204fa942c..dcab60f3d6b 100644 --- a/test/e2e/pd.go +++ b/test/e2e/pd.go @@ -57,7 +57,7 @@ var _ = Describe("PD", func() { }) It("should schedule a pod w/ a RW PD, remove it, then schedule it on another host", func() { - if testContext.Provider != "gce" && testContext.Provider != "aws" { + if !providerIs("gce", "aws") { By(fmt.Sprintf("Skipping PD test, which is only supported for providers gce & aws (not %s)", testContext.Provider)) return diff --git a/test/e2e/rc.go b/test/e2e/rc.go index fbb95c77d28..68fe8530a69 100644 --- a/test/e2e/rc.go +++ b/test/e2e/rc.go @@ -46,13 +46,12 @@ var _ = Describe("ReplicationController", func() { }) It("should serve a basic image on each replica with a private image", func() { - switch testContext.Provider { - case "gce", "gke": - ServeImageOrFail(c, "private", "gcr.io/_b_k8s_authenticated_test/serve_hostname:1.1") - default: + if !providerIs("gce", "gke") { By(fmt.Sprintf("Skipping private variant, which is only supported for providers gce and gke (not %s)", testContext.Provider)) + return } + ServeImageOrFail(c, "private", "gcr.io/_b_k8s_authenticated_test/serve_hostname:1.1") }) }) diff --git a/test/e2e/service.go b/test/e2e/service.go index e07497339a3..8c3d5a11264 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -47,7 +47,7 @@ var _ = Describe("Services", func() { }) It("should provide DNS for the cluster", func() { - if testContext.Provider == "vagrant" { + if providerIs("vagrant") { By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") return } diff --git a/test/e2e/shell.go b/test/e2e/shell.go index 4298618c088..6640d0a4b8e 100644 --- a/test/e2e/shell.go +++ b/test/e2e/shell.go @@ -35,14 +35,6 @@ var ( var _ = Describe("Shell", func() { defer GinkgoRecover() - - // A number of scripts only work on gce - if testContext.Provider != "gce" && testContext.Provider != "gke" { - By(fmt.Sprintf("Skipping Shell test, which is only supported for provider gce and gke (not %s)", - testContext.Provider)) - return - } - // Slurp up all the tests in hack/e2e-suite bashE2ERoot := filepath.Join(root, "hack/e2e-suite") files, err := ioutil.ReadDir(bashE2ERoot) @@ -53,6 +45,12 @@ var _ = Describe("Shell", func() { for _, file := range files { fileName := file.Name() // Make a copy It(fmt.Sprintf("tests that %v passes", fileName), func() { + // A number of scripts only work on gce + if !providerIs("gce", "gke") { + By(fmt.Sprintf("Skipping Shell test %s, which is only supported for provider gce and gke (not %s)", + fileName, testContext.Provider)) + return + } runCmdTest(filepath.Join(bashE2ERoot, fileName)) }) } diff --git a/test/e2e/util.go b/test/e2e/util.go index bec437a3185..9ede8ba048b 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -62,6 +62,18 @@ func Failf(format string, a ...interface{}) { Fail(fmt.Sprintf(format, a...), 1) } +func providerIs(providers ...string) bool { + if testContext.Provider == "" { + Fail("testContext.Provider is not defined") + } + for _, provider := range providers { + if strings.ToLower(provider) == strings.ToLower(testContext.Provider) { + return true + } + } + return false +} + type podCondition func(pod *api.Pod) (bool, error) func waitForPodCondition(c *client.Client, ns, podName, desc string, condition podCondition) error {