mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Validate restart policy. Fixes #14351
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
d7326bd787
commit
f3faf59925
2 changed files with 7 additions and 8 deletions
|
@ -428,12 +428,15 @@ func ParseRestartPolicy(policy string) (RestartPolicy, error) {
|
|||
p.Name = name
|
||||
switch name {
|
||||
case "always":
|
||||
if len(parts) == 2 {
|
||||
if len(parts) > 1 {
|
||||
return p, fmt.Errorf("maximum restart count not valid with restart policy of \"always\"")
|
||||
}
|
||||
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 {
|
||||
|
|
|
@ -456,12 +456,13 @@ 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'",
|
||||
}
|
||||
valids := map[string]RestartPolicy{
|
||||
"": {},
|
||||
// FIXME This feels not right
|
||||
"always:1:2": {
|
||||
"always": {
|
||||
Name: "always",
|
||||
MaximumRetryCount: 0,
|
||||
},
|
||||
|
@ -469,11 +470,6 @@ func TestParseRestartPolicy(t *testing.T) {
|
|||
Name: "on-failure",
|
||||
MaximumRetryCount: 1,
|
||||
},
|
||||
// FIXME This doesn't feel right
|
||||
"on-failure:1:2": {
|
||||
Name: "on-failure",
|
||||
MaximumRetryCount: 0,
|
||||
},
|
||||
}
|
||||
for restart, expectedError := range invalids {
|
||||
if _, _, _, err := parseRun([]string{fmt.Sprintf("--restart=%s", restart), "img", "cmd"}); err == nil || err.Error() != expectedError {
|
||||
|
|
Loading…
Reference in a new issue