docker_cli_daemon_not_experimental_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // +build daemon,!windows,!experimental
  2. package main
  3. import (
  4. "io/ioutil"
  5. "os"
  6. "strings"
  7. "github.com/go-check/check"
  8. )
  9. // os.Kill should kill daemon ungracefully, leaving behind container mounts.
  10. // A subsequent daemon restart shoud clean up said mounts.
  11. func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonKill(c *check.C) {
  12. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  13. out, err := s.d.Cmd("run", "-d", "busybox", "top")
  14. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  15. id := strings.TrimSpace(out)
  16. c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil)
  17. mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
  18. c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
  19. // container mounts should exist even after daemon has crashed.
  20. comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
  21. c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment)
  22. // restart daemon.
  23. if err := s.d.Restart(); err != nil {
  24. c.Fatal(err)
  25. }
  26. // Now, container mounts should be gone.
  27. mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
  28. c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
  29. comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
  30. c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
  31. }
  32. // #22913
  33. func (s *DockerDaemonSuite) TestContainerStartAfterDaemonKill(c *check.C) {
  34. testRequires(c, DaemonIsLinux)
  35. c.Assert(s.d.StartWithBusybox(), check.IsNil)
  36. // the application is chosen so it generates output and doesn't react to SIGTERM
  37. out, err := s.d.Cmd("run", "-d", "busybox", "sh", "-c", "while true;do date;done")
  38. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  39. id := strings.TrimSpace(out)
  40. c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil)
  41. // restart daemon.
  42. if err := s.d.Restart(); err != nil {
  43. c.Fatal(err)
  44. }
  45. out, err = s.d.Cmd("start", id)
  46. c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
  47. }