fix the problem that memory-swap=-1 is not working for docker command
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
parent
c03d6f57b6
commit
aee28e0e87
2 changed files with 21 additions and 4 deletions
|
@ -60,6 +60,19 @@ func TestRunEchoStdoutWithMemoryLimit(t *testing.T) {
|
||||||
logDone("run - echo with memory limit")
|
logDone("run - echo with memory limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should run without memory swap
|
||||||
|
func TestRunWithoutMemoryswapLimit(t *testing.T) {
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to run container, output: %q", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAllContainers()
|
||||||
|
|
||||||
|
logDone("run - without memory swap limit")
|
||||||
|
}
|
||||||
|
|
||||||
// "test" should be printed
|
// "test" should be printed
|
||||||
func TestRunEchoStdoutWitCPULimit(t *testing.T) {
|
func TestRunEchoStdoutWitCPULimit(t *testing.T) {
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test")
|
runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test")
|
||||||
|
|
|
@ -140,12 +140,16 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
||||||
|
|
||||||
var MemorySwap int64
|
var MemorySwap int64
|
||||||
if *flMemorySwap != "" {
|
if *flMemorySwap != "" {
|
||||||
|
if *flMemorySwap == "-1" {
|
||||||
|
MemorySwap = -1
|
||||||
|
} else {
|
||||||
parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap)
|
parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, cmd, err
|
return nil, nil, cmd, err
|
||||||
}
|
}
|
||||||
MemorySwap = parsedMemorySwap
|
MemorySwap = parsedMemorySwap
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var binds []string
|
var binds []string
|
||||||
// add any bind targets to the list of container volumes
|
// add any bind targets to the list of container volumes
|
||||||
|
|
Loading…
Reference in a new issue