From 2e0a98b605fa278ee1f348c68fe7e07aed57b834 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 12 Nov 2017 18:27:05 -0800 Subject: [PATCH] integration: test case for #35271 This test case is checking that the built-in default size for /dev/shm (which is used for `--ipcmode` being `private` or `shareable`) is not overriding the size of user-defined tmpfs mount for /dev/shm. In other words, this is a regression test case for issue #35271, https://github.com/moby/moby/issues/35271 Signed-off-by: Kir Kolyshkin --- daemon/daemon_linux_test.go | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/daemon/daemon_linux_test.go b/daemon/daemon_linux_test.go index c7d5117195..36ef52e25a 100644 --- a/daemon/daemon_linux_test.go +++ b/daemon/daemon_linux_test.go @@ -5,6 +5,13 @@ package daemon import ( "strings" "testing" + + containertypes "github.com/docker/docker/api/types/container" + "github.com/docker/docker/container" + "github.com/docker/docker/oci" + "github.com/docker/docker/pkg/idtools" + + "github.com/stretchr/testify/assert" ) const mountsFixture = `142 78 0:38 / / rw,relatime - aufs none rw,si=573b861da0b3a05b,dio @@ -102,3 +109,51 @@ func TestNotCleanupMounts(t *testing.T) { t.Fatal("Expected not to clean up /dev/shm") } } + +// TestTmpfsDevShmSizeOverride checks that user-specified /dev/tmpfs mount +// size is not overriden by the default shmsize (that should only be used +// for default /dev/shm (as in "shareable" and "private" ipc modes). +// https://github.com/moby/moby/issues/35271 +func TestTmpfsDevShmSizeOverride(t *testing.T) { + size := "777m" + mnt := "/dev/shm" + + d := Daemon{ + idMappings: &idtools.IDMappings{}, + } + c := &container.Container{ + HostConfig: &containertypes.HostConfig{ + ShmSize: 48 * 1024, // size we should NOT end up with + }, + } + ms := []container.Mount{ + { + Source: "tmpfs", + Destination: mnt, + Data: "size=" + size, + }, + } + + // convert ms to spec + spec := oci.DefaultSpec() + err := setMounts(&d, &spec, c, ms) + assert.NoError(t, err) + + // Check the resulting spec for the correct size + found := false + for _, m := range spec.Mounts { + if m.Destination == mnt { + for _, o := range m.Options { + if !strings.HasPrefix(o, "size=") { + continue + } + t.Logf("%+v\n", m.Options) + assert.Equal(t, "size="+size, o) + found = true + } + } + } + if !found { + t.Fatal("/dev/shm not found in spec, or size option missing") + } +}