зеркало из https://github.com/microsoft/docker.git
Merge pull request #12450 from brahmaroutu/integration_test3_12255
Port test from integration tests - test low memory on create
This commit is contained in:
Коммит
435643545c
|
@ -1226,6 +1226,10 @@ func checkKernel() error {
|
|||
func (daemon *Daemon) verifyHostConfig(hostConfig *runconfig.HostConfig) ([]string, error) {
|
||||
var warnings []string
|
||||
|
||||
if hostConfig == nil {
|
||||
return warnings, nil
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
|
|||
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
|
||||
// creating a container, not during start.
|
||||
if hostConfig != nil {
|
||||
|
|
|
@ -817,3 +817,54 @@ func TestContainerApiPostCreateNull(t *testing.T) {
|
|||
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -3496,15 +3496,3 @@ func TestRunPidHostWithChildIsKillable(t *testing.T) {
|
|||
}
|
||||
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")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче