2016-01-04 10:58:20 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-04-11 15:18:30 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
2016-01-04 10:58:20 -05:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) {
|
2017-04-11 15:18:30 -04:00
|
|
|
out := cli.DockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false").Combined()
|
2016-01-04 10:58:20 -05:00
|
|
|
timeout := 60 * time.Second
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() == "windows" {
|
2016-03-14 07:49:24 -04:00
|
|
|
timeout = 180 * time.Second
|
2016-01-04 10:58:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
id := strings.TrimSpace(string(out))
|
|
|
|
|
|
|
|
// update restart policy to on-failure:5
|
2017-04-11 15:18:30 -04:00
|
|
|
cli.DockerCmd(c, "update", "--restart=on-failure:5", id)
|
2016-01-04 10:58:20 -05:00
|
|
|
|
2017-04-11 15:18:30 -04:00
|
|
|
cli.WaitExited(c, id, timeout)
|
2016-01-04 10:58:20 -05:00
|
|
|
|
|
|
|
count := inspectField(c, id, "RestartCount")
|
|
|
|
c.Assert(count, checker.Equals, "5")
|
|
|
|
|
|
|
|
maximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
|
|
|
|
c.Assert(maximumRetryCount, checker.Equals, "5")
|
|
|
|
}
|
2016-08-15 04:38:47 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) {
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "--rm")
|
2016-08-15 04:38:47 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
// update restart policy for an AutoRemove container
|
2017-04-11 15:18:30 -04:00
|
|
|
cli.Docker(cli.Args("update", "--restart=always", id)).Assert(c, icmd.Expected{
|
|
|
|
ExitCode: 1,
|
|
|
|
Err: "Restart policy cannot be updated because AutoRemove is enabled for the container",
|
|
|
|
})
|
2016-08-15 04:38:47 -04:00
|
|
|
}
|