Merge pull request #8706 from lavalamp/e2e-timeout

Use e2e framework in more tests
This commit is contained in:
Dawn Chen 2015-05-22 15:53:00 -07:00
commit e52e299de2
5 changed files with 26 additions and 80 deletions

View File

@ -22,7 +22,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields" "github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@ -38,25 +37,15 @@ var dnsServiceLableSelector = labels.Set{
}.AsSelector() }.AsSelector()
var _ = Describe("DNS", func() { var _ = Describe("DNS", func() {
var c *client.Client f := NewFramework("dns")
// Use this in tests. They're unique for each test to prevent name collisions.
var testNamespace string
BeforeEach(func() {
var err error
c, err = loadClient()
Expect(err).NotTo(HaveOccurred())
ns, err := createTestingNS("dns", c)
Expect(err).NotTo(HaveOccurred())
testNamespace = ns.Name
})
It("should provide DNS for the cluster", func() { It("should provide DNS for the cluster", func() {
if providerIs("vagrant") { if providerIs("vagrant") {
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
return return
} }
podClient := c.Pods(api.NamespaceDefault) podClient := f.Client.Pods(api.NamespaceDefault)
By("Waiting for DNS Service to be Running") By("Waiting for DNS Service to be Running")
dnsPods, err := podClient.List(dnsServiceLableSelector, fields.Everything()) dnsPods, err := podClient.List(dnsServiceLableSelector, fields.Everything())
@ -66,7 +55,7 @@ var _ = Describe("DNS", func() {
if len(dnsPods.Items) != 1 { if len(dnsPods.Items) != 1 {
Failf("Unexpected number of pods (%d) matches the label selector %v", len(dnsPods.Items), dnsServiceLableSelector.String()) Failf("Unexpected number of pods (%d) matches the label selector %v", len(dnsPods.Items), dnsServiceLableSelector.String())
} }
expectNoError(waitForPodRunning(c, dnsPods.Items[0].Name)) expectNoError(waitForPodRunning(f.Client, dnsPods.Items[0].Name))
// All the names we need to be able to resolve. // All the names we need to be able to resolve.
// TODO: Spin up a separate test service and test that dns works for that service. // TODO: Spin up a separate test service and test that dns works for that service.
@ -99,7 +88,7 @@ var _ = Describe("DNS", func() {
}, },
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "dns-test-" + string(util.NewUUID()), Name: "dns-test-" + string(util.NewUUID()),
Namespace: testNamespace, Namespace: f.Namespace.Name,
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
Volumes: []api.Volume{ Volumes: []api.Volume{
@ -138,7 +127,7 @@ var _ = Describe("DNS", func() {
} }
By("submitting the pod to kubernetes") By("submitting the pod to kubernetes")
podClient = c.Pods(testNamespace) podClient = f.Client.Pods(f.Namespace.Name)
defer func() { defer func() {
By("deleting the pod") By("deleting the pod")
defer GinkgoRecover() defer GinkgoRecover()
@ -148,7 +137,7 @@ var _ = Describe("DNS", func() {
Failf("Failed to create %s pod: %v", pod.Name, err) Failf("Failed to create %s pod: %v", pod.Name, err)
} }
expectNoError(waitForPodRunningInNamespace(c, pod.Name, testNamespace)) expectNoError(f.WaitForPodRunning(pod.Name))
By("retrieving the pod") By("retrieving the pod")
pod, err = podClient.Get(pod.Name) pod, err = podClient.Get(pod.Name)
@ -165,10 +154,10 @@ var _ = Describe("DNS", func() {
for _, name := range namesToResolve { for _, name := range namesToResolve {
for _, proto := range []string{"udp", "tcp"} { for _, proto := range []string{"udp", "tcp"} {
testCase := fmt.Sprintf("%s@%s", proto, name) testCase := fmt.Sprintf("%s@%s", proto, name)
_, err := c.Get(). _, err := f.Client.Get().
Prefix("proxy"). Prefix("proxy").
Resource("pods"). Resource("pods").
Namespace(testNamespace). Namespace(f.Namespace.Name).
Name(pod.Name). Name(pod.Name).
Suffix("results", testCase). Suffix("results", testCase).
Do().Raw() Do().Raw()

View File

@ -22,22 +22,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
) )
var _ = Describe("emptyDir", func() { var _ = Describe("emptyDir", func() {
var ( f := NewFramework("emptydir")
c *client.Client
)
BeforeEach(func() {
var err error
c, err = loadClient()
expectNoError(err)
})
It("volume on tmpfs should have the correct mode", func() { It("volume on tmpfs should have the correct mode", func() {
volumePath := "/test-volume" volumePath := "/test-volume"
@ -50,7 +41,7 @@ var _ = Describe("emptyDir", func() {
fmt.Sprintf("--fs_type=%v", volumePath), fmt.Sprintf("--fs_type=%v", volumePath),
fmt.Sprintf("--file_mode=%v", volumePath), fmt.Sprintf("--file_mode=%v", volumePath),
} }
testContainerOutput("emptydir r/w on tmpfs", c, pod, []string{ f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
"mount type of \"/test-volume\": tmpfs", "mount type of \"/test-volume\": tmpfs",
"mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir "mode of file \"/test-volume\": dtrwxrwxrwx", // we expect the sticky bit (mode flag t) to be set for the dir
}) })
@ -69,7 +60,7 @@ var _ = Describe("emptyDir", func() {
fmt.Sprintf("--rw_new_file=%v", filePath), fmt.Sprintf("--rw_new_file=%v", filePath),
fmt.Sprintf("--file_mode=%v", filePath), fmt.Sprintf("--file_mode=%v", filePath),
} }
testContainerOutput("emptydir r/w on tmpfs", c, pod, []string{ f.TestContainerOutput("emptydir r/w on tmpfs", pod, []string{
"mount type of \"/test-volume\": tmpfs", "mount type of \"/test-volume\": tmpfs",
"mode of file \"/test-volume/test-file\": -rw-r--r--", "mode of file \"/test-volume/test-file\": -rw-r--r--",
"content of file \"/test-volume/test-file\": mount-tester new file", "content of file \"/test-volume/test-file\": mount-tester new file",

View File

@ -94,3 +94,8 @@ func (f *Framework) afterEach() {
func (f *Framework) WaitForPodRunning(podName string) error { func (f *Framework) WaitForPodRunning(podName string) error {
return waitForPodRunningInNamespace(f.Client, podName, f.Namespace.Name) return waitForPodRunningInNamespace(f.Client, podName, f.Namespace.Name)
} }
// Runs the given pod and verifies that its output matches the desired output.
func (f *Framework) TestContainerOutput(scenarioName string, pod *api.Pod, expectedOutput []string) {
testContainerOutputInNamespace(scenarioName, f.Client, pod, expectedOutput, f.Namespace.Name)
}

View File

@ -20,33 +20,13 @@ import (
"fmt" "fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
) )
var _ = Describe("Secrets", func() { var _ = Describe("Secrets", func() {
var c *client.Client f := NewFramework("secrets")
var ns string
BeforeEach(func() {
var err error
c, err = loadClient()
expectNoError(err)
ns_, err := createTestingNS("secrets", c)
ns = ns_.Name
expectNoError(err)
})
AfterEach(func() {
// Clean up the namespace if a non-default one was used
if ns != api.NamespaceDefault {
By("Cleaning up the namespace")
err := c.Namespaces().Delete(ns)
expectNoError(err)
}
})
It("should be consumable from pods", func() { It("should be consumable from pods", func() {
name := "secret-test-" + string(util.NewUUID()) name := "secret-test-" + string(util.NewUUID())
@ -55,7 +35,7 @@ var _ = Describe("Secrets", func() {
secret := &api.Secret{ secret := &api.Secret{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Namespace: ns, Namespace: f.Namespace.Name,
Name: name, Name: name,
}, },
Data: map[string][]byte{ Data: map[string][]byte{
@ -68,12 +48,12 @@ var _ = Describe("Secrets", func() {
By(fmt.Sprintf("Creating secret with name %s", secret.Name)) By(fmt.Sprintf("Creating secret with name %s", secret.Name))
defer func() { defer func() {
By("Cleaning up the secret") By("Cleaning up the secret")
if err := c.Secrets(ns).Delete(secret.Name); err != nil { if err := f.Client.Secrets(f.Namespace.Name).Delete(secret.Name); err != nil {
Failf("unable to delete secret %v: %v", secret.Name, err) Failf("unable to delete secret %v: %v", secret.Name, err)
} }
}() }()
var err error var err error
if secret, err = c.Secrets(ns).Create(secret); err != nil { if secret, err = f.Client.Secrets(f.Namespace.Name).Create(secret); err != nil {
Failf("unable to create test secret %s: %v", secret.Name, err) Failf("unable to create test secret %s: %v", secret.Name, err)
} }
@ -112,9 +92,9 @@ var _ = Describe("Secrets", func() {
}, },
} }
testContainerOutputInNamespace("consume secrets", c, pod, []string{ testContainerOutputInNamespace("consume secrets", f.Client, pod, []string{
"content of file \"/etc/secret-volume/data-1\": value-1", "content of file \"/etc/secret-volume/data-1\": value-1",
"mode of file \"/etc/secret-volume/data-1\": -r--r--r--", "mode of file \"/etc/secret-volume/data-1\": -r--r--r--",
}, ns) }, f.Namespace.Name)
}) })
}) })

View File

@ -32,26 +32,7 @@ import (
) )
var _ = Describe("ServiceAccounts", func() { var _ = Describe("ServiceAccounts", func() {
var c *client.Client f := NewFramework("svcaccounts")
var ns string
BeforeEach(func() {
var err error
c, err = loadClient()
expectNoError(err)
ns_, err := createTestingNS("service-accounts", c)
ns = ns_.Name
expectNoError(err)
})
AfterEach(func() {
// Clean up the namespace if a non-default one was used
if ns != api.NamespaceDefault {
By("Cleaning up the namespace")
err := c.Namespaces().Delete(ns)
expectNoError(err)
}
})
It("should mount an API token into pods", func() { It("should mount an API token into pods", func() {
var tokenName string var tokenName string
@ -61,7 +42,7 @@ var _ = Describe("ServiceAccounts", func() {
expectNoError(wait.Poll(time.Millisecond*500, time.Second*10, func() (bool, error) { expectNoError(wait.Poll(time.Millisecond*500, time.Second*10, func() (bool, error) {
By("getting the auto-created API token") By("getting the auto-created API token")
tokenSelector := fields.SelectorFromSet(map[string]string{client.SecretType: string(api.SecretTypeServiceAccountToken)}) tokenSelector := fields.SelectorFromSet(map[string]string{client.SecretType: string(api.SecretTypeServiceAccountToken)})
secrets, err := c.Secrets(ns).List(labels.Everything(), tokenSelector) secrets, err := f.Client.Secrets(f.Namespace.Name).List(labels.Everything(), tokenSelector)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -94,8 +75,8 @@ var _ = Describe("ServiceAccounts", func() {
}, },
} }
testContainerOutputInNamespace("consume service account token", c, pod, []string{ f.TestContainerOutput("consume service account token", pod, []string{
fmt.Sprintf(`content of file "%s/%s": %s`, serviceaccount.DefaultAPITokenMountPath, api.ServiceAccountTokenKey, tokenContent), fmt.Sprintf(`content of file "%s/%s": %s`, serviceaccount.DefaultAPITokenMountPath, api.ServiceAccountTokenKey, tokenContent),
}, ns) })
}) })
}) })