Also live restore is stable now. So move experimental tests out to stable.
Signed-off-by: Anusha Ragunathan <anusha@docker.com>
(cherry picked from commit 006d58d7e6756848058bd69a12c698c44e64efd1)
| ... | ... |
@@ -1,155 +1,54 @@ |
| 1 |
-// +build daemon,!windows,experimental |
|
| 1 |
+// +build linux, experimental |
|
| 2 | 2 |
|
| 3 | 3 |
package main |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "io/ioutil" |
|
| 7 |
- "os" |
|
| 8 |
- "os/exec" |
|
| 9 |
- "strings" |
|
| 10 |
- "time" |
|
| 11 |
- |
|
| 6 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 12 | 7 |
"github.com/go-check/check" |
| 13 | 8 |
) |
| 14 | 9 |
|
| 15 |
-// TestDaemonRestartWithKilledRunningContainer requires live restore of running containers |
|
| 16 |
-func (s *DockerDaemonSuite) TestDaemonRestartWithKilledRunningContainer(t *check.C) {
|
|
| 17 |
- // TODO(mlaventure): Not sure what would the exit code be on windows |
|
| 18 |
- testRequires(t, DaemonIsLinux) |
|
| 19 |
- if err := s.d.StartWithBusybox(); err != nil {
|
|
| 20 |
- t.Fatal(err) |
|
| 21 |
- } |
|
| 22 |
- |
|
| 23 |
- cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
|
| 24 |
- defer s.d.Stop() |
|
| 25 |
- if err != nil {
|
|
| 26 |
- t.Fatal(cid, err) |
|
| 27 |
- } |
|
| 28 |
- cid = strings.TrimSpace(cid) |
|
| 29 |
- |
|
| 30 |
- // Kill the daemon |
|
| 31 |
- if err := s.d.Kill(); err != nil {
|
|
| 32 |
- t.Fatal(err) |
|
| 33 |
- } |
|
| 34 |
- |
|
| 35 |
- // kill the container |
|
| 36 |
- runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", cid) |
|
| 37 |
- if out, ec, err := runCommandWithOutput(runCmd); err != nil {
|
|
| 38 |
- t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid)
|
|
| 39 |
- } |
|
| 40 |
- |
|
| 41 |
- // Give time to containerd to process the command if we don't |
|
| 42 |
- // the exit event might be received after we do the inspect |
|
| 43 |
- time.Sleep(3 * time.Second) |
|
| 10 |
+var pluginName = "tiborvass/no-remove" |
|
| 44 | 11 |
|
| 45 |
- // restart the daemon |
|
| 12 |
+// TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin |
|
| 13 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) {
|
|
| 46 | 14 |
if err := s.d.Start(); err != nil {
|
| 47 |
- t.Fatal(err) |
|
| 48 |
- } |
|
| 49 |
- |
|
| 50 |
- // Check that we've got the correct exit code |
|
| 51 |
- out, err := s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", cid)
|
|
| 52 |
- t.Assert(err, check.IsNil) |
|
| 53 |
- |
|
| 54 |
- out = strings.TrimSpace(out) |
|
| 55 |
- if out != "143" {
|
|
| 56 |
- t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "143", out, cid)
|
|
| 57 |
- } |
|
| 58 |
- |
|
| 59 |
-} |
|
| 60 |
- |
|
| 61 |
-// os.Kill should kill daemon ungracefully, leaving behind live containers. |
|
| 62 |
-// The live containers should be known to the restarted daemon. Stopping |
|
| 63 |
-// them now, should remove the mounts. |
|
| 64 |
-func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
|
|
| 65 |
- testRequires(c, DaemonIsLinux) |
|
| 66 |
- c.Assert(s.d.StartWithBusybox("--live-restore"), check.IsNil)
|
|
| 67 |
- |
|
| 68 |
- out, err := s.d.Cmd("run", "-d", "busybox", "top")
|
|
| 69 |
- c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 70 |
- id := strings.TrimSpace(out) |
|
| 71 |
- |
|
| 72 |
- c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) |
|
| 73 |
- mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
|
|
| 74 |
- c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
|
| 75 |
- |
|
| 76 |
- // container mounts should exist even after daemon has crashed. |
|
| 77 |
- comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
|
|
| 78 |
- c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) |
|
| 79 |
- |
|
| 80 |
- // restart daemon. |
|
| 81 |
- if err := s.d.Restart("--live-restore"); err != nil {
|
|
| 82 |
- c.Fatal(err) |
|
| 15 |
+ c.Fatalf("Could not start daemon: %v", err)
|
|
| 83 | 16 |
} |
| 84 | 17 |
|
| 85 |
- // container should be running. |
|
| 86 |
- out, err = s.d.Cmd("inspect", "--format='{{.State.Running}}'", id)
|
|
| 87 |
- c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 88 |
- out = strings.TrimSpace(out) |
|
| 89 |
- if out != "true" {
|
|
| 90 |
- c.Fatalf("Container %s expected to stay alive after daemon restart", id)
|
|
| 18 |
+ if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName); err != nil {
|
|
| 19 |
+ c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
| 91 | 20 |
} |
| 92 | 21 |
|
| 93 |
- // 'docker stop' should work. |
|
| 94 |
- out, err = s.d.Cmd("stop", id)
|
|
| 95 |
- c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 96 |
- |
|
| 97 |
- // Now, container mounts should be gone. |
|
| 98 |
- mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
|
|
| 99 |
- c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
|
| 100 |
- comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
|
|
| 101 |
- c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) |
|
| 102 |
-} |
|
| 103 |
- |
|
| 104 |
-// TestDaemonRestartWithUnpausedRunningContainer requires live restore of running containers. |
|
| 105 |
-func (s *DockerDaemonSuite) TestDaemonRestartWithUnpausedRunningContainer(t *check.C) {
|
|
| 106 |
- // TODO(mlaventure): Not sure what would the exit code be on windows |
|
| 107 |
- testRequires(t, DaemonIsLinux) |
|
| 108 |
- if err := s.d.StartWithBusybox("--live-restore"); err != nil {
|
|
| 109 |
- t.Fatal(err) |
|
| 22 |
+ if err := s.d.Restart(); err != nil {
|
|
| 23 |
+ c.Fatalf("Could not restart daemon: %v", err)
|
|
| 110 | 24 |
} |
| 111 | 25 |
|
| 112 |
- cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
|
| 113 |
- defer s.d.Stop() |
|
| 26 |
+ out, err := s.d.Cmd("plugin", "ls")
|
|
| 114 | 27 |
if err != nil {
|
| 115 |
- t.Fatal(cid, err) |
|
| 116 |
- } |
|
| 117 |
- cid = strings.TrimSpace(cid) |
|
| 118 |
- |
|
| 119 |
- // pause the container |
|
| 120 |
- if _, err := s.d.Cmd("pause", cid); err != nil {
|
|
| 121 |
- t.Fatal(cid, err) |
|
| 28 |
+ c.Fatalf("Could not list plugins: %v %s", err, out)
|
|
| 122 | 29 |
} |
| 30 |
+ c.Assert(out, checker.Contains, pluginName) |
|
| 31 |
+ c.Assert(out, checker.Contains, "true") |
|
| 32 |
+} |
|
| 123 | 33 |
|
| 124 |
- // Kill the daemon |
|
| 125 |
- if err := s.d.Kill(); err != nil {
|
|
| 126 |
- t.Fatal(err) |
|
| 34 |
+// TestDaemonRestartWithPluginEnabled tests state restore for a disabled plugin |
|
| 35 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) {
|
|
| 36 |
+ if err := s.d.Start(); err != nil {
|
|
| 37 |
+ c.Fatalf("Could not start daemon: %v", err)
|
|
| 127 | 38 |
} |
| 128 | 39 |
|
| 129 |
- // resume the container |
|
| 130 |
- runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "resume", cid) |
|
| 131 |
- if out, ec, err := runCommandWithOutput(runCmd); err != nil {
|
|
| 132 |
- t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid)
|
|
| 40 |
+ if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pluginName, "--disable"); err != nil {
|
|
| 41 |
+ c.Fatalf("Could not install plugin: %v %s", err, out)
|
|
| 133 | 42 |
} |
| 134 | 43 |
|
| 135 |
- // Give time to containerd to process the command if we don't |
|
| 136 |
- // the resume event might be received after we do the inspect |
|
| 137 |
- time.Sleep(3 * time.Second) |
|
| 138 |
- |
|
| 139 |
- // restart the daemon |
|
| 140 |
- if err := s.d.Start("--live-restore"); err != nil {
|
|
| 141 |
- t.Fatal(err) |
|
| 44 |
+ if err := s.d.Restart(); err != nil {
|
|
| 45 |
+ c.Fatalf("Could not restart daemon: %v", err)
|
|
| 142 | 46 |
} |
| 143 | 47 |
|
| 144 |
- // Check that we've got the correct status |
|
| 145 |
- out, err := s.d.Cmd("inspect", "-f", "{{.State.Status}}", cid)
|
|
| 146 |
- t.Assert(err, check.IsNil) |
|
| 147 |
- |
|
| 148 |
- out = strings.TrimSpace(out) |
|
| 149 |
- if out != "running" {
|
|
| 150 |
- t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "running", out, cid)
|
|
| 151 |
- } |
|
| 152 |
- if _, err := s.d.Cmd("kill", cid); err != nil {
|
|
| 153 |
- t.Fatal(err) |
|
| 48 |
+ out, err := s.d.Cmd("plugin", "ls")
|
|
| 49 |
+ if err != nil {
|
|
| 50 |
+ c.Fatalf("Could not list plugins: %v %s", err, out)
|
|
| 154 | 51 |
} |
| 52 |
+ c.Assert(out, checker.Contains, pluginName) |
|
| 53 |
+ c.Assert(out, checker.Contains, "false") |
|
| 155 | 54 |
} |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-// +build !windows |
|
| 1 |
+// +build linux |
|
| 2 | 2 |
|
| 3 | 3 |
package main |
| 4 | 4 |
|
| ... | ... |
@@ -2091,6 +2091,158 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) {
|
| 2091 | 2091 |
c.Assert(test3validated, check.Equals, true) |
| 2092 | 2092 |
} |
| 2093 | 2093 |
|
| 2094 |
+// TestDaemonRestartWithKilledRunningContainer requires live restore of running containers |
|
| 2095 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithKilledRunningContainer(t *check.C) {
|
|
| 2096 |
+ // TODO(mlaventure): Not sure what would the exit code be on windows |
|
| 2097 |
+ testRequires(t, DaemonIsLinux) |
|
| 2098 |
+ if err := s.d.StartWithBusybox(); err != nil {
|
|
| 2099 |
+ t.Fatal(err) |
|
| 2100 |
+ } |
|
| 2101 |
+ |
|
| 2102 |
+ cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
|
| 2103 |
+ defer s.d.Stop() |
|
| 2104 |
+ if err != nil {
|
|
| 2105 |
+ t.Fatal(cid, err) |
|
| 2106 |
+ } |
|
| 2107 |
+ cid = strings.TrimSpace(cid) |
|
| 2108 |
+ |
|
| 2109 |
+ // Kill the daemon |
|
| 2110 |
+ if err := s.d.Kill(); err != nil {
|
|
| 2111 |
+ t.Fatal(err) |
|
| 2112 |
+ } |
|
| 2113 |
+ |
|
| 2114 |
+ // kill the container |
|
| 2115 |
+ runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", cid) |
|
| 2116 |
+ if out, ec, err := runCommandWithOutput(runCmd); err != nil {
|
|
| 2117 |
+ t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid)
|
|
| 2118 |
+ } |
|
| 2119 |
+ |
|
| 2120 |
+ // Give time to containerd to process the command if we don't |
|
| 2121 |
+ // the exit event might be received after we do the inspect |
|
| 2122 |
+ pidCmd := exec.Command("pidof", "top")
|
|
| 2123 |
+ _, ec, _ := runCommandWithOutput(pidCmd) |
|
| 2124 |
+ for ec == 0 {
|
|
| 2125 |
+ time.Sleep(3 * time.Second) |
|
| 2126 |
+ _, ec, _ = runCommandWithOutput(pidCmd) |
|
| 2127 |
+ } |
|
| 2128 |
+ |
|
| 2129 |
+ // restart the daemon |
|
| 2130 |
+ if err := s.d.Start(); err != nil {
|
|
| 2131 |
+ t.Fatal(err) |
|
| 2132 |
+ } |
|
| 2133 |
+ |
|
| 2134 |
+ // Check that we've got the correct exit code |
|
| 2135 |
+ out, err := s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", cid)
|
|
| 2136 |
+ t.Assert(err, check.IsNil) |
|
| 2137 |
+ |
|
| 2138 |
+ out = strings.TrimSpace(out) |
|
| 2139 |
+ if out != "143" {
|
|
| 2140 |
+ t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "143", out, cid)
|
|
| 2141 |
+ } |
|
| 2142 |
+ |
|
| 2143 |
+} |
|
| 2144 |
+ |
|
| 2145 |
+// os.Kill should kill daemon ungracefully, leaving behind live containers. |
|
| 2146 |
+// The live containers should be known to the restarted daemon. Stopping |
|
| 2147 |
+// them now, should remove the mounts. |
|
| 2148 |
+func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
|
|
| 2149 |
+ testRequires(c, DaemonIsLinux) |
|
| 2150 |
+ c.Assert(s.d.StartWithBusybox("--live-restore"), check.IsNil)
|
|
| 2151 |
+ |
|
| 2152 |
+ out, err := s.d.Cmd("run", "-d", "busybox", "top")
|
|
| 2153 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 2154 |
+ id := strings.TrimSpace(out) |
|
| 2155 |
+ |
|
| 2156 |
+ c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) |
|
| 2157 |
+ mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
|
|
| 2158 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
|
| 2159 |
+ |
|
| 2160 |
+ // container mounts should exist even after daemon has crashed. |
|
| 2161 |
+ comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
|
|
| 2162 |
+ c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) |
|
| 2163 |
+ |
|
| 2164 |
+ // restart daemon. |
|
| 2165 |
+ if err := s.d.Restart("--live-restore"); err != nil {
|
|
| 2166 |
+ c.Fatal(err) |
|
| 2167 |
+ } |
|
| 2168 |
+ |
|
| 2169 |
+ // container should be running. |
|
| 2170 |
+ out, err = s.d.Cmd("inspect", "--format='{{.State.Running}}'", id)
|
|
| 2171 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 2172 |
+ out = strings.TrimSpace(out) |
|
| 2173 |
+ if out != "true" {
|
|
| 2174 |
+ c.Fatalf("Container %s expected to stay alive after daemon restart", id)
|
|
| 2175 |
+ } |
|
| 2176 |
+ |
|
| 2177 |
+ // 'docker stop' should work. |
|
| 2178 |
+ out, err = s.d.Cmd("stop", id)
|
|
| 2179 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 2180 |
+ |
|
| 2181 |
+ // Now, container mounts should be gone. |
|
| 2182 |
+ mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
|
|
| 2183 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
|
|
| 2184 |
+ comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
|
|
| 2185 |
+ c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) |
|
| 2186 |
+} |
|
| 2187 |
+ |
|
| 2188 |
+// TestDaemonRestartWithUnpausedRunningContainer requires live restore of running containers. |
|
| 2189 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithUnpausedRunningContainer(t *check.C) {
|
|
| 2190 |
+ // TODO(mlaventure): Not sure what would the exit code be on windows |
|
| 2191 |
+ testRequires(t, DaemonIsLinux) |
|
| 2192 |
+ if err := s.d.StartWithBusybox("--live-restore"); err != nil {
|
|
| 2193 |
+ t.Fatal(err) |
|
| 2194 |
+ } |
|
| 2195 |
+ |
|
| 2196 |
+ cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
|
| 2197 |
+ defer s.d.Stop() |
|
| 2198 |
+ if err != nil {
|
|
| 2199 |
+ t.Fatal(cid, err) |
|
| 2200 |
+ } |
|
| 2201 |
+ cid = strings.TrimSpace(cid) |
|
| 2202 |
+ |
|
| 2203 |
+ // pause the container |
|
| 2204 |
+ if _, err := s.d.Cmd("pause", cid); err != nil {
|
|
| 2205 |
+ t.Fatal(cid, err) |
|
| 2206 |
+ } |
|
| 2207 |
+ |
|
| 2208 |
+ // Kill the daemon |
|
| 2209 |
+ if err := s.d.Kill(); err != nil {
|
|
| 2210 |
+ t.Fatal(err) |
|
| 2211 |
+ } |
|
| 2212 |
+ |
|
| 2213 |
+ // resume the container |
|
| 2214 |
+ runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "resume", cid) |
|
| 2215 |
+ if out, ec, err := runCommandWithOutput(runCmd); err != nil {
|
|
| 2216 |
+ t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid)
|
|
| 2217 |
+ } |
|
| 2218 |
+ |
|
| 2219 |
+ // Give time to containerd to process the command if we don't |
|
| 2220 |
+ // the resume event might be received after we do the inspect |
|
| 2221 |
+ pidCmd := exec.Command("pidof", "top")
|
|
| 2222 |
+ _, ec, _ := runCommandWithOutput(pidCmd) |
|
| 2223 |
+ for ec == 0 {
|
|
| 2224 |
+ time.Sleep(3 * time.Second) |
|
| 2225 |
+ _, ec, _ = runCommandWithOutput(pidCmd) |
|
| 2226 |
+ } |
|
| 2227 |
+ |
|
| 2228 |
+ // restart the daemon |
|
| 2229 |
+ if err := s.d.Start("--live-restore"); err != nil {
|
|
| 2230 |
+ t.Fatal(err) |
|
| 2231 |
+ } |
|
| 2232 |
+ |
|
| 2233 |
+ // Check that we've got the correct status |
|
| 2234 |
+ out, err := s.d.Cmd("inspect", "-f", "{{.State.Status}}", cid)
|
|
| 2235 |
+ t.Assert(err, check.IsNil) |
|
| 2236 |
+ |
|
| 2237 |
+ out = strings.TrimSpace(out) |
|
| 2238 |
+ if out != "running" {
|
|
| 2239 |
+ t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "running", out, cid)
|
|
| 2240 |
+ } |
|
| 2241 |
+ if _, err := s.d.Cmd("kill", cid); err != nil {
|
|
| 2242 |
+ t.Fatal(err) |
|
| 2243 |
+ } |
|
| 2244 |
+} |
|
| 2245 |
+ |
|
| 2094 | 2246 |
// TestRunLinksChanged checks that creating a new container with the same name does not update links |
| 2095 | 2247 |
// this ensures that the old, pre gh#16032 functionality continues on |
| 2096 | 2248 |
func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) {
|