Commit e9591382 authored by Filipe Brandenburger's avatar Filipe Brandenburger

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.
parent 5d2ea04b
...@@ -32,27 +32,28 @@ import ( ...@@ -32,27 +32,28 @@ import (
) )
func runLivenessTest(c *client.Client, podDescr *api.Pod) bool { func runLivenessTest(c *client.Client, podDescr *api.Pod) bool {
glog.Infof("Creating pod %s", podDescr.Name) ns := "e2e-test-" + string(util.NewUUID())
_, err := c.Pods(api.NamespaceDefault).Create(podDescr) glog.Infof("Creating pod %s in namespace %s", podDescr.Name, ns)
_, err := c.Pods(ns).Create(podDescr)
if err != nil { if err != nil {
glog.Infof("Failed to create pod %s: %v", podDescr.Name, err) glog.Infof("Failed to create pod %s: %v", podDescr.Name, err)
return false return false
} }
// At the end of the test, clean up by removing the pod. // 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 // 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 // 'Pending' other than checking for 'Running', since when failures occur, we go to
// 'Terminated' which can cause indefinite blocking.) // 'Terminated' which can cause indefinite blocking.)
if !waitForPodNotPending(c, podDescr.Name) { if !waitForPodNotPending(c, ns, podDescr.Name) {
glog.Infof("Failed to start pod %s", podDescr.Name) glog.Infof("Failed to start pod %s in namespace %s", podDescr.Name, ns)
return false 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. // 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 { 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 return false
} }
initialRestartCount := pod.Status.Info["liveness"].RestartCount initialRestartCount := pod.Status.Info["liveness"].RestartCount
...@@ -62,29 +63,28 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) bool { ...@@ -62,29 +63,28 @@ func runLivenessTest(c *client.Client, podDescr *api.Pod) bool {
for i := 0; i < 48; i++ { for i := 0; i < 48; i++ {
// Wait until restartCount is incremented. // Wait until restartCount is incremented.
time.Sleep(5 * time.Second) 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 { if err != nil {
glog.Errorf("Get pod %s failed: %v", podDescr.Name, err) glog.Errorf("Get pod %s failed: %v", podDescr.Name, err)
return false return false
} }
restartCount := pod.Status.Info["liveness"].RestartCount 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 { 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 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 return false
} }
// TestLivenessHttp tests restarts with a /healthz http liveness probe. // TestLivenessHttp tests restarts with a /healthz http liveness probe.
func TestLivenessHttp(c *client.Client) bool { func TestLivenessHttp(c *client.Client) bool {
name := "liveness-http-" + string(util.NewUUID())
return runLivenessTest(c, &api.Pod{ return runLivenessTest(c, &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: name, Name: "liveness-http",
Labels: map[string]string{"test": "liveness"}, Labels: map[string]string{"test": "liveness"},
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
...@@ -110,10 +110,9 @@ func TestLivenessHttp(c *client.Client) bool { ...@@ -110,10 +110,9 @@ func TestLivenessHttp(c *client.Client) bool {
// TestLivenessExec tests restarts with a docker exec "cat /tmp/health" liveness probe. // TestLivenessExec tests restarts with a docker exec "cat /tmp/health" liveness probe.
func TestLivenessExec(c *client.Client) bool { func TestLivenessExec(c *client.Client) bool {
name := "liveness-exec-" + string(util.NewUUID())
return runLivenessTest(c, &api.Pod{ return runLivenessTest(c, &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: name, Name: "liveness-exec",
Labels: map[string]string{"test": "liveness"}, Labels: map[string]string{"test": "liveness"},
}, },
Spec: api.PodSpec{ Spec: api.PodSpec{
......
...@@ -57,23 +57,23 @@ func waitForPodRunning(c *client.Client, id string) { ...@@ -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. // 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++ { for i := 0; i < 10; i++ {
if i > 0 { if i > 0 {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
pod, err := c.Pods(api.NamespaceDefault).Get(podName) pod, err := c.Pods(ns).Get(podName)
if err != nil { 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 continue
} }
if pod.Status.Phase != api.PodPending { 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 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 return false
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment