From e9591382a7ea86846c9344063963114d645c4aae Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 4 Feb 2015 16:00:06 -0800 Subject: [PATCH] Use a custom namespace for running liveness e2e test cases. This will allow us greated isolation between test case runs without the need to include randomized uuids to many of the fields in the pods, services and rcs creation requests. Tested: - Ran two instances of `e2e -t TestLivenessHttp -t TestLivenessExec` simultaneously and confirmed that pod names did not clash and that both of them completed successfully. --- test/e2e/liveness.go | 31 +++++++++++++++---------------- test/e2e/util.go | 12 ++++++------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/test/e2e/liveness.go b/test/e2e/liveness.go index 0fca9cc670885..9a5af6a3db5a2 100644 --- a/test/e2e/liveness.go +++ b/test/e2e/liveness.go @@ -32,27 +32,28 @@ import ( ) func runLivenessTest(c *client.Client, podDescr *api.Pod) bool { - glog.Infof("Creating pod %s", podDescr.Name) - _, err := c.Pods(api.NamespaceDefault).Create(podDescr) + ns := "e2e-test-" + string(util.NewUUID()) + glog.Infof("Creating pod %s in namespace %s", podDescr.Name, ns) + _, err := c.Pods(ns).Create(podDescr) if err != nil { glog.Infof("Failed to create pod %s: %v", podDescr.Name, err) return false } // At the end of the test, clean up by removing the pod. - defer c.Pods(api.NamespaceDefault).Delete(podDescr.Name) + defer c.Pods(ns).Delete(podDescr.Name) // Wait until the pod is not pending. (Here we need to check for something other than // 'Pending' other than checking for 'Running', since when failures occur, we go to // 'Terminated' which can cause indefinite blocking.) - if !waitForPodNotPending(c, podDescr.Name) { - glog.Infof("Failed to start pod %s", podDescr.Name) + if !waitForPodNotPending(c, ns, podDescr.Name) { + glog.Infof("Failed to start pod %s in namespace %s", podDescr.Name, ns) return false } - glog.Infof("Started pod %s", podDescr.Name) + glog.Infof("Started pod %s in namespace %s", podDescr.Name, ns) // Check the pod's current state and verify that restartCount is present. - pod, err := c.Pods(api.NamespaceDefault).Get(podDescr.Name) + pod, err := c.Pods(ns).Get(podDescr.Name) if err != nil { - glog.Errorf("Get pod %s failed: %v", podDescr.Name, err) + glog.Errorf("Get pod %s in namespace %s failed: %v", podDescr.Name, ns, err) return false } initialRestartCount := pod.Status.Info["liveness"].RestartCount @@ -62,29 +63,28 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) bool { for i := 0; i < 48; i++ { // Wait until restartCount is incremented. time.Sleep(5 * time.Second) - pod, err = c.Pods(api.NamespaceDefault).Get(podDescr.Name) + pod, err = c.Pods(ns).Get(podDescr.Name) if err != nil { glog.Errorf("Get pod %s failed: %v", podDescr.Name, err) return false } restartCount := pod.Status.Info["liveness"].RestartCount - glog.Infof("Restart count of pod %s is now %d", podDescr.Name, restartCount) + glog.Infof("Restart count of pod %s in namespace %s is now %d", podDescr.Name, ns, restartCount) if restartCount > initialRestartCount { - glog.Infof("Restart count of pod %s increased from %d to %d during the test", podDescr.Name, initialRestartCount, restartCount) + glog.Infof("Restart count of pod %s in namespace %s increased from %d to %d during the test", podDescr.Name, ns, initialRestartCount, restartCount) return true } } - glog.Errorf("Did not see the restart count of pod %s increase from %d during the test", podDescr.Name, initialRestartCount) + glog.Errorf("Did not see the restart count of pod %s in namespace %s increase from %d during the test", podDescr.Name, ns, initialRestartCount) return false } // TestLivenessHttp tests restarts with a /healthz http liveness probe. func TestLivenessHttp(c *client.Client) bool { - name := "liveness-http-" + string(util.NewUUID()) return runLivenessTest(c, &api.Pod{ ObjectMeta: api.ObjectMeta{ - Name: name, + Name: "liveness-http", Labels: map[string]string{"test": "liveness"}, }, Spec: api.PodSpec{ @@ -110,10 +110,9 @@ func TestLivenessHttp(c *client.Client) bool { // TestLivenessExec tests restarts with a docker exec "cat /tmp/health" liveness probe. func TestLivenessExec(c *client.Client) bool { - name := "liveness-exec-" + string(util.NewUUID()) return runLivenessTest(c, &api.Pod{ ObjectMeta: api.ObjectMeta{ - Name: name, + Name: "liveness-exec", Labels: map[string]string{"test": "liveness"}, }, Spec: api.PodSpec{ diff --git a/test/e2e/util.go b/test/e2e/util.go index 07befd14dcf5b..266980fbb73d3 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -57,23 +57,23 @@ func waitForPodRunning(c *client.Client, id string) { } // waitForPodNotPending returns false if it took too long for the pod to go out of pending state. -func waitForPodNotPending(c *client.Client, podName string) bool { +func waitForPodNotPending(c *client.Client, ns, podName string) bool { for i := 0; i < 10; i++ { if i > 0 { time.Sleep(5 * time.Second) } - pod, err := c.Pods(api.NamespaceDefault).Get(podName) + pod, err := c.Pods(ns).Get(podName) if err != nil { - glog.Warningf("Get pod %s failed: %v", podName, err) + glog.Warningf("Get pod %s in namespace %s failed: %v", podName, ns, err) continue } if pod.Status.Phase != api.PodPending { - glog.Infof("Saw pod %s out of pending state (found %q)", podName, pod.Status.Phase) + glog.Infof("Saw pod %s in namespace %s out of pending state (found %q)", podName, ns, pod.Status.Phase) return true } - glog.Infof("Waiting for pod %s status to be !%q (found %q)", podName, api.PodPending, pod.Status.Phase) + glog.Infof("Waiting for status of pod %s in namespace %s to be !%q (found %q)", podName, ns, api.PodPending, pod.Status.Phase) } - glog.Warningf("Gave up waiting for pod %s status to go out of pending", podName) + glog.Warningf("Gave up waiting for status of pod %s in namespace %s to go out of pending", podName, ns) return false }