mirror of
https://github.com/moby/moby.git
synced 2025-08-01 05:47:11 +03:00
api: add TypeTmpfs to api/types/mount
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
@ -1569,13 +1569,80 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
||||
notExistPath := prefix + slash + "notexist"
|
||||
|
||||
cases := []testCase{
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "notreal", Target: destPath}}}}, http.StatusBadRequest, "mount type unknown"},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "bind"}}}}, http.StatusBadRequest, "Target must not be empty"},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "bind", Target: destPath}}}}, http.StatusBadRequest, "Source must not be empty"},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "bind", Source: notExistPath, Target: destPath}}}}, http.StatusBadRequest, "bind source path does not exist"},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "volume"}}}}, http.StatusBadRequest, "Target must not be empty"},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "volume", Source: "hello", Target: destPath}}}}, http.StatusCreated, ""},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "volume", Source: "hello2", Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{DriverConfig: &mounttypes.Driver{Name: "local"}}}}}}, http.StatusCreated, ""},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "notreal",
|
||||
Target: destPath}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "mount type unknown",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "bind"}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "Target must not be empty",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "bind",
|
||||
Target: destPath}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "Source must not be empty",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "bind",
|
||||
Source: notExistPath,
|
||||
Target: destPath}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "bind source path does not exist",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "volume"}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "Target must not be empty",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "volume",
|
||||
Source: "hello",
|
||||
Target: destPath}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "volume",
|
||||
Source: "hello2",
|
||||
Target: destPath,
|
||||
VolumeOptions: &mounttypes.VolumeOptions{
|
||||
DriverConfig: &mounttypes.Driver{
|
||||
Name: "local"}}}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
}
|
||||
|
||||
if SameHostDaemon.Condition() {
|
||||
@ -1583,14 +1650,85 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
cases = append(cases, []testCase{
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "bind", Source: tmpDir, Target: destPath}}}}, http.StatusCreated, ""},
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "bind", Source: tmpDir, Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{}}}}}, http.StatusBadRequest, "VolumeOptions must not be specified"},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "bind",
|
||||
Source: tmpDir,
|
||||
Target: destPath}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "bind",
|
||||
Source: tmpDir,
|
||||
Target: destPath,
|
||||
VolumeOptions: &mounttypes.VolumeOptions{}}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "VolumeOptions must not be specified",
|
||||
},
|
||||
}...)
|
||||
}
|
||||
|
||||
if DaemonIsLinux.Condition() {
|
||||
cases = append(cases, []testCase{
|
||||
{cfg{Image: "busybox", HostConfig: hc{Mounts: []m{{Type: "volume", Source: "hello3", Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{DriverConfig: &mounttypes.Driver{Name: "local", Options: map[string]string{"o": "size=1"}}}}}}}, http.StatusCreated, ""},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "volume",
|
||||
Source: "hello3",
|
||||
Target: destPath,
|
||||
VolumeOptions: &mounttypes.VolumeOptions{
|
||||
DriverConfig: &mounttypes.Driver{
|
||||
Name: "local",
|
||||
Options: map[string]string{"o": "size=1"}}}}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "tmpfs",
|
||||
Target: destPath}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "tmpfs",
|
||||
Target: destPath,
|
||||
TmpfsOptions: &mounttypes.TmpfsOptions{
|
||||
SizeBytes: 4096 * 1024,
|
||||
Mode: 0700,
|
||||
}}}}},
|
||||
status: http.StatusCreated,
|
||||
msg: "",
|
||||
},
|
||||
|
||||
{
|
||||
config: cfg{
|
||||
Image: "busybox",
|
||||
HostConfig: hc{
|
||||
Mounts: []m{{
|
||||
Type: "tmpfs",
|
||||
Source: "/shouldnotbespecified",
|
||||
Target: destPath}}}},
|
||||
status: http.StatusBadRequest,
|
||||
msg: "Source must not be specified",
|
||||
},
|
||||
}...)
|
||||
|
||||
}
|
||||
@ -1759,3 +1897,45 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
type testCase struct {
|
||||
cfg map[string]interface{}
|
||||
expectedOptions []string
|
||||
}
|
||||
target := "/foo"
|
||||
cases := []testCase{
|
||||
{
|
||||
cfg: map[string]interface{}{
|
||||
"Type": "tmpfs",
|
||||
"Target": target},
|
||||
expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime"},
|
||||
},
|
||||
{
|
||||
cfg: map[string]interface{}{
|
||||
"Type": "tmpfs",
|
||||
"Target": target,
|
||||
"TmpfsOptions": map[string]interface{}{
|
||||
"SizeBytes": 4096 * 1024, "Mode": 0700}},
|
||||
expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k", "mode=700"},
|
||||
},
|
||||
}
|
||||
|
||||
for i, x := range cases {
|
||||
cName := fmt.Sprintf("test-tmpfs-%d", i)
|
||||
data := map[string]interface{}{
|
||||
"Image": "busybox",
|
||||
"Cmd": []string{"/bin/sh", "-c",
|
||||
fmt.Sprintf("mount | grep 'tmpfs on %s'", target)},
|
||||
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{x.cfg}},
|
||||
}
|
||||
status, resp, err := sockRequest("POST", "/containers/create?name="+cName, data)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(resp)))
|
||||
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp)))
|
||||
out, _ := dockerCmd(c, "start", "-a", cName)
|
||||
for _, option := range x.expectedOptions {
|
||||
c.Assert(out, checker.Contains, option)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user