mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Validate --cpuset-cpus, --cpuset-mems
Before this patch libcontainer badly errored out with `invalid argument` or `numerical result out of range` while trying to write to cpuset.cpus or cpuset.mems with an invalid value provided. This patch adds validation to --cpuset-cpus and --cpuset-mems flag along with validation based on system's available cpus/mems before starting a container. Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
@ -1525,3 +1525,29 @@ func (s *DockerSuite) TestContainersApiGetContainersJSONEmpty(c *check.C) {
|
||||
c.Fatalf("Expected empty response to be `[]`, got %q", string(body))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
c1 := struct {
|
||||
Image string
|
||||
CpusetCpus string
|
||||
}{"busybox", "1-42,,"}
|
||||
name := "wrong-cpuset-cpus"
|
||||
status, body, err := sockRequest("POST", "/containers/create?name="+name, c1)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||
expected := "Invalid value 1-42,, for cpuset cpus.\n"
|
||||
c.Assert(string(body), check.Equals, expected, check.Commentf("Expected output to contain %q, got %q", expected, string(body)))
|
||||
|
||||
c2 := struct {
|
||||
Image string
|
||||
CpusetMems string
|
||||
}{"busybox", "42-3,1--"}
|
||||
name = "wrong-cpuset-mems"
|
||||
status, body, err = sockRequest("POST", "/containers/create?name="+name, c2)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||
expected = "Invalid value 42-3,1-- for cpuset mems.\n"
|
||||
c.Assert(string(body), check.Equals, expected, check.Commentf("Expected output to contain %q, got %q", expected, string(body)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user