Skip to content

Commit

Permalink
Merge pull request kubernetes#5600 from satnam6502/network
Browse files Browse the repository at this point in the history
Make networking e2e test run in its own namespace
  • Loading branch information
zmerlynn committed Mar 18, 2015
2 parents c342008 + 7cd102e commit f7cd28a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test/e2e/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var _ = Describe("Networking", func() {
Expect(err).NotTo(HaveOccurred())
})

// Create a unique namespace for this test.
ns := "nettest-" + randomSuffix()

It("should function for pods", func() {
if testContext.provider == "vagrant" {
By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
Expand All @@ -54,10 +57,7 @@ var _ = Describe("Networking", func() {
Fail(fmt.Sprintf("unexpected error code. expected 200, got: %v (%v)", resp.StatusCode, resp))
}

ns := api.NamespaceDefault
// TODO(satnam6502): Replace call of randomSuffix with call to NewUUID when service
// names have the same form as pod and replication controller names.
name := "nettest-" + randomSuffix()
name := "nettest"

svc, err := c.Services(ns).Create(&api.Service{
ObjectMeta: api.ObjectMeta{
Expand All @@ -74,7 +74,7 @@ var _ = Describe("Networking", func() {
},
},
})
By(fmt.Sprintf("Creating service with name %s", svc.Name))
By(fmt.Sprintf("Creating service with name %s in namespace %s", svc.Name, ns))
if err != nil {
Fail(fmt.Sprintf("unable to create test service %s: %v", svc.Name, err))
}
Expand Down Expand Up @@ -109,7 +109,7 @@ var _ = Describe("Networking", func() {
{
Name: "webserver",
Image: "kubernetes/nettest:latest",
Command: []string{"-service=" + name},
Command: []string{"-service=" + name, "-namespace=" + ns},
Ports: []api.ContainerPort{{ContainerPort: 8080}},
},
},
Expand Down Expand Up @@ -140,7 +140,7 @@ var _ = Describe("Networking", func() {
var body []byte
for i := 0; i < maxAttempts && !passed; i++ {
time.Sleep(2 * time.Second)
body, err = c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("status").Do().Raw()
body, err = c.Get().Namespace(ns).Prefix("proxy").Resource("services").Name(svc.Name).Suffix("status").Do().Raw()
if err != nil {
fmt.Printf("Attempt %v/%v: service/pod still starting. (error: '%v')\n", i, maxAttempts, err)
continue
Expand All @@ -154,7 +154,7 @@ var _ = Describe("Networking", func() {
fmt.Printf("Attempt %v/%v: test still running\n", i, maxAttempts)
break
case "fail":
if body, err = c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("read").Do().Raw(); err != nil {
if body, err = c.Get().Namespace(ns).Prefix("proxy").Resource("services").Name(svc.Name).Suffix("read").Do().Raw(); err != nil {
Fail(fmt.Sprintf("Failed on attempt %v. Cleaning up. Error reading details: %v", i, err))
} else {
Fail(fmt.Sprintf("Failed on attempt %v. Cleaning up. Details:\n%v", i, string(body)))
Expand All @@ -164,7 +164,13 @@ var _ = Describe("Networking", func() {
}

if !passed {
if body, err = c.Get().Prefix("proxy").Resource("services").Name(svc.Name).Suffix("read").Do().Raw(); err != nil {
if body, err = c.Get().
Namespace(ns).
Prefix("proxy").
Resource("services").
Name(svc.Name).
Suffix("read").
Do().Raw(); err != nil {
Fail(fmt.Sprintf("Timed out. Cleaning up. Error reading details: %v", err))
} else {
Fail(fmt.Sprintf("Timed out. Cleaning up. Details:\n%v", string(body)))
Expand All @@ -184,6 +190,7 @@ var _ = Describe("Networking", func() {
for _, test := range tests {
By(fmt.Sprintf("testing: %s", test.path))
data, err := c.RESTClient.Get().
Namespace(ns).
AbsPath(test.path).
Do().
Raw()
Expand Down

0 comments on commit f7cd28a

Please sign in to comment.