Browse code

Fix update clear the restart policy of monitor

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2016/12/17 10:57:05
Showing 2 changed files
... ...
@@ -67,7 +67,9 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
67 67
 	}
68 68
 
69 69
 	// if Restart Policy changed, we need to update container monitor
70
-	container.UpdateMonitor(hostConfig.RestartPolicy)
70
+	if hostConfig.RestartPolicy.Name != "" {
71
+		container.UpdateMonitor(hostConfig.RestartPolicy)
72
+	}
71 73
 
72 74
 	// If container is not running, update hostConfig struct is enough,
73 75
 	// resources will be updated when the container is started again.
... ...
@@ -5,7 +5,10 @@ package main
5 5
 import (
6 6
 	"encoding/json"
7 7
 	"fmt"
8
+	"github.com/kr/pty"
9
+	"os/exec"
8 10
 	"strings"
11
+	"time"
9 12
 
10 13
 	"github.com/docker/docker/api/types"
11 14
 	"github.com/docker/docker/pkg/integration/checker"
... ...
@@ -250,3 +253,31 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
250 250
 
251 251
 	dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
252 252
 }
253
+
254
+func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) {
255
+	testRequires(c, DaemonIsLinux, cpuShare)
256
+
257
+	out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
258
+	id := strings.TrimSpace(string(out))
259
+	dockerCmd(c, "update", "--cpu-shares", "512", id)
260
+
261
+	cpty, tty, err := pty.Open()
262
+	c.Assert(err, checker.IsNil)
263
+	defer cpty.Close()
264
+
265
+	cmd := exec.Command(dockerBinary, "attach", id)
266
+	cmd.Stdin = tty
267
+
268
+	c.Assert(cmd.Start(), checker.IsNil)
269
+	defer cmd.Process.Kill()
270
+
271
+	_, err = cpty.Write([]byte("exit\n"))
272
+	c.Assert(err, checker.IsNil)
273
+
274
+	c.Assert(cmd.Wait(), checker.IsNil)
275
+
276
+	// container should restart again and keep running
277
+	err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second)
278
+	c.Assert(err, checker.IsNil)
279
+	c.Assert(waitRun(id), checker.IsNil)
280
+}