Node e2e: switch most of the tests to use the e2e framework

This commit switches the tests to use the e2e framework, so that namespace
creation/deletion is handled between tests.
pull/6/head
Yu-Ju Hong 2016-06-13 15:10:36 -07:00 committed by Random-Liu
parent 6e5faf59b2
commit 2b65b5a283
5 changed files with 34 additions and 75 deletions

View File

@ -21,23 +21,16 @@ import (
"time"
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Kubelet Container Manager", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
var _ = framework.KubeDescribe("Kubelet Container Manager", func() {
f := NewDefaultFramework("kubelet-container-manager")
Describe("oom score adjusting", func() {
namespace := "oom-adj"
Context("when scheduling a busybox command that always fails in a pod", func() {
var podName string
@ -46,7 +39,7 @@ var _ = Describe("Kubelet Container Manager", func() {
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: podName,
Namespace: namespace,
Namespace: f.Namespace.Name,
},
Spec: api.PodSpec{
// Force the Pod to schedule to the node without a scheduler running
@ -63,13 +56,13 @@ var _ = Describe("Kubelet Container Manager", func() {
},
}
_, err := cl.Pods(namespace).Create(pod)
_, err := f.Client.Pods(f.Namespace.Name).Create(pod)
Expect(err).To(BeNil(), fmt.Sprintf("Error creating Pod %v", err))
})
It("it should have an error terminated reason", func() {
It("should have an error terminated reason", func() {
Eventually(func() error {
podData, err := cl.Pods(namespace).Get(podName)
podData, err := f.Client.Pods(f.Namespace.Name).Get(podName)
if err != nil {
return err
}
@ -87,22 +80,10 @@ var _ = Describe("Kubelet Container Manager", func() {
}, time.Minute, time.Second*4).Should(BeNil())
})
It("it should be possible to delete", func() {
err := cl.Pods(namespace).Delete(podName, &api.DeleteOptions{})
It("should be possible to delete", func() {
err := f.Client.Pods(f.Namespace.Name).Delete(podName, &api.DeleteOptions{})
Expect(err).To(BeNil(), fmt.Sprintf("Error deleting Pod %v", err))
})
AfterEach(func() {
cl.Pods(namespace).Delete(podName, &api.DeleteOptions{})
Eventually(func() bool {
_, err := cl.Pods(namespace).Get(podName)
if err != nil && apierrs.IsNotFound(err) {
return true
}
return false
}, time.Minute, time.Second*4).Should(BeTrue())
})
})
})

View File

@ -19,9 +19,6 @@ package e2e_node
import (
"time"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -34,13 +31,6 @@ const (
)
var _ = Describe("Image Container Conformance Test", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
Describe("[FLAKY] image conformance blackbox test", func() {
Context("when testing images that exist", func() {
var conformImages []ConformanceImage

View File

@ -38,9 +38,8 @@ import (
)
var _ = framework.KubeDescribe("Kubelet", func() {
f := NewDefaultFramework("kubelet-test")
Context("when scheduling a busybox command in a pod", func() {
// Setup the framework
f := NewDefaultFramework("pod-scheduling")
podName := "busybox-scheduling-" + string(util.NewUUID())
It("it should print the output to logs", func() {
podClient := f.Client.Pods(f.Namespace.Name)
@ -81,7 +80,6 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
Context("when scheduling a read only busybox container", func() {
f := NewDefaultFramework("pod-scheduling")
podName := "busybox-readonly-fs" + string(util.NewUUID())
It("it should not write to root filesystem", func() {
podClient := f.Client.Pods(f.Namespace.Name)
@ -123,8 +121,6 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
})
Describe("metrics api", func() {
// Setup the framework
f := NewDefaultFramework("kubelet-metrics-api")
Context("when querying /stats/summary", func() {
It("it should report resource usage through the stats api", func() {
podNamePrefix := "stats-busybox-" + string(util.NewUUID())

View File

@ -24,25 +24,21 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("MirrorPod", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
ns := "mirror-pod"
var _ = framework.KubeDescribe("MirrorPod", func() {
f := NewDefaultFramework("mirror-pod")
Context("when create a mirror pod ", func() {
var staticPodName, mirrorPodName string
BeforeEach(func() {
ns := f.Namespace.Name
staticPodName = "static-pod-" + string(util.NewUUID())
mirrorPodName = staticPodName + "-" + e2es.nodeName
@ -52,12 +48,13 @@ var _ = Describe("MirrorPod", func() {
By("wait for the mirror pod to be running")
Eventually(func() error {
return checkMirrorPodRunning(cl, mirrorPodName, ns)
return checkMirrorPodRunning(f.Client, mirrorPodName, ns)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
It("should be updated when static pod updated", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
@ -68,53 +65,56 @@ var _ = Describe("MirrorPod", func() {
By("wait for the mirror pod to be updated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
By("check the mirror pod container image is updated")
pod, err = cl.Pods(ns).Get(mirrorPodName)
pod, err = f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
Expect(len(pod.Spec.Containers)).Should(Equal(1))
Expect(pod.Spec.Containers[0].Image).Should(Equal(image))
})
It("should be recreated when mirror pod gracefully deleted", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
By("delete the mirror pod with grace period 30s")
err = cl.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(30))
err = f.Client.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(30))
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to be recreated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
It("should be recreated when mirror pod forcibly deleted", func() {
ns := f.Namespace.Name
By("get mirror pod uid")
pod, err := cl.Pods(ns).Get(mirrorPodName)
pod, err := f.Client.Pods(ns).Get(mirrorPodName)
Expect(err).ShouldNot(HaveOccurred())
uid := pod.UID
By("delete the mirror pod with grace period 0s")
err = cl.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(0))
err = f.Client.Pods(ns).Delete(mirrorPodName, api.NewDeleteOptions(0))
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to be recreated")
Eventually(func() error {
return checkMirrorPodRecreatedAndRunnig(cl, mirrorPodName, ns, uid)
return checkMirrorPodRecreatedAndRunnig(f.Client, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
AfterEach(func() {
ns := f.Namespace.Name
By("delete the static pod")
err := deleteStaticPod(e2es.kubeletStaticPodDir, staticPodName, ns)
Expect(err).ShouldNot(HaveOccurred())
By("wait for the mirror pod to disappear")
Eventually(func() error {
return checkMirrorPodDisappear(cl, mirrorPodName, ns)
return checkMirrorPodDisappear(f.Client, mirrorPodName, ns)
}, 2*time.Minute, time.Second*4).Should(BeNil())
})
})

View File

@ -24,8 +24,6 @@ import (
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/restclient"
client "k8s.io/kubernetes/pkg/client/unversioned"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -48,15 +46,9 @@ type testCase struct {
}
var _ = Describe("Container Runtime Conformance Test", func() {
var cl *client.Client
BeforeEach(func() {
// Setup the apiserver client
cl = client.NewOrDie(&restclient.Config{Host: *apiServerAddress})
})
f := NewDefaultFramework("runtime-conformance")
Describe("container runtime conformance blackbox test", func() {
namespace := "runtime-conformance"
Context("when starting a container that exits", func() {
It("it should run with the expected status [Conformance]", func() {
@ -108,11 +100,11 @@ while true; do sleep 1; done
testContainer.Command = []string{"sh", "-c", tmpCmd}
terminateContainer := ConformanceContainer{
Container: testContainer,
Client: cl,
Client: f.Client,
RestartPolicy: testCase.RestartPolicy,
Volumes: testVolumes,
NodeName: *nodeName,
Namespace: namespace,
Namespace: f.Namespace.Name,
}
Expect(terminateContainer.Create()).To(Succeed())
defer terminateContainer.Delete()
@ -152,10 +144,10 @@ while true; do sleep 1; done
testContainer.Name = testCase.Name
invalidImageContainer := ConformanceContainer{
Container: testContainer,
Client: cl,
Client: f.Client,
RestartPolicy: testCase.RestartPolicy,
NodeName: *nodeName,
Namespace: namespace,
Namespace: f.Namespace.Name,
}
Expect(invalidImageContainer.Create()).To(Succeed())
defer invalidImageContainer.Delete()