From 259b05fa1edc3a6c613e184dd8da9dcc16692bbc Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 18 Nov 2014 15:10:07 -0800 Subject: [PATCH] Add test for --net container: This adds an integration test for checking that the network namespace fds are the same when a container joins another container's network namespace. Signed-off-by: Michael Crosby Upstream-commit: 71209f75791fdc1a2124682f50cd00a413ddb143 Component: engine --- .../integration-cli/docker_cli_run_test.go | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/components/engine/integration-cli/docker_cli_run_test.go b/components/engine/integration-cli/docker_cli_run_test.go index ce85f7741b..6d0f34f921 100644 --- a/components/engine/integration-cli/docker_cli_run_test.go +++ b/components/engine/integration-cli/docker_cli_run_test.go @@ -2638,3 +2638,37 @@ func TestRunModeIpcContainer(t *testing.T) { logDone("run - hostname and several network modes") } + +func TestContainerNetworkMode(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + id := strings.TrimSpace(out) + if err := waitRun(id); err != nil { + t.Fatal(err) + } + pid1, err := inspectField(id, "State.Pid") + if err != nil { + t.Fatal(err) + } + + parentContainerNet, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1)) + if err != nil { + t.Fatal(err) + } + cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net") + out2, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out2) + } + + out2 = strings.Trim(out2, "\n") + if parentContainerNet != out2 { + t.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out2) + } + deleteAllContainers() + + logDone("run - container shared network namespace") +}