Merge pull request #29039 from thaJeztah/fix-restart-limit-validation
Fix restartpolicy max-retry validation
This commit is contained in:
commit
6e023ac748
|
@ -268,11 +268,11 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostCon
|
||||||
switch p.Name {
|
switch p.Name {
|
||||||
case "always", "unless-stopped", "no":
|
case "always", "unless-stopped", "no":
|
||||||
if p.MaximumRetryCount != 0 {
|
if p.MaximumRetryCount != 0 {
|
||||||
return nil, fmt.Errorf("maximum restart count not valid with restart policy of '%s'", p.Name)
|
return nil, fmt.Errorf("maximum retry count cannot be used with restart policy '%s'", p.Name)
|
||||||
}
|
}
|
||||||
case "on-failure":
|
case "on-failure":
|
||||||
if p.MaximumRetryCount < 1 {
|
if p.MaximumRetryCount < 0 {
|
||||||
return nil, fmt.Errorf("maximum restart count must be a positive integer")
|
return nil, fmt.Errorf("maximum retry count cannot be negative")
|
||||||
}
|
}
|
||||||
case "":
|
case "":
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
|
@ -728,7 +728,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
|
||||||
c.Assert(string(b[:]), checker.Contains, "invalid port")
|
c.Assert(string(b[:]), checker.Contains, "invalid port")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyName(c *check.C) {
|
func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C) {
|
||||||
config := `{
|
config := `{
|
||||||
"Image": "busybox",
|
"Image": "busybox",
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
|
@ -748,7 +748,7 @@ func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyName(c *check.C) {
|
||||||
c.Assert(string(b[:]), checker.Contains, "invalid restart policy")
|
c.Assert(string(b[:]), checker.Contains, "invalid restart policy")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyRetryMismatch(c *check.C) {
|
func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
|
||||||
config := `{
|
config := `{
|
||||||
"Image": "busybox",
|
"Image": "busybox",
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
|
@ -765,10 +765,10 @@ func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyRetryMismatch(c *check
|
||||||
|
|
||||||
b, err := readBody(body)
|
b, err := readBody(body)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(string(b[:]), checker.Contains, "maximum restart count not valid with restart policy")
|
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be used with restart policy")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyPositiveRetryCount(c *check.C) {
|
func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C) {
|
||||||
config := `{
|
config := `{
|
||||||
"Image": "busybox",
|
"Image": "busybox",
|
||||||
"HostConfig": {
|
"HostConfig": {
|
||||||
|
@ -785,7 +785,23 @@ func (s *DockerSuite) TestContainerAPIInvalidRestartPolicyPositiveRetryCount(c *
|
||||||
|
|
||||||
b, err := readBody(body)
|
b, err := readBody(body)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(string(b[:]), checker.Contains, "maximum restart count must be a positive integer")
|
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be negative")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C) {
|
||||||
|
config := `{
|
||||||
|
"Image": "busybox",
|
||||||
|
"HostConfig": {
|
||||||
|
"RestartPolicy": {
|
||||||
|
"Name": "on-failure",
|
||||||
|
"MaximumRetryCount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
res, _, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue 7941 - test to make sure a "null" in JSON is just ignored.
|
// Issue 7941 - test to make sure a "null" in JSON is just ignored.
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (s *DockerSuite) TestRestartWithVolumes(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "run", "-d", "--restart=no", "busybox", "false")
|
out, _ := dockerCmd(c, "create", "--restart=no", "busybox")
|
||||||
|
|
||||||
id := strings.TrimSpace(string(out))
|
id := strings.TrimSpace(string(out))
|
||||||
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
||||||
|
@ -82,7 +82,7 @@ func (s *DockerSuite) TestRestartPolicyNO(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false")
|
out, _ := dockerCmd(c, "create", "--restart=always", "busybox")
|
||||||
|
|
||||||
id := strings.TrimSpace(string(out))
|
id := strings.TrimSpace(string(out))
|
||||||
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
||||||
|
@ -95,12 +95,36 @@ func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:1", "busybox", "false")
|
out, _, err := dockerCmdWithError("create", "--restart=on-failure:-1", "busybox")
|
||||||
|
c.Assert(err, check.NotNil, check.Commentf(out))
|
||||||
|
c.Assert(out, checker.Contains, "maximum retry count cannot be negative")
|
||||||
|
|
||||||
|
out, _ = dockerCmd(c, "create", "--restart=on-failure:1", "busybox")
|
||||||
|
|
||||||
id := strings.TrimSpace(string(out))
|
id := strings.TrimSpace(string(out))
|
||||||
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
name := inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
||||||
c.Assert(name, checker.Equals, "on-failure")
|
maxRetry := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
|
||||||
|
|
||||||
|
c.Assert(name, checker.Equals, "on-failure")
|
||||||
|
c.Assert(maxRetry, checker.Equals, "1")
|
||||||
|
|
||||||
|
out, _ = dockerCmd(c, "create", "--restart=on-failure:0", "busybox")
|
||||||
|
|
||||||
|
id = strings.TrimSpace(string(out))
|
||||||
|
name = inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
||||||
|
maxRetry = inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
|
||||||
|
|
||||||
|
c.Assert(name, checker.Equals, "on-failure")
|
||||||
|
c.Assert(maxRetry, checker.Equals, "0")
|
||||||
|
|
||||||
|
out, _ = dockerCmd(c, "create", "--restart=on-failure", "busybox")
|
||||||
|
|
||||||
|
id = strings.TrimSpace(string(out))
|
||||||
|
name = inspectField(c, id, "HostConfig.RestartPolicy.Name")
|
||||||
|
maxRetry = inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
|
||||||
|
|
||||||
|
c.Assert(name, checker.Equals, "on-failure")
|
||||||
|
c.Assert(maxRetry, checker.Equals, "0")
|
||||||
}
|
}
|
||||||
|
|
||||||
// a good container with --restart=on-failure:3
|
// a good container with --restart=on-failure:3
|
||||||
|
|
Loading…
Reference in New Issue