From caad45d0edd9c1e48eac6e0ae0889039ca6844fc Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 18 Apr 2014 03:12:27 +0000 Subject: [PATCH] Port networking tests Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- integration-cli/docker_cli_run_test.go | 43 +++++++++++ integration/container_test.go | 100 ------------------------- 2 files changed, 43 insertions(+), 100 deletions(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 5474bff158..d50adeafcf 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -560,3 +560,46 @@ func TestEnvironment(t *testing.T) { logDone("run - verify environment") } + +func TestContainerNetwork(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "busybox", "ping", "-c", "1", "127.0.0.1") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + deleteAllContainers() + + logDone("run - test container network via ping") +} + +// Issue #4681 +func TestLoopbackWhenNetworkDisabled(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "--networking=false", "busybox", "ping", "-c", "1", "127.0.0.1") + if _, err := runCommand(cmd); err != nil { + t.Fatal(err) + } + + deleteAllContainers() + + logDone("run - test container loopback when networking disabled") +} + +func TestLoopbackOnlyExistsWhenNetworkingDisabled(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "--networking=false", "busybox", "ip", "a", "show", "up") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + + interfaces := regexp.MustCompile(`(?m)^[0-9]+: [a-zA-Z0-9]+`).FindAllString(out, -1) + if len(interfaces) != 1 { + t.Fatalf("Wrong interface count in test container: expected [*: lo], got %s", interfaces) + } + if !strings.HasSuffix(interfaces[0], ": lo") { + t.Fatalf("Wrong interface in test container: expected [*: lo], got %s", interfaces) + } + + deleteAllContainers() + + logDone("run - test loopback only exists when networking disabled") +} diff --git a/integration/container_test.go b/integration/container_test.go index 1e64beab43..bce3a9628f 100644 --- a/integration/container_test.go +++ b/integration/container_test.go @@ -583,106 +583,6 @@ func TestRestartWithVolumes(t *testing.T) { } } -func TestContainerNetwork(t *testing.T) { - daemon := mkDaemon(t) - defer nuke(daemon) - container, _, err := daemon.Create( - &runconfig.Config{ - Image: GetTestImage(daemon).ID, - // If I change this to ping 8.8.8.8 it fails. Any idea why? - timthelion - Cmd: []string{"ping", "-c", "1", "127.0.0.1"}, - }, - "", - ) - if err != nil { - t.Fatal(err) - } - defer daemon.Destroy(container) - if err := container.Run(); err != nil { - t.Fatal(err) - } - if code := container.State.GetExitCode(); code != 0 { - t.Fatalf("Unexpected ping 127.0.0.1 exit code %d (expected 0)", code) - } -} - -// Issue #4681 -func TestLoopbackFunctionsWhenNetworkingIsDissabled(t *testing.T) { - daemon := mkDaemon(t) - defer nuke(daemon) - container, _, err := daemon.Create( - &runconfig.Config{ - Image: GetTestImage(daemon).ID, - Cmd: []string{"ping", "-c", "1", "127.0.0.1"}, - NetworkDisabled: true, - }, - "", - ) - if err != nil { - t.Fatal(err) - } - defer daemon.Destroy(container) - if err := container.Run(); err != nil { - t.Fatal(err) - } - if code := container.State.GetExitCode(); code != 0 { - t.Fatalf("Unexpected ping 127.0.0.1 exit code %d (expected 0)", code) - } -} - -func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) { - eng := NewTestEngine(t) - daemon := mkDaemonFromEngine(eng, t) - defer nuke(daemon) - - config, hc, _, err := runconfig.Parse([]string{"-n=false", GetTestImage(daemon).ID, "ip", "addr", "show", "up"}, nil) - if err != nil { - t.Fatal(err) - } - - jobCreate := eng.Job("create") - if err := jobCreate.ImportEnv(config); err != nil { - t.Fatal(err) - } - var id string - jobCreate.Stdout.AddString(&id) - if err := jobCreate.Run(); err != nil { - t.Fatal(err) - } - // FIXME: this hack can be removed once Wait is a job - c := daemon.Get(id) - if c == nil { - t.Fatalf("Couldn't retrieve container %s from daemon", id) - } - stdout, err := c.StdoutPipe() - if err != nil { - t.Fatal(err) - } - - jobStart := eng.Job("start", id) - if err := jobStart.ImportEnv(hc); err != nil { - t.Fatal(err) - } - if err := jobStart.Run(); err != nil { - t.Fatal(err) - } - - c.WaitTimeout(500 * time.Millisecond) - c.Wait() - output, err := ioutil.ReadAll(stdout) - if err != nil { - t.Fatal(err) - } - - interfaces := regexp.MustCompile(`(?m)^[0-9]+: [a-zA-Z0-9]+`).FindAllString(string(output), -1) - if len(interfaces) != 1 { - t.Fatalf("Wrong interface count in test container: expected [*: lo], got %s", interfaces) - } - if !strings.HasSuffix(interfaces[0], ": lo") { - t.Fatalf("Wrong interface in test container: expected [*: lo], got %s", interfaces) - } -} - func TestPrivilegedCanMknod(t *testing.T) { eng := NewTestEngine(t) daemon := mkDaemonFromEngine(eng, t)