Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a custom namespace for running liveness e2e test cases. #4139

Merged
merged 1 commit into from
Feb 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions test/e2e/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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{
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down