Start e2e framework; print events
This commit is contained in:
@@ -19,10 +19,10 @@ package e2e
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
@@ -31,20 +31,17 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func LaunchNetTestPodPerNode(nodes *api.NodeList, name string, c *client.Client, ns string) []string {
|
||||
func LaunchNetTestPodPerNode(f *Framework, nodes *api.NodeList, name string) []string {
|
||||
podNames := []string{}
|
||||
|
||||
totalPods := len(nodes.Items)
|
||||
|
||||
Expect(totalPods).NotTo(Equal(0))
|
||||
|
||||
for i, node := range nodes.Items {
|
||||
podName := fmt.Sprintf("%s-%d", name, i)
|
||||
podNames = append(podNames, podName)
|
||||
Logf("Creating pod %s on node %s", podName, node.Name)
|
||||
_, err := c.Pods(ns).Create(&api.Pod{
|
||||
for _, node := range nodes.Items {
|
||||
pod, err := f.Client.Pods(f.Namespace.Name).Create(&api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: podName,
|
||||
GenerateName: name + "-",
|
||||
Labels: map[string]string{
|
||||
"name": name,
|
||||
},
|
||||
@@ -59,7 +56,7 @@ func LaunchNetTestPodPerNode(nodes *api.NodeList, name string, c *client.Client,
|
||||
//peers >= totalPods should be asserted by the container.
|
||||
//the nettest container finds peers by looking up list of svc endpoints.
|
||||
fmt.Sprintf("-peers=%d", totalPods),
|
||||
"-namespace=" + ns},
|
||||
"-namespace=" + f.Namespace.Name},
|
||||
Ports: []api.ContainerPort{{ContainerPort: 8080}},
|
||||
},
|
||||
},
|
||||
@@ -68,16 +65,16 @@ func LaunchNetTestPodPerNode(nodes *api.NodeList, name string, c *client.Client,
|
||||
},
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Logf("Created pod %s on node %s", pod.ObjectMeta.Name, node.Name)
|
||||
podNames = append(podNames, pod.ObjectMeta.Name)
|
||||
}
|
||||
return podNames
|
||||
}
|
||||
|
||||
var _ = Describe("Networking", func() {
|
||||
f := NewFramework("nettest")
|
||||
|
||||
//This namespace is modified throughout the course of the test.
|
||||
var namespace *api.Namespace
|
||||
var svcname = "nettest"
|
||||
var c *client.Client = nil
|
||||
|
||||
BeforeEach(func() {
|
||||
//Assert basic external connectivity.
|
||||
@@ -91,22 +88,6 @@ var _ = Describe("Networking", func() {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
Failf("Unexpected error code, expected 200, got, %v (%v)", resp.StatusCode, resp)
|
||||
}
|
||||
|
||||
By("Creating a kubernetes client")
|
||||
c, err = loadClient()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Building a namespace api object")
|
||||
namespace, err = createTestingNS("nettest", c)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
By(fmt.Sprintf("Destroying namespace for this suite %v", namespace.Name))
|
||||
if err := c.Namespaces().Delete(namespace.Name); err != nil {
|
||||
Failf("Couldn't delete ns %s", err)
|
||||
}
|
||||
})
|
||||
|
||||
// First test because it has no dependencies on variables created later on.
|
||||
@@ -120,8 +101,8 @@ var _ = Describe("Networking", func() {
|
||||
}
|
||||
for _, test := range tests {
|
||||
By(fmt.Sprintf("testing: %s", test.path))
|
||||
data, err := c.RESTClient.Get().
|
||||
Namespace(namespace.Name).
|
||||
data, err := f.Client.RESTClient.Get().
|
||||
Namespace(f.Namespace.Name).
|
||||
AbsPath(test.path).
|
||||
DoRaw()
|
||||
if err != nil {
|
||||
@@ -139,8 +120,8 @@ var _ = Describe("Networking", func() {
|
||||
return
|
||||
}
|
||||
|
||||
By(fmt.Sprintf("Creating a service named [%s] in namespace %s", svcname, namespace.Name))
|
||||
svc, err := c.Services(namespace.Name).Create(&api.Service{
|
||||
By(fmt.Sprintf("Creating a service named %q in namespace %q", svcname, f.Namespace.Name))
|
||||
svc, err := f.Client.Services(f.Namespace.Name).Create(&api.Service{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: svcname,
|
||||
Labels: map[string]string{
|
||||
@@ -166,26 +147,26 @@ var _ = Describe("Networking", func() {
|
||||
defer func() {
|
||||
defer GinkgoRecover()
|
||||
By("Cleaning up the service")
|
||||
if err = c.Services(namespace.Name).Delete(svc.Name); err != nil {
|
||||
if err = f.Client.Services(f.Namespace.Name).Delete(svc.Name); err != nil {
|
||||
Failf("unable to delete svc %v: %v", svc.Name, err)
|
||||
}
|
||||
}()
|
||||
|
||||
By("Creating a webserver (pending) pod on each node")
|
||||
|
||||
nodes, err := c.Nodes().List(labels.Everything(), fields.Everything())
|
||||
nodes, err := f.Client.Nodes().List(labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
Failf("Failed to list nodes: %v", err)
|
||||
}
|
||||
|
||||
podNames := LaunchNetTestPodPerNode(nodes, svcname, c, namespace.Name)
|
||||
podNames := LaunchNetTestPodPerNode(f, nodes, svcname)
|
||||
|
||||
// Clean up the pods
|
||||
defer func() {
|
||||
defer GinkgoRecover()
|
||||
By("Cleaning up the webserver pods")
|
||||
for _, podName := range podNames {
|
||||
if err = c.Pods(namespace.Name).Delete(podName, nil); err != nil {
|
||||
if err = f.Client.Pods(f.Namespace.Name).Delete(podName, nil); err != nil {
|
||||
Logf("Failed to delete pod %s: %v", podName, err)
|
||||
}
|
||||
}
|
||||
@@ -193,63 +174,67 @@ var _ = Describe("Networking", func() {
|
||||
|
||||
By("Waiting for the webserver pods to transition to Running state")
|
||||
for _, podName := range podNames {
|
||||
err = waitForPodRunningInNamespace(c, podName, namespace.Name)
|
||||
err = f.WaitForPodRunning(podName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
By("Waiting for connectivity to be verified")
|
||||
const maxAttempts = 60
|
||||
passed := false
|
||||
|
||||
//once response OK, evaluate response body for pass/fail.
|
||||
var body []byte
|
||||
getDetails := func() ([]byte, error) {
|
||||
return f.Client.Get().
|
||||
Namespace(f.Namespace.Name).
|
||||
Prefix("proxy").
|
||||
Resource("services").
|
||||
Name(svc.Name).
|
||||
Suffix("read").
|
||||
DoRaw()
|
||||
}
|
||||
|
||||
for i := 0; i < maxAttempts && !passed; i++ {
|
||||
time.Sleep(2 * time.Second)
|
||||
Logf("About to make a proxy status call")
|
||||
start := time.Now()
|
||||
body, err = c.Get().
|
||||
Namespace(namespace.Name).
|
||||
getStatus := func() ([]byte, error) {
|
||||
return f.Client.Get().
|
||||
Namespace(f.Namespace.Name).
|
||||
Prefix("proxy").
|
||||
Resource("services").
|
||||
Name(svc.Name).
|
||||
Suffix("status").
|
||||
DoRaw()
|
||||
}
|
||||
|
||||
for i := 0; !passed; i++ { // Timeout will keep us from going forever.
|
||||
time.Sleep(2 * time.Second)
|
||||
Logf("About to make a proxy status call")
|
||||
start := time.Now()
|
||||
body, err = getStatus()
|
||||
Logf("Proxy status call returned in %v", time.Since(start))
|
||||
if err != nil {
|
||||
Logf("Attempt %v/%v: service/pod still starting. (error: '%v')", i, maxAttempts, err)
|
||||
Logf("Attempt %v: service/pod still starting. (error: '%v')", i, err)
|
||||
continue
|
||||
}
|
||||
//Finally, we pass/fail the test based on if the container's response body, as to wether or not it was able to find peers.
|
||||
switch string(body) {
|
||||
case "pass":
|
||||
// Finally, we pass/fail the test based on if the container's response body, as to wether or not it was able to find peers.
|
||||
switch {
|
||||
case string(body) == "pass":
|
||||
Logf("Passed on attempt %v. Cleaning up.", i)
|
||||
passed = true
|
||||
case "running":
|
||||
Logf("Attempt %v/%v: test still running", i, maxAttempts)
|
||||
case "fail":
|
||||
if body, err = c.Get().
|
||||
Namespace(namespace.Name).Prefix("proxy").
|
||||
Resource("services").
|
||||
Name(svc.Name).Suffix("read").
|
||||
DoRaw(); err != nil {
|
||||
case string(body) == "running":
|
||||
Logf("Attempt %v: test still running", i)
|
||||
case string(body) == "fail":
|
||||
if body, err = getDetails(); err != nil {
|
||||
Failf("Failed on attempt %v. Cleaning up. Error reading details: %v", i, err)
|
||||
} else {
|
||||
Failf("Failed on attempt %v. Cleaning up. Details:\n%s", i, string(body))
|
||||
}
|
||||
case strings.Contains(string(body), "no endpoints available"):
|
||||
Logf("Attempt %v: waiting on service/endpoints", i)
|
||||
default:
|
||||
Logf("Unexpected response: %q", body)
|
||||
Logf("Unexpected response:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
if !passed {
|
||||
if body, err = c.Get().
|
||||
Namespace(namespace.Name).
|
||||
Prefix("proxy").
|
||||
Resource("services").
|
||||
Name(svc.Name).
|
||||
Suffix("read").
|
||||
DoRaw(); err != nil {
|
||||
if body, err = getDetails(); err != nil {
|
||||
Failf("Timed out. Cleaning up. Error reading details: %v", err)
|
||||
} else {
|
||||
Failf("Timed out. Cleaning up. Details:\n%s", string(body))
|
||||
|
Reference in New Issue
Block a user