зеркало из https://github.com/microsoft/docker.git
Merge pull request #9226 from crosbymichael/container-net-test
Add test for --net container:<id>
This commit is contained in:
Коммит
739d917d70
|
@ -2653,3 +2653,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")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче