Merge pull request #24073 from johnharris85/move-restart-policy-check-to-daemon

Move restart-policy validation from client to daemon.
Upstream-commit: d13ad3ef7684bf330cec2eaa4a14048e3fbc2d94
Component: engine
This commit is contained in:
Vincent Demeester
2016-08-25 17:02:30 +02:00
committed by GitHub
4 changed files with 92 additions and 31 deletions

View File

@ -729,34 +729,21 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
return p, nil
}
var (
parts = strings.Split(policy, ":")
name = parts[0]
)
parts := strings.Split(policy, ":")
p.Name = name
switch name {
case "always", "unless-stopped":
if len(parts) > 1 {
return p, fmt.Errorf("maximum restart count not valid with restart policy of \"%s\"", name)
}
case "no":
// do nothing
case "on-failure":
if len(parts) > 2 {
return p, fmt.Errorf("restart count format is not valid, usage: 'on-failure:N' or 'on-failure'")
}
if len(parts) == 2 {
count, err := strconv.Atoi(parts[1])
if err != nil {
return p, err
}
p.MaximumRetryCount = count
}
default:
return p, fmt.Errorf("invalid restart policy %s", name)
if len(parts) > 2 {
return p, fmt.Errorf("invalid restart policy format")
}
if len(parts) == 2 {
count, err := strconv.Atoi(parts[1])
if err != nil {
return p, fmt.Errorf("maximum retry count must be an integer")
}
p.MaximumRetryCount = count
}
p.Name = parts[0]
return p, nil
}

View File

@ -556,11 +556,8 @@ func TestParseModes(t *testing.T) {
func TestParseRestartPolicy(t *testing.T) {
invalids := map[string]string{
"something": "invalid restart policy something",
"always:2": "maximum restart count not valid with restart policy of \"always\"",
"always:2:3": "maximum restart count not valid with restart policy of \"always\"",
"on-failure:invalid": `strconv.ParseInt: parsing "invalid": invalid syntax`,
"on-failure:2:5": "restart count format is not valid, usage: 'on-failure:N' or 'on-failure'",
"always:2:3": "invalid restart policy format",
"on-failure:invalid": "maximum retry count must be an integer",
}
valids := map[string]container.RestartPolicy{
"": {},