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 <crosbymichael@gmail.com>
| ... | ... |
@@ -2638,3 +2638,37 @@ func TestRunModeIpcContainer(t *testing.T) {
|
| 2638 | 2638 |
|
| 2639 | 2639 |
logDone("run - hostname and several network modes")
|
| 2640 | 2640 |
} |
| 2641 |
+ |
|
| 2642 |
+func TestContainerNetworkMode(t *testing.T) {
|
|
| 2643 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") |
|
| 2644 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 2645 |
+ if err != nil {
|
|
| 2646 |
+ t.Fatal(err, out) |
|
| 2647 |
+ } |
|
| 2648 |
+ id := strings.TrimSpace(out) |
|
| 2649 |
+ if err := waitRun(id); err != nil {
|
|
| 2650 |
+ t.Fatal(err) |
|
| 2651 |
+ } |
|
| 2652 |
+ pid1, err := inspectField(id, "State.Pid") |
|
| 2653 |
+ if err != nil {
|
|
| 2654 |
+ t.Fatal(err) |
|
| 2655 |
+ } |
|
| 2656 |
+ |
|
| 2657 |
+ parentContainerNet, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1))
|
|
| 2658 |
+ if err != nil {
|
|
| 2659 |
+ t.Fatal(err) |
|
| 2660 |
+ } |
|
| 2661 |
+ cmd = exec.Command(dockerBinary, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net")
|
|
| 2662 |
+ out2, _, err := runCommandWithOutput(cmd) |
|
| 2663 |
+ if err != nil {
|
|
| 2664 |
+ t.Fatal(err, out2) |
|
| 2665 |
+ } |
|
| 2666 |
+ |
|
| 2667 |
+ out2 = strings.Trim(out2, "\n") |
|
| 2668 |
+ if parentContainerNet != out2 {
|
|
| 2669 |
+ t.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out2)
|
|
| 2670 |
+ } |
|
| 2671 |
+ deleteAllContainers() |
|
| 2672 |
+ |
|
| 2673 |
+ logDone("run - container shared network namespace")
|
|
| 2674 |
+} |