1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Migrate some ipcmode tests to integration

This fix migrates some ipcmode tests in integration-cli
to integration tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2018-07-04 04:14:23 +00:00
parent b0e6eedcf4
commit e0403604e2
2 changed files with 116 additions and 66 deletions

View file

@ -46,72 +46,6 @@ func testIpcCheckDevExists(mm string) (bool, error) {
return false, s.Err()
}
// testIpcNonePrivateShareable is a helper function to test "none",
// "private" and "shareable" modes.
func testIpcNonePrivateShareable(c *check.C, mode string, mustBeMounted bool, mustBeShared bool) {
cfg := container.Config{
Image: "busybox",
Cmd: []string{"top"},
}
hostCfg := container.HostConfig{
IpcMode: container.IpcMode(mode),
}
ctx := context.Background()
client := testEnv.APIClient()
resp, err := client.ContainerCreate(ctx, &cfg, &hostCfg, nil, "")
c.Assert(err, checker.IsNil)
c.Assert(len(resp.Warnings), checker.Equals, 0)
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
c.Assert(err, checker.IsNil)
// get major:minor pair for /dev/shm from container's /proc/self/mountinfo
cmd := "awk '($5 == \"/dev/shm\") {printf $3}' /proc/self/mountinfo"
mm := cli.DockerCmd(c, "exec", "-i", resp.ID, "sh", "-c", cmd).Combined()
if !mustBeMounted {
c.Assert(mm, checker.Equals, "")
// no more checks to perform
return
}
c.Assert(mm, checker.Matches, "^[0-9]+:[0-9]+$")
shared, err := testIpcCheckDevExists(mm)
c.Assert(err, checker.IsNil)
c.Logf("[testIpcPrivateShareable] ipcmode: %v, ipcdev: %v, shared: %v, mustBeShared: %v\n", mode, mm, shared, mustBeShared)
c.Assert(shared, checker.Equals, mustBeShared)
}
/* TestAPIIpcModeNone checks the container "none" IPC mode
* (--ipc none) works as expected. It makes sure there is no
* /dev/shm mount inside the container.
*/
func (s *DockerSuite) TestAPIIpcModeNone(c *check.C) {
testRequires(c, DaemonIsLinux, MinimumAPIVersion("1.32"))
testIpcNonePrivateShareable(c, "none", false, false)
}
/* TestAPIIpcModePrivate checks the container private IPC mode
* (--ipc private) works as expected. It gets the minor:major pair
* of /dev/shm mount from the container, and makes sure there is no
* such pair on the host.
*/
func (s *DockerSuite) TestAPIIpcModePrivate(c *check.C) {
testRequires(c, DaemonIsLinux, SameHostDaemon)
testIpcNonePrivateShareable(c, "private", true, false)
}
/* TestAPIIpcModeShareable checks the container shareable IPC mode
* (--ipc shareable) works as expected. It gets the minor:major pair
* of /dev/shm mount from the container, and makes sure such pair
* also exists on the host.
*/
func (s *DockerSuite) TestAPIIpcModeShareable(c *check.C) {
testRequires(c, DaemonIsLinux, SameHostDaemon)
testIpcNonePrivateShareable(c, "shareable", true, true)
}
// testIpcContainer is a helper function to test --ipc container:NNN mode in various scenarios
func testIpcContainer(s *DockerSuite, c *check.C, donorMode string, mustWork bool) {
cfg := container.Config{