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

Merge pull request #12450 from brahmaroutu/integration_test3_12255

Port test from integration tests - test low memory on create
This commit is contained in:
Phil Estes 2015-04-20 17:27:17 -04:00
commit 435643545c
4 changed files with 59 additions and 12 deletions

View file

@ -1226,6 +1226,10 @@ func checkKernel() error {
func (daemon *Daemon) verifyHostConfig(hostConfig *runconfig.HostConfig) ([]string, error) { func (daemon *Daemon) verifyHostConfig(hostConfig *runconfig.HostConfig) ([]string, error) {
var warnings []string var warnings []string
if hostConfig == nil {
return warnings, nil
}
if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") { if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") {
return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name()) return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
} }

View file

@ -20,6 +20,10 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
return fmt.Errorf("Container already started") return fmt.Errorf("Container already started")
} }
if _, err = daemon.verifyHostConfig(hostConfig); err != nil {
return err
}
// This is kept for backward compatibility - hostconfig should be passed when // This is kept for backward compatibility - hostconfig should be passed when
// creating a container, not during start. // creating a container, not during start.
if hostConfig != nil { if hostConfig != nil {

View file

@ -817,3 +817,54 @@ func TestContainerApiPostCreateNull(t *testing.T) {
logDone("containers REST API - Create Null") logDone("containers REST API - Create Null")
} }
func TestCreateWithTooLowMemoryLimit(t *testing.T) {
defer deleteAllContainers()
config := `{
"Image": "busybox",
"Cmd": "ls",
"OpenStdin": true,
"CpuShares": 100,
"Memory": 524287
}`
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
b, err2 := readBody(body)
if err2 != nil {
t.Fatal(err2)
}
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
}
logDone("container REST API - create can't set too low memory limit")
}
func TestStartWithTooLowMemoryLimit(t *testing.T) {
defer deleteAllContainers()
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "busybox"))
if err != nil {
t.Fatal(err, out)
}
containerID := strings.TrimSpace(out)
config := `{
"CpuShares": 100,
"Memory": 524287
}`
_, body, err := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
b, err2 := readBody(body)
if err2 != nil {
t.Fatal(err2)
}
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
}
logDone("container REST API - start can't set too low memory limit")
}

View file

@ -3496,15 +3496,3 @@ func TestRunPidHostWithChildIsKillable(t *testing.T) {
} }
logDone("run - can kill container with pid-host and some childs of pid 1") logDone("run - can kill container with pid-host and some childs of pid 1")
} }
func TestRunWithTooSmallMemoryLimit(t *testing.T) {
defer deleteAllContainers()
// this memory limit is 1 byte less than the min, which is 4MB
// https://github.com/docker/docker/blob/v1.5.0/daemon/create.go#L22
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-m", "4194303", "busybox"))
if err == nil || !strings.Contains(out, "Minimum memory limit allowed is 4MB") {
t.Fatalf("expected run to fail when using too low a memory limit: %q", out)
}
logDone("run - can't set too low memory limit")
}