Signed-off-by: Alexander Morozov <lk4d4@docker.com>
| ... | ... |
@@ -2708,18 +2708,32 @@ func TestRunNonLocalMacAddress(t *testing.T) {
|
| 2708 | 2708 |
|
| 2709 | 2709 |
func TestRunNetHost(t *testing.T) {
|
| 2710 | 2710 |
defer deleteAllContainers() |
| 2711 |
- iplinkHost, err := exec.Command("ip", "link", "list").CombinedOutput()
|
|
| 2711 |
+ hostNet, err := os.Readlink("/proc/1/ns/net")
|
|
| 2712 | 2712 |
if err != nil {
|
| 2713 | 2713 |
t.Fatal(err) |
| 2714 | 2714 |
} |
| 2715 | 2715 |
|
| 2716 |
- iplinkCont, err := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ip", "link", "list").CombinedOutput() |
|
| 2716 |
+ cmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "readlink", "/proc/self/ns/net") |
|
| 2717 |
+ out2, _, err := runCommandWithOutput(cmd) |
|
| 2717 | 2718 |
if err != nil {
|
| 2718 |
- t.Fatal(err) |
|
| 2719 |
+ t.Fatal(err, out2) |
|
| 2719 | 2720 |
} |
| 2720 | 2721 |
|
| 2721 |
- if !bytes.Equal(iplinkHost, iplinkCont) {
|
|
| 2722 |
- t.Fatalf("Container network:\n%s\nis not equal to host network:\n%s", iplinkCont, iplinkHost)
|
|
| 2722 |
+ out2 = strings.Trim(out2, "\n") |
|
| 2723 |
+ if hostNet != out2 {
|
|
| 2724 |
+ t.Fatalf("Net namespace different with --net=host %s != %s\n", hostNet, out2)
|
|
| 2723 | 2725 |
} |
| 2724 |
- logDone("run - host network")
|
|
| 2726 |
+ |
|
| 2727 |
+ cmd = exec.Command(dockerBinary, "run", "busybox", "readlink", "/proc/self/ns/net") |
|
| 2728 |
+ out2, _, err = runCommandWithOutput(cmd) |
|
| 2729 |
+ if err != nil {
|
|
| 2730 |
+ t.Fatal(err, out2) |
|
| 2731 |
+ } |
|
| 2732 |
+ |
|
| 2733 |
+ out2 = strings.Trim(out2, "\n") |
|
| 2734 |
+ if hostNet == out2 {
|
|
| 2735 |
+ t.Fatalf("Net namespace should be different without --net=host %s == %s\n", hostNet, out2)
|
|
| 2736 |
+ } |
|
| 2737 |
+ |
|
| 2738 |
+ logDone("run - net host mode")
|
|
| 2725 | 2739 |
} |