MCPcopy
hub / github.com/moby/moby / TestRunContainerWithBridgeNone

Function TestRunContainerWithBridgeNone

integration/network/network_linux_test.go:29–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestRunContainerWithBridgeNone(t *testing.T) {
30 skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")
31 skip.If(t, testEnv.IsUserNamespace)
32
33 ctx := testutil.StartSpan(baseContext, t)
34
35 d := daemon.New(t)
36 d.StartWithBusybox(ctx, t, "-b", "none")
37 defer d.Stop(t)
38
39 c := d.NewClientT(t)
40
41 id1 := container.Run(ctx, t, c)
42 defer c.ContainerRemove(ctx, id1, client.ContainerRemoveOptions{Force: true})
43
44 result, err := container.Exec(ctx, c, id1, []string{"ip", "l"})
45 assert.NilError(t, err)
46 assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled")
47
48 id2 := container.Run(ctx, t, c, container.WithNetworkMode("bridge"))
49 defer c.ContainerRemove(ctx, id2, client.ContainerRemoveOptions{Force: true})
50
51 result, err = container.Exec(ctx, c, id2, []string{"ip", "l"})
52 assert.NilError(t, err)
53 assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in bridge mode when bridge network is disabled")
54
55 nsCommand := "ls -l /proc/self/ns/net | awk -F '->' '{print $2}'"
56 cmd := exec.Command("sh", "-c", nsCommand)
57 stdout := bytes.NewBuffer(nil)
58 cmd.Stdout = stdout
59 err = cmd.Run()
60 assert.NilError(t, err, "Failed to get current process network namespace: %+v", err)
61
62 id3 := container.Run(ctx, t, c, container.WithNetworkMode("host"))
63 defer c.ContainerRemove(ctx, id3, client.ContainerRemoveOptions{Force: true})
64
65 result, err = container.Exec(ctx, c, id3, []string{"sh", "-c", nsCommand})
66 assert.NilError(t, err)
67 assert.Check(t, is.Equal(stdout.String(), result.Combined()), "The network namespace of container should be the same with host when --net=host and bridge network is disabled")
68}
69
70func TestHostIPv4BridgeLabel(t *testing.T) {
71 skip.If(t, testEnv.IsRemoteDaemon)

Callers

nothing calls this directly

Calls 15

StartSpanFunction · 0.92
NewFunction · 0.92
RunFunction · 0.92
ExecFunction · 0.92
WithNetworkModeFunction · 0.92
StartWithBusyboxMethod · 0.80
NewClientTMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
CombinedMethod · 0.80
ContainerRemoveMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…