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 <kolyshkin@gmail.com>
| ... | ... |
@@ -5,6 +5,13 @@ package daemon |
| 5 | 5 |
import ( |
| 6 | 6 |
"strings" |
| 7 | 7 |
"testing" |
| 8 |
+ |
|
| 9 |
+ containertypes "github.com/docker/docker/api/types/container" |
|
| 10 |
+ "github.com/docker/docker/container" |
|
| 11 |
+ "github.com/docker/docker/oci" |
|
| 12 |
+ "github.com/docker/docker/pkg/idtools" |
|
| 13 |
+ |
|
| 14 |
+ "github.com/stretchr/testify/assert" |
|
| 8 | 15 |
) |
| 9 | 16 |
|
| 10 | 17 |
const mountsFixture = `142 78 0:38 / / rw,relatime - aufs none rw,si=573b861da0b3a05b,dio |
| ... | ... |
@@ -102,3 +109,51 @@ func TestNotCleanupMounts(t *testing.T) {
|
| 102 | 102 |
t.Fatal("Expected not to clean up /dev/shm")
|
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 |
+ |
|
| 106 |
+// TestTmpfsDevShmSizeOverride checks that user-specified /dev/tmpfs mount |
|
| 107 |
+// size is not overriden by the default shmsize (that should only be used |
|
| 108 |
+// for default /dev/shm (as in "shareable" and "private" ipc modes). |
|
| 109 |
+// https://github.com/moby/moby/issues/35271 |
|
| 110 |
+func TestTmpfsDevShmSizeOverride(t *testing.T) {
|
|
| 111 |
+ size := "777m" |
|
| 112 |
+ mnt := "/dev/shm" |
|
| 113 |
+ |
|
| 114 |
+ d := Daemon{
|
|
| 115 |
+ idMappings: &idtools.IDMappings{},
|
|
| 116 |
+ } |
|
| 117 |
+ c := &container.Container{
|
|
| 118 |
+ HostConfig: &containertypes.HostConfig{
|
|
| 119 |
+ ShmSize: 48 * 1024, // size we should NOT end up with |
|
| 120 |
+ }, |
|
| 121 |
+ } |
|
| 122 |
+ ms := []container.Mount{
|
|
| 123 |
+ {
|
|
| 124 |
+ Source: "tmpfs", |
|
| 125 |
+ Destination: mnt, |
|
| 126 |
+ Data: "size=" + size, |
|
| 127 |
+ }, |
|
| 128 |
+ } |
|
| 129 |
+ |
|
| 130 |
+ // convert ms to spec |
|
| 131 |
+ spec := oci.DefaultSpec() |
|
| 132 |
+ err := setMounts(&d, &spec, c, ms) |
|
| 133 |
+ assert.NoError(t, err) |
|
| 134 |
+ |
|
| 135 |
+ // Check the resulting spec for the correct size |
|
| 136 |
+ found := false |
|
| 137 |
+ for _, m := range spec.Mounts {
|
|
| 138 |
+ if m.Destination == mnt {
|
|
| 139 |
+ for _, o := range m.Options {
|
|
| 140 |
+ if !strings.HasPrefix(o, "size=") {
|
|
| 141 |
+ continue |
|
| 142 |
+ } |
|
| 143 |
+ t.Logf("%+v\n", m.Options)
|
|
| 144 |
+ assert.Equal(t, "size="+size, o) |
|
| 145 |
+ found = true |
|
| 146 |
+ } |
|
| 147 |
+ } |
|
| 148 |
+ } |
|
| 149 |
+ if !found {
|
|
| 150 |
+ t.Fatal("/dev/shm not found in spec, or size option missing")
|
|
| 151 |
+ } |
|
| 152 |
+} |