Browse code

TestDaemonRestartIpcMode: modernize

Move the test case from integration-cli to integration.

The test logic itself has not changed, except these
two things:

* the new test sets default-ipc-mode via command line
rather than via daemon.json (less code);
* the new test uses current API version.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2019/02/15 10:08:00
Showing 2 changed files
... ...
@@ -2896,47 +2896,6 @@ func (s *DockerDaemonSuite) TestDaemonStartWithIpcModes(c *check.C) {
2896 2896
 	}
2897 2897
 }
2898 2898
 
2899
-// TestDaemonRestartIpcMode makes sure a container keeps its ipc mode
2900
-// (derived from daemon default) even after the daemon is restarted
2901
-// with a different default ipc mode.
2902
-func (s *DockerDaemonSuite) TestDaemonRestartIpcMode(c *check.C) {
2903
-	f, err := ioutil.TempFile("", "test-daemon-ipc-config-restart")
2904
-	c.Assert(err, checker.IsNil)
2905
-	file := f.Name()
2906
-	defer os.Remove(file)
2907
-	c.Assert(f.Close(), checker.IsNil)
2908
-
2909
-	config := []byte(`{"default-ipc-mode": "private"}`)
2910
-	c.Assert(ioutil.WriteFile(file, config, 0644), checker.IsNil)
2911
-	s.d.StartWithBusybox(c, "--config-file", file)
2912
-
2913
-	// check the container is created with private ipc mode as per daemon default
2914
-	name := "ipc1"
2915
-	_, err = s.d.Cmd("run", "-d", "--name", name, "--restart=always", "busybox", "top")
2916
-	c.Assert(err, checker.IsNil)
2917
-	m, err := s.d.InspectField(name, ".HostConfig.IpcMode")
2918
-	c.Assert(err, check.IsNil)
2919
-	c.Assert(m, checker.Equals, "private")
2920
-
2921
-	// restart the daemon with shareable default ipc mode
2922
-	config = []byte(`{"default-ipc-mode": "shareable"}`)
2923
-	c.Assert(ioutil.WriteFile(file, config, 0644), checker.IsNil)
2924
-	s.d.Restart(c, "--config-file", file)
2925
-
2926
-	// check the container is still having private ipc mode
2927
-	m, err = s.d.InspectField(name, ".HostConfig.IpcMode")
2928
-	c.Assert(err, check.IsNil)
2929
-	c.Assert(m, checker.Equals, "private")
2930
-
2931
-	// check a new container is created with shareable ipc mode as per new daemon default
2932
-	name = "ipc2"
2933
-	_, err = s.d.Cmd("run", "-d", "--name", name, "busybox", "top")
2934
-	c.Assert(err, checker.IsNil)
2935
-	m, err = s.d.InspectField(name, ".HostConfig.IpcMode")
2936
-	c.Assert(err, check.IsNil)
2937
-	c.Assert(m, checker.Equals, "shareable")
2938
-}
2939
-
2940 2899
 // TestFailedPluginRemove makes sure that a failed plugin remove does not block
2941 2900
 // the daemon from starting
2942 2901
 func (s *DockerDaemonSuite) TestFailedPluginRemove(c *check.C) {
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/internal/test/daemon"
14 14
 	"golang.org/x/sys/unix"
15 15
 	"gotest.tools/assert"
16
+	is "gotest.tools/assert/cmp"
16 17
 	"gotest.tools/skip"
17 18
 )
18 19
 
... ...
@@ -76,3 +77,46 @@ func getContainerdShimPid(t *testing.T, c types.ContainerJSON) int {
76 76
 	assert.Check(t, ppid != 1, "got unexpected ppid")
77 77
 	return ppid
78 78
 }
79
+
80
+// TestDaemonRestartIpcMode makes sure a container keeps its ipc mode
81
+// (derived from daemon default) even after the daemon is restarted
82
+// with a different default ipc mode.
83
+func TestDaemonRestartIpcMode(t *testing.T) {
84
+	skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")
85
+	skip.If(t, testEnv.DaemonInfo.OSType == "windows")
86
+	t.Parallel()
87
+
88
+	d := daemon.New(t)
89
+	d.StartWithBusybox(t, "--iptables=false", "--default-ipc-mode=private")
90
+	defer d.Stop(t)
91
+
92
+	c := d.NewClientT(t)
93
+	ctx := context.Background()
94
+
95
+	// check the container is created with private ipc mode as per daemon default
96
+	cID := container.Run(t, ctx, c,
97
+		container.WithCmd("top"),
98
+		container.WithRestartPolicy("always"),
99
+	)
100
+	defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
101
+
102
+	inspect, err := c.ContainerInspect(ctx, cID)
103
+	assert.NilError(t, err)
104
+	assert.Check(t, is.Equal(string(inspect.HostConfig.IpcMode), "private"))
105
+
106
+	// restart the daemon with shareable default ipc mode
107
+	d.Restart(t, "--iptables=false", "--default-ipc-mode=shareable")
108
+
109
+	// check the container is still having private ipc mode
110
+	inspect, err = c.ContainerInspect(ctx, cID)
111
+	assert.NilError(t, err)
112
+	assert.Check(t, is.Equal(string(inspect.HostConfig.IpcMode), "private"))
113
+
114
+	// check a new container is created with shareable ipc mode as per new daemon default
115
+	cID = container.Run(t, ctx, c)
116
+	defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
117
+
118
+	inspect, err = c.ContainerInspect(ctx, cID)
119
+	assert.NilError(t, err)
120
+	assert.Check(t, is.Equal(string(inspect.HostConfig.IpcMode), "shareable"))
121
+}